Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proguard obfuscates Activity names in a merged library manifest

I have several application projects which use a common library project. I recently tried moving some common Activity declarations from each application project's AndroidManifest.xml into the library's manifest, and enabled manifest merging with manifestmerger.enabled=true in project.properties.

Everything works fine in a debug build, but release builds (obfuscated by Proguard) fail with an ActivityNotFoundException. This is because Proguard is obfuscating the names of Activities which are declared in the library manifest, but not those in the application manifest.

I have examined the merged bin/AndroidManifest.xml file for the application project, and it correctly has the Activity names listed.

Can someone please suggest a workaround?

like image 406
Graham Borland Avatar asked Apr 17 '13 22:04

Graham Borland


1 Answers

The standard Ant build process invokes the aapt tool to create a ProGuard configuration (bin/proguard.txt) that preserves the necessary classes (e.g. all activities that it deems used). If that doesn't work for your project structure (maybe a bug or an unsupported case), you can preserve the classes yourself in your 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

If the resulting application is still missing other classes, you can find more manual configuration in the ProGuard manual > Examples > A complete Android application.

like image 184
Eric Lafortune Avatar answered Sep 28 '22 04:09

Eric Lafortune