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

Android Jetpack入门项目无法运行,构建及运行配置问题求助

解决Android Jetpack Hello World项目的系列构建与运行问题

Hey there! Let's break down and fix each of the issues you're facing as a new Android developer starting with Jetpack—these are common hiccups when setting up projects with pre-release Studio versions, so don't worry.

1. 修复 Could not get unknown property 'archLifecycleVersion' 错误

This error pops up because your project is referencing the archLifecycleVersion variable but it hasn't been defined anywhere. Here's how to fix it:

  • Open the root-level build.gradle file (not the one inside your app module)
  • Add an ext block at the top to define the missing version variable. For example:
    buildscript {
        ext {
            archLifecycleVersion = "2.6.2" // Use the version matching your Jetpack setup
        }
        // Rest of your buildscript code...
    }
    
  • Save the file and sync your project with Gradle (click the sync button in the toolbar). This tells Gradle where to find the version value it's missing.

2. 解决 the '-d' option with a directory destination is ignored because '-Xbuild-file' is specified 错误

This odd error usually comes from conflicting Gradle command-line parameters in Android Studio's settings. Try these steps:

  • Go to File > Settings (or Android Studio > Settings on Mac)
  • Navigate to Build, Execution, Deployment > Build Tools > Gradle
  • Check the "Command-line options" field—if there's a -d parameter listed, remove it
  • If that doesn't work, try invalidating caches to clear any corrupted build state:
    1. Go to File > Invalidate Caches...
    2. Select "Invalidate and Restart" and let Studio restart and rebuild your project

3. 修复运行按钮禁用、无模块可选的问题

When no modules show up in the run configuration, it means Android Studio isn't recognizing your module as a valid Android app. Here's how to fix this:

  • First, check your settings.gradle file (root directory) and make sure it includes your app module. It should have a line like:
    include ':app'
    
    If not, add that line and sync the project.
  • Next, verify your module's type:
    1. Open File > Project Structure
    2. Select your app module from the left sidebar
    3. On the right, under "Module SDK", make sure an Android SDK is selected (not a Java SDK)
    4. Confirm the module type is set to "Android Application"
  • Finally, sync your project again and try adding the run configuration:
    1. Click the dropdown next to the run button and select "Edit Configurations"
    2. Click the + button and choose "Android App"
    3. Your app module should now appear in the "Module" dropdown—select it and save the configuration

After these steps, your run button should be enabled and you should be able to launch your Hello World app!

内容的提问来源于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.28 09:32:54