InstantAppBundleException:未找到基本拆分!基本拆分 APK 是在 <manifest> 标签上未设置 'splitName' 属性的 APK

InstantAppBundleException: No base split found! Base split APK is the one with no 'splitName' attribute set on the <manifest> tag

尝试启动 Instant App 时,报告

Side loading failed with message: Failure when trying to read bundel. 
Failed to parse app: /data/local/tmp/aia/my_app.zip

看logcat的时候出现这个错误

InstantAppBundleException: No base split found! 
Base split APK is the one with no 'splitName' attribute set on the <manifest> tag

我错过了什么?

我想您可能忘记了基本模块中的 baseFeature 标记。 如果您有一个基本模块和 2 个功能模块作为示例,您的 gradle 应该如下所示(您需要注意正确的插件、baseFeature=true 标签和正确的依赖声明).

基本模块 Gradle 文件:

apply plugin: 'com.android.feature'

android {
    //this is mandatory for the base module of the project
    baseFeature = true
    ...
}

dependencies {
    ...
    feature project(':feature1')
    feature project(':feature2')
    application project(':hello-installed')
}

Feature1 模块Feature2 模块 Gradle 文件:

apply plugin: 'com.android.feature'

android {
    ...
}

dependencies {
    ...
    implementation project(':base')
}

即时应用程序模块 Gradle 个文件:

apply plugin: 'com.android.instantapp'

dependencies {
    implementation project(':base')
    implementation project(':feature1')
    implementation project(':feature2')
}

完整应用程序模块 Gradle 文件:

apply plugin: 'com.android.application'

android {
    //classic gradle declaration for legacy apps
}

dependencies {
    implementation project(':base')
    implementation project(':feature1')
    implementation project(':feature2')

    //non instant libraries will only appear here
    implementation project(':nonInstantLibrary')
}

非即时兼容模块 Gradle 文件:

//it will use the legacy library plugin
apply plugin: 'com.android.library'

dependencies {
    ...
    implementation project(':base')
}