我正在遵循 Google Codelabs 之一来制作即时应用程序。
我试图创建
topeka-ui
(即时应用程序的 UI 功能模块)。
当我尝试运行其中一个即时应用程序模块时,它显示:
定义了依赖功能,但未设置包 ID。 您可能缺少基本功能中的功能依赖性。
我遇到了一个问题,因为我有一个 Android 应用程序和一个 Android 库,但我错误地使用了错误的插件。
对于应用程序:
plugins {
id "com.android.application"
id "kotlin-android"
}
对于图书馆:
plugins {
id "com.android.library"
id "kotlin-android"
}
因为这是“定义了依赖功能但未设置包 ID。您可能在基本功能中缺少功能依赖项”的唯一 stackoverflow 问题。我将在这里回答我的问题,而不是创建一个新问题。我有一个模块给了我这个错误并且无法找出问题所在。在依赖模块的 build.gradle 文件中,我有:
apply plugin: 'com.android.feature'
本来应该是:
apply plugin: 'com.android.library'
您可能已添加依赖模块作为应用程序,它应该作为库添加。 检查模块的 build.gradle 文件并
更换
plugins {
id 'com.android.application'
到
plugins {
id 'com.android.library'
如果在defaultConfig块中添加了applicationId,versionCode和versionName,也从内部模块的build.gradle中删除它。
我刚刚在 AS 3.0 beta 2 上运行了 Codelab,没有出现任何问题(*注)。您的问题是在 Codelab 中的哪个点之后出现的?
您可能错过了一个步骤。仔细检查您的基本模块的 build.gradle 是否具有:
dependencies {
...
application project(":topekaapk")
feature project(":topekaui")
}
省略
feature project(":topekaui")
可能会导致此错误:
错误:com.android.builder.internal.aapt.AaptException:依赖项 已定义功能但未设置包 ID。你可能是 基本功能中缺少功能依赖性。
注意:由于非基本模块的数据绑定已被禁用(https://issuetracker.google.com/63814741),因此在多功能步骤 7 中需要一些额外的步骤来解决它(即.摆脱 DataBindingUtil)。
我在 build.gradle(...mylibrary) 中完成了它,修复了它并且它起作用了:
plugins {
- id 'com.android.application'
+ id 'com.android.library'}
defaultConfig {
- applicationId "com.example.mylibrary"
minSdk 21
targetSdk 32}
当我忘记在基本模块的
android.dynamicFeatures = [":module_name"]
数组中添加对它的引用时,我的动态功能模块中遇到了这个问题
基于基本即时应用程序项目结构,
当您构建即时应用程序时,此模块将采用所有功能并创建即时应用程序 APK。它不包含任何代码或资源;它仅包含一个
文件并应用了build.gradle
插件。这是一个例子:com.android.instantapp
apply plugin: 'com.android.instantapp'
...
dependencies {
implementation project(':base')
// if there additional features, they go here
implementation project(':feature1')
}
此外,请注意
基本功能模块的构建配置文件需要应用
gradle插件。com.android.feature
文件不包含任何即时应用程序特定的修改。build.gradle
有了这个并根据您遇到的错误,您可能需要检查您的基本功能模块的构建配置文件。最后,请确保您还将项目与 gradle 文件同步。
请参阅Android Instant Apps 文档了解更多信息。
使用以下 gradle pugin
classpath 'com.android.tools.build:gradle:3.5.1'
就我而言,添加到应用程序的 build.gradle 后
android{
dataBinding {
enabled = true
}
}
我收到了发布的错误,然后执行以下操作
Android studio -> invalidate cache and restart
问题已解决!
还没修好?
build.gradle 中可能存在冲突的依赖项, 就像同一个库的旧版本和当前版本