Class 使用动态功能构建 APK 时未找到

Class Not Found when build APK when using dynamic feature

我通过 'com.android.dynamic-feature' 设置了菜单模块。当我通过 android 工作室编码和 运行 时一切正常。当通过 Build -> Build APK(s) 打包 apk 时,当我在模块中启动 activity 时,它会崩溃 Class Not Found。 注意:activity 路径是正确的,我想我的模块没有附加到 app

  1. 清单模块:
    <dist:module
        dist:instant="false"
        dist:onDemand="false"
        dist:title="">
        <dist:delivery>
            <dist:install-time />
        </dist:delivery>
        <dist:fusing dist:include="true" />
    </dist:module>
  1. 模块gradle
apply plugin: 'com.android.dynamic-feature'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply from: '../shared_dependencies.gradle'

这里有错吗?谢谢

构建具有动态功能模块的 Android 项目将始终在模拟器上运行,因为没有 Google Play 上的交付系统。当你使用功能模块时,你也应该使用 Build -> Build Bundle(s)/APK(s)->Build Bundle(s) 选项。

在主模块的 build.gradle 文件中,您需要设置 dynamicFeatures,例如:

android {
...
  dynamicFeatures = [
        ':module1',
        ':module2',
        ':module3'
   ]
...
}

在动态功能模块的 build.gradle 文件中,您需要主模块的依赖项:

dependencies {
   implementation project(':app')
}

如果您使用 <dist:fusing dist:include="true" /> 并通过 APK 签署您的应用程序,它仍然不会包含在您的 APK 中。 dynamic-feature 仅用于 AAB 格式。

如果您仍想使用 APK 格式,则必须使用 bundle-toolAAB

生成 universal APK

https://developer.android.com/studio/command-line/bundletool