已定义依赖功能但未设置包 ID。您可能缺少基本功能中的功能依赖性

A dependent feature was defined but no package ID was set. You are probably missing a feature dependency in the base feature

我正在关注其中一位 Google Codelabs 制作即时应用程序。

我正在尝试创建 topeka-ui一个 UI Instant Apps 功能模块)。

当我尝试 运行 其中一个即时应用程序模块时,它说:

A dependent feature was defined but no package ID was set. You are probably missing a feature dependency in the base feature.

来自 basic instant app project structure

的基础

When you build your instant app, this module takes all of the features and creates Instant App APKs. It does not hold any code or resources; it contains only a build.gradle file and has the com.android.instantapp plugin applied to it. Here's an example:

apply plugin: 'com.android.instantapp'
...
dependencies {
    implementation project(':base')
    // if there additional features, they go here
    implementation project(':feature1')
}

此外,请注意

The base feature module's build configuration file needs to apply the com.android.feature gradle plugin. The build.gradle file does not contain any instant app specific modifications.

有了这个并根据您遇到的错误,您可能需要检查您的 base feature module's build configuration file. Lastly, make sure that you also sync your project with gradle files

有关详细信息,请参阅 Android Instant Apps documentation

我刚刚 运行 通过 AS 3.0 beta 2 上的代码实验室,没有任何问题(*注意)。您的问题是在 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).

因为这是“已定义相关功能但未设置包 ID。您可能缺少基本功能中的功能相关性”的唯一 Whosebug 问题。我将在这里回答我的问题,而不是创建一个新问题。我有一个模块给我这个错误,但无法找出问题所在。在依赖模块的 build.gradle 文件中,我有:

apply plugin: 'com.android.feature'

应该是:

apply plugin: 'com.android.library'

当我忘记在基本模块的 android.dynamicFeatures = [":module_name"] 数组

中添加对动态功能模块的引用时,我在我的动态功能模块中遇到了这个问题

具有以下gradle pugin

classpath 'com.android.tools.build:gradle:3.5.1'

在我的例子中,添加到应用程序后 build.gradle

android{
dataBinding {
        enabled = true
    }
}

我收到了发布的错误,然后执行以下操作

Android studio -> invalidate cache and restart

问题已解决!

还没有修复?

Probably there is a conflicting dependency residing in build.gradle, like the older and current version of the same library

我有一个问题,我有一个 Android 应用程序和一个 Android 库,但我错误地使用了错误的插件。

对于应用程序:

plugins {
    id "com.android.application"
    id "kotlin-android"
}

图书馆:

plugins {
    id "com.android.library"
    id "kotlin-android"
}

我在 build.gradle(...mylibrary) 中完成了它,修复了它并且成功了:

plugins {
- id 'com.android.application'
+ id 'com.android.library'}

defaultConfig {
    - applicationId "com.example.mylibrary"
    minSdk 21
    targetSdk 32}