“已配置相关功能,但未设置包 ID。” 创建新模块 Android 时

Nur*_*lov 20 android-studio android-gradle-plugin android-module

我正在尝试创建一个新模块。这个模块的元素应该对第一个模块可见。这就是我添加的原因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.
Run Code Online (Sandbox Code Playgroud)

Ree*_*edy 30

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

  • 所有创建的模块都使用“com.android.application”。如果我将其重命名为“com.android.library”,则会收到此错误:“库项目无法设置 applicationId”。applicationId 在默认配置中设置为“com.example.nameOfMyModule”。受影响的模块:nameOfMyModule` (2认同)
  • @LeNguyenDuyAnh 这是预料之中的。从该模块的 gradle 文件中的 defaultConfig 中删除 applicationId 字段。 (2认同)

den*_*T30 12

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

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

plugins {
    // id 'com.android.application'
    id "com.android.library"
}

android {
    defaultConfig {
     //   applicationId "com.xxx.xx.x"
    }
}
Run Code Online (Sandbox Code Playgroud)

看来图书馆不需要applicationId


小智 5

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

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

object Plugins {

   const val androidApplication    = "com.android.application"
   const val androidLibrary        = "com.android.library"
}
Run Code Online (Sandbox Code Playgroud)

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

:应用程序

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

}
Run Code Online (Sandbox Code Playgroud)

:我的模块

plugins {
    id(Plugins.androidLibrary)
     .........
}
Run Code Online (Sandbox Code Playgroud)