【问题标题】:How to include AAR in Dynamic Feature Module?如何在动态功能模块中包含 AAR?
【发布时间】:2020-08-12 04:05:17
【问题描述】:

我想将一个大的 AAR 库(“crypteriumsdk”)放入一个可以按需安装的动态功能模块中。但是当我这样做时,它找不到它的资源(主题):

资源样式/CrypteriumTheme(又名 com.crypter.cryptocyrrency:style/CrypteriumTheme) 未找到。

我还在主清单(应用程序模块)中将tools:replace="android:theme" 添加到application。

这里有什么问题?

settings.gradle:

include ':crypteriumsdk'
include ':wallet'
include ':app'

wallet.gradle:

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation project(":app")
    implementation project(':crypteriumsdk') // added the library here
}

【问题讨论】:

    标签: android android-app-bundle dynamic-feature-module


    【解决方案1】:

    Manifest 过早合并,无法在用户设备上使用实际的主题实现。

    你可以把它添加到你的基础模块的styles.xml中:

        <style name="CrypteriumTheme" />
    

    这允许在安装时找到样式资源 ID,并在模块可用并启动后将其覆盖。

    请参阅this sample 以了解有效的实施。

    【讨论】:

    • 谢谢,这行得通!您是否知道我可以对来自 3rd 方库的同名资源做些什么?例如。我们在我们的基础(应用程序)模块中使用库 A,然后在动态功能模块中使用库 B,并且两个库都有一些同名的布局资源。这会在尝试构建捆绑包时导致错误:Modules 'base' and 'dynamicfeature' contain entry 'res/layout/design_bottom_navigation_item.xml' with different content.。我知道这个问题离题了,但非常感谢您在这方面的经验:)
    • 感谢您提出。我在问题中添加了answer。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-07-17
    • 2023-03-23
    • 2020-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多