我正在跟随 Google Codelabs 中的一个教程,制作一个即时应用程序。
我正在尝试创建 topeka-ui
(即时应用程序的 UI 功能模块)。
当我尝试运行其中一个即时应用程序模块时,它会显示:
已定义依赖功能,但未设置包 ID。 您可能在基础功能中缺少功能依赖项。
我正在跟随 Google Codelabs 中的一个教程,制作一个即时应用程序。
我正在尝试创建 topeka-ui
(即时应用程序的 UI 功能模块)。
当我尝试运行其中一个即时应用程序模块时,它会显示:
已定义依赖功能,但未设置包 ID。 您可能在基础功能中缺少功能依赖项。
我遇到了一个问题,我有一个安卓应用和一个安卓库,但是我错误地使用了错误的插件。
对于应用:
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'
我刚刚顺利地完成了AS 3.0 beta 2上的codelab (*注意)。在codelab的哪个阶段出现了问题?
可能是您错过了某个步骤。请仔细检查您的基础模块的build.gradle文件是否包含:
dependencies {
...
application project(":topekaapk")
feature project(":topekaui")
}
如果省略了feature project(":topekaui")
,可能会导致以下错误:
Error:com.android.builder.internal.aapt.AaptException: A dependent feature was defined but no package ID was set. You are probably missing a feature dependency in the base feature.
注意:由于数据绑定已被禁用于非基本模块(https://issuetracker.google.com/63814741),因此在多功能步骤7中需要进行一些额外的步骤以解决这个问题(即摆脱DataBindingUtil)。
plugins {
id 'com.android.application'
到
plugins {
id 'com.android.library'
如果在defaultConfig块中添加了applicationId,请从内部模块的build.gradle中删除它
我在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
gradle 插件。build.gradle
文件不包含任何即时应用程序特定的修改。
classpath 'com.android.tools.build:gradle:3.5.1'
android{
dataBinding {
enabled = true
}
}
Android studio -> invalidate cache and restart
问题已经解决!
还没有解决?
可能在build.gradle中存在冲突的依赖项, 例如同一库的旧版本和当前版本