Android Studio编译报错:-d选项因指定-Xbuild-file被忽略,Run按钮禁用
Hey there! Let's tackle these problems step by step to get your first Jetpack project up and running smoothly.
1. Recap & Best Practice for the archLifecycleVersion Error
You mentioned you already fixed the "Could not get unknown property 'archLifecycleVersion'" error, but let's reinforce a best practice for managing dependency versions (this is likely what the official Jetpack docs intended):
Add the version variable to your root-level build.gradle so you can reuse it across modules:
// In root build.gradle's buildscript block buildscript { ext.kotlin_version = '1.2.41' ext.archLifecycleVersion = '1.1.1' // Add this line repositories { google() jcenter() } // ... rest of your buildscript code }
Then update your app-level build.gradle dependency to use the variable:
implementation "android.arch.lifecycle:extensions:$archLifecycleVersion"
This keeps version numbers centralized and easier to update later.
2. Fixing the "-d option ignored" Compile Error
This error usually stems from a Gradle configuration mismatch or corrupted cached build data. Try these fixes in order:
- Use the Gradle Wrapper: Go to
File > Settings > Build, Execution, Deployment > Build Tools > Gradle, then select "Use Gradle from: 'gradle-wrapper.properties' file" (this ensures you're using the Gradle version compatible with your Android plugin). - Invalidate Caches & Restart: Go to
File > Invalidate Caches / Restart, choose "Invalidate and Restart". This clears wonky cached data that often causes weird build issues. - Verify Gradle Version Compatibility: Check your
gradle/wrapper/gradle-wrapper.propertiesfile—for plugin version3.2.0-alpha14, you need Gradle 4.6 or higher. Make sure your distribution URL looks like this:distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
3. Enabling the Run Option & Configuring Your Launcher
The Run option is disabled because Android Studio doesn't have a launch configuration set up yet. Here's how to fix it:
- Click the Run dropdown menu (next to the green play button) and select Edit Configurations...
- In the top-left corner of the window, click the
+icon and choose Android App - Configure the settings:
- Name: Give your configuration a simple name (e.g., "JetpackHelloWorld")
- Module: Select your
appmodule from the dropdown (it should showcom.example.touseef.jetpackhelloworld) - Launch: Keep this set to Default Activity (your project should have a
MainActivitymarked as the launcher inAndroidManifest.xml)
- Click Apply then OK
Your Run button should now be enabled—click it to launch your app on an emulator or connected device!
Quick Sanity Check
Double-check that your AndroidManifest.xml has the correct launcher intent filter for your MainActivity:
<activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>
This ensures the app knows which activity to start when launched.
内容的提问来源于stack exchange,提问作者Muhammad Touseef

