【问题标题】:Class Not Found when build APK when using dynamic feature使用动态功能构建 APK 时找不到类
【发布时间】:2020-11-02 15:45:25
【问题描述】:

我通过“com.android.dynamic-feature”设置了菜单模块。当我编码并由 android studio 运行时,一切正常。当通过 Build -> Build APK(s) 打包 apk 时,当我在模块中开始活动时,它会崩溃 Class Not Found。 注意:活动路径是正确的,我猜我的模块没有附加到应用程序中

  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. 模块分级
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 apk dynamic-feature-module


    【解决方案1】:

    如果您使用&lt;dist:fusing dist:include="true" /&gt; 并通过APK 签署您的应用程序,它仍然不会包含在您的APK 中。 dynamic-feature 只能与AAB 格式一起使用。

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

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

    【讨论】:

      【解决方案2】:

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

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

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

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

      dependencies {
         implementation project(':app')
      }
      

      【讨论】:

      • 我已经在上面添加了一些代码,我必须构建 APK 因为我的应用程序发布到另一个商店。它不支持 AAB
      • 您可以尝试删除 因为这会导致默认行为并在构建时包含模块
      • 谢谢,但我已经尝试过但无法正常工作。也许它只提供 AAB 格式
      • 您可以尝试将发布版本构建变体构建到模拟器,您需要在 build.gradle 中添加 APK 签名,以便您获得签名的 APK,但您可能会获得两个 APK,一个用于主模块,另一个用于一个用于功能模块
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-24
      • 2021-08-30
      • 2017-08-01
      • 2021-01-06
      • 2017-05-18
      • 2022-01-09
      相关资源
      最近更新 更多