android - Proguard 混淆了合并库 list 中的 Activity 名称

标签 android proguard

我有几个使用公共(public)库项目的应用程序项目。我最近尝试将一些常见的 Activity 声明从每个应用程序项目的 AndroidManifest.xml 移动到库的 list 中,并在 project.properties 中使用 manifestmerger.enabled=true 启用 list 合并。

在调试版本中一切正常,但发布版本(被 Proguard 混淆)失败并出现 ActivityNotFoundException。这是因为 Proguard 混淆了库 list 中声明的​​ Activity 的名称,而不是应用程序 list 中的名称。

我已经检查了应用程序项目的合并 bin/AndroidManifest.xml 文件,它正确地列出了 Activity 名称。

有人可以建议解决方法吗?

最佳答案

标准的 Ant 构建过程调用 aapt 工具来创建 ProGuard 配置 (bin/proguard.txt),该配置保留必要的类(例如它认为使用的所有 Activity )。如果这对您的项目结构不起作用(可能是错误或不受支持的情况),您可以自己在 proguard-project.txt 中保留这些类:

-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider

如果生成的应用程序仍然缺少其他类,您可以在 ProGuard 手册 > 示例 > A complete Android application 中找到更多手动配置.

关于android - Proguard 混淆了合并库 list 中的 Activity 名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16071498/

相关文章:

android - 如何修复编译 smartass Governor 时初始化程序中指定的未知字段 'suspend'?

android - Proguard : can't find referenced method 'android. app.DatePickerDialog 访问$000

java - 获取光传感器值

android - 为什么MediaPlayer失败?

android - 如何从 Proguard(Android 项目)的混淆中排除外部 .jar?

proguard - 您如何解读反混淆后的 Android 崩溃报告?

多库项目中的 Android Studio proguard 处理

android - 当minifyEnabled为真时,如何在发布版本中修复 "NoSuchFieldException: No field producerIndex"- android?

android - Fragment 中的 ViewModel + LiveData,从 ItemDetailFragment 返回时如何保留 ListItemFragment 的数据

android - 如何使用不存在或过时的 Google Play 服务测试 Android 应用程序?