[英]Dynamic Feature with third party library that has an activity in its manifest with a custom theme - Resource not found
I have a module in my app that acts as a dynamic feature.我的应用程序中有一个用作动态功能的模块。
This dynamic feature module uses a third party library where this third party library has in its AndroidManifest an Activity that uses a custom theme.此动态功能模块使用第三方库,其中该第三方库在其 AndroidManifest 中有一个使用自定义主题的 Activity。
With the described configurations, the app compiles fine, but when I try to run it, it throws an error saying that the resource of that Activity's theme could not be found.使用所描述的配置,该应用程序可以正常编译,但是当我尝试运行它时,它会抛出一个错误,指出找不到该 Activity 主题的资源。
The error looks like this:错误如下所示:
AGPBI: {"kind":"error","text":"Android resource linking failed","sources":[{"file":"/Users/my_user/Documents/MyProject/App/AppName/build/intermediates/metadata_feature_manifest/debug/processDebugManifest/metadata-feature/AndroidManifest.xml","position":{"startLine":40,"startColumn":8,"endLine":45,"endColumn":54}}],"original":"/Users/my_user/Documents/MyProject/App/AppName/build/intermediates/metadata_feature_manifest/debug/processDebugManifest/metadata-feature/AndroidManifest.xml:41:9-46:55: AAPT: error: resource style/CustomTheme (aka com.my.project.domain:style/CustomTheme) not found.\\n ","tool":"AAPT"}
AGPBI: {"kind":"error","text":"Android 资源链接失败","sources":[{"file":"/Users/my_user/Documents/MyProject/App/AppName/build/intermediates/ metadata_feature_manifest/debug/processDebugManifest/metadata-feature/AndroidManifest.xml","position":{"startLine":40,"startColumn":8,"endLine":45,"endColumn":54}}],"original" :"/Users/my_user/Documents/MyProject/App/AppName/build/intermediates/metadata_feature_manifest/debug/processDebugManifest/metadata-feature/AndroidManifest.xml:41:9-46:55: AAPT: 错误: 资源样式/CustomTheme (又名 com.my.project.domain:style/CustomTheme) 未找到。\\n ","tool":"AAPT"}
* What went wrong: Execution failed for task ':app:processDebugResources'.
* 出了什么问题:任务 ':app:processDebugResources' 执行失败。 A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade Android resource linking failed /Users/my_user/Documents/MyProject/App/AppName/build/intermediates/metadata_feature_manifest/debug/processDebugManifest/metadata-feature/AndroidManifest.xml:41:9-46:55: AAPT: error: resource style/CustomTheme (aka com.my.project.domain:style/CustomTheme) not found.
执行 com.android.build.gradle.internal.tasks.Workers$ActionFacade Android 资源链接失败时发生故障 /Users/my_user/Documents/MyProject/App/AppName/build/intermediates/metadata_feature_manifest/debug/processDebugManifest/metadata-feature /AndroidManifest.xml:41:9-46:55: AAPT: 错误:找不到资源样式/CustomTheme(又名 com.my.project.domain:style/CustomTheme)。
I think that that problem is related to the following issue described by Google:我认为该问题与谷歌描述的以下问题有关:
In a dynamic feature module's manifest, you should not reference resources that don't exist in the base module.
在动态功能模块的清单中,您不应引用基本模块中不存在的资源。 That's because, when Google Play generates your app's base APK, it merges manifests for all modules into that of the base APK.
这是因为,当 Google Play 生成您应用的基础 APK 时,它会将所有模块的清单合并到基础 APK 的清单中。 So, resource linking breaks if the base APK's manifest references resources that don't exist in the base APK.
因此,如果基础 APK 的清单引用了基础 APK 中不存在的资源,则资源链接会中断。
Reference: https://developer.android.com/guide/app-bundle/参考: https : //developer.android.com/guide/app-bundle/
How can one make that project run, if the third party library is not open to be modified?如果没有打开第三方库进行修改,如何使该项目运行?
A work around to fix the mentioned problem is actually pretty simple (misleading and not good looking though).解决上述问题的解决方法实际上非常简单(虽然具有误导性且不好看)。
For example, if the log complains about a style named CustomTheme
and a string name custom_string
that could not be found, all you have to do is create that style and string resource, empty, in your base module.例如,如果日志抱怨一个名为
CustomTheme
的样式和一个无法找到的字符串名称custom_string
,您所要做的就是在您的基本模块中创建该样式和字符串资源,为空。
../app/src/main/res/values/styles.xml ../app/src/main/res/values/styles.xml
<resources ...>
...
<style name="CustomTheme" />
</resources>
../app/src/main/res/values/strings.xml ../app/src/main/res/values/strings.xml
<resources ...>
...
<string name="custom_string" />
<resources />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.