Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proguard errors when exporting Android project after updating to ADT 20

After updating to ADT 20 I can no longer successfully export any of my Android projects. I get:

Proguard returned with error code 1. See console

In the console I get tons of the can't find referenced class warnings and occasionally the can't find superclass or interface warning. At the end of the warnings I get something like this:

    You should check if you need to specify additional program jars.
Warning: there were 199 unresolved references to classes or interfaces.
    You may need to specify additional library jars (using '-libraryjars').
java.io.IOException: Please correct the above warnings first.
 at proguard.Initializer.execute(Initializer.java:321)
 at proguard.ProGuard.initialize(ProGuard.java:211)
 at proguard.ProGuard.execute(ProGuard.java:86)
 at proguard.ProGuard.main(ProGuard.java:492)

Each time I attempt to build I get different numbers of warnings (it's not very consistent). Also, when I perform a clean before export, the export completes without producing any warnings, but the resulting APK crashes on launch often due to ClassNotFoundException.

My proguard-project.txt includes the necessary -keep class rules for the Android Support Library and ActionBarSherlock.

I had no problems building this project before ADT 20. I even tried building my last release (which obviously built fine when I released it), but I get the same proguard warnings and failed export.

I've tried adding -libraryjars and/or -dontwarn rules as many other SO questions suggest, but to no avail. It will sometimes build successfully, but the APK created crashes on launch.

Any suggestions?

like image 577
ashughes Avatar asked Jul 13 '12 19:07

ashughes


2 Answers

There is a bug in AAPT where it will only process

<fragment android:name"..." />

but not

<fragment class="..." />

We'll fix AAPT but in the meantime you can use the other attribute and it'll work.

like image 109
Xavier Ducrohet Avatar answered Sep 28 '22 06:09

Xavier Ducrohet


In ADT 20, we use a feature of aapt (see the -G flag) which can create a proguard file which contains keep rules for exactly the custom views used by your code.

The old proguard config files would keep all views. When you used a library project such as the compatibility library, where you might be using only a small subset of the available code, this could end up including a lot of stuff you don't need. By removing the generic keep rules, and adding a new keep file based on your application, your .apks would get smaller since a lot of unused stuff can be removed.

One area where this can go wrong is if you update to Tools 20 (so you have the new smaller proguard-android.txt file), and you continue to use ADT 18. Make sure to use ADT 20, since it will add in not just the proguard files specified in your project.properties setting, but the generated proguard file listing the keep files from aapt -G as well. I believe the ant build will also use the -G feature.

(Note - see http://code.google.com/p/android/issues/detail?id=35107 for any followups on this)

like image 25
Tor Norbye Avatar answered Sep 28 '22 04:09

Tor Norbye