You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android Studio编译报错:-d选项因指定-Xbuild-file被忽略,Run按钮禁用

Fixing Your Jetpack Hello World Project Issues

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.properties file—for plugin version 3.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 app module from the dropdown (it should show com.example.touseef.jetpackhelloworld)
    • Launch: Keep this set to Default Activity (your project should have a MainActivity marked as the launcher in AndroidManifest.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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 10:01:15