【问题标题】:"Dependent features configured but no package ID was set." When creating a new module Android“已配置相关功能,但未设置包 ID。”创建新模块 Android 时
【发布时间】:2020-02-29 04:33:40
【问题描述】:

我正在尝试创建一个新模块。该模块的元素应该对第一个模块可见。这就是我将implementation project(":messanger") 添加到Build.gradle(:app) 的原因,但它给出了以下错误:

Dependent features configured but no package ID was set.
Execution failed for task ':app:processDebugResources'.
A failure occurred while executing 
com.android.build.gradle.internal.tasks.Workers$ActionFacade
AAPT2 aapt2-4.0.0-beta01-6051327-linux Daemon #0: Unexpected error during link, attempting 
 to 
stop daemon.
 This should not happen under normal circumstances, please file an issue if it does.

【问题讨论】:

    标签: android-studio android-gradle-plugin android-module


    【解决方案1】:

    您创建的模块正在使用插件“com.android.application”,它应该使用“com.android.library”插件。 您可以在模块的 build.gradle 文件中找到它,将其更改为使用库插件,它应该可以编译。

    【讨论】:

    • 非常感谢兄弟,我在这个问题上卡了 4 个小时
    • 所有创建的模块都使用com.android.application。如果我将其重命名为 com.android.library 我会收到此错误:Library projects cannot set applicationId. applicationId is set to 'com.example.nameOfMyModule' in default config. Affected Modules: nameOfMyModule
    • @LeNguyenDuyAnh 这是预期的。从该模块的 gradle 文件中的 defaultConfig 中删除 applicationId 字段。
    【解决方案2】:

    我整合了目前的 Reedy 答案,强调应用程序和模块必须使用两个不同的插件。

    如果您转向 buildSrc 方法(强烈建议),您应该在以下位置声明两个不同的变量: buildSrc/src/main/java/dependencies.kt

    object Plugins {
    
       const val androidApplication    = "com.android.application"
       const val androidLibrary        = "com.android.library"
    }
    

    并在 app 和 mymodule build.gradle 中正确使用它们

    :应用程序

    plugins {
        id(Plugins.androidApplication)
         .......
    
    }
    

    :我的模块

    plugins {
        id(Plugins.androidLibrary)
         .........
    }
    

    【讨论】:

      【解决方案3】:

      如果模块是库,而不是应用程序

      build.gradle ( for the module ) 中使用如下配置

      plugins {
          // id 'com.android.application'
          id "com.android.library"
      }
      
      android {
          defaultConfig {
           //   applicationId "com.xxx.xx.x"
          }
      }
      

      看来,图书馆不需要applicationId

      【讨论】:

        【解决方案4】:

        检查您的模块是否是:库而不是应用程序

        在 build.gradle 中检查是否: 'com。安卓。图书馆”

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2020-11-15
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-12-20
          • 1970-01-01
          • 1970-01-01
          • 2016-03-27
          相关资源
          最近更新 更多