Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proguard with android project using (compatibility) libraries

I'm trying to use Proguard via the build-in Proguard support in Package Explorer Export > Export Android Application. The main project is using a library project that in turn uses the android compatibility library, it uses this compatibility lib itself too. Basically like so:

BaseLibraryProject BaseActitivity libs:android-support-v4.jar MainProject uses library BaseLibraryProject libs:android-support-v4.jar

This app runs OK both on devices and simluators. However Proguard emits a lot of warnings and exists with code 1.

This is the last bit of the Proguard related listing:

[2012-04-09 14:19:49 - MainProject] Warning: android.support.v4.widget.SearchViewCompatHoneycomb: can't find referenced class android.widget.SearchView
[2012-04-09 14:19:49 - MainProject] Warning: android.support.v4.widget.SearchViewCompatHoneycomb: can't find referenced class android.widget.SearchView
[2012-04-09 14:19:49 - MainProject] Warning: android.support.v4.widget.SearchViewCompatHoneycomb: can't find referenced class android.widget.SearchView$OnQueryTextListener
[2012-04-09 14:19:49 - MainProject] Warning: android.support.v4.widget.SearchViewCompatHoneycomb: can't find referenced class android.widget.SearchView
[2012-04-09 14:19:49 - MainProject] Warning: android.support.v4.widget.SearchViewCompatHoneycomb$1: can't find referenced class android.widget.SearchView$OnQueryTextListener
[2012-04-09 14:19:49 - MainProject] Warning: android.support.v4.widget.SearchViewCompatHoneycomb$1: can't find referenced class android.widget.SearchView
[2012-04-09 14:19:49 - MainProject] Warning: there were 131 unresolved references to classes or interfaces.
[2012-04-09 14:19:49 - MainProject]          You may need to specify additional library jars (using '-libraryjars').
[2012-04-09 14:19:49 - MainProject] Warning: there were 29 unresolved references to program class members.
[2012-04-09 14:19:49 - MainProject]          Your input classes appear to be inconsistent.
[2012-04-09 14:19:49 - MainProject]          You may need to recompile them and try again.
[2012-04-09 14:19:49 - MainProject]          Alternatively, you may have to specify the option 
[2012-04-09 14:19:49 - MainProject]          '-dontskipnonpubliclibraryclassmembers'.
[2012-04-09 14:19:49 - MainProject] java.io.IOException: Please correct the above warnings first.

As you see: it cannot find the compatibility library.

This is the start of the proguard.cfg file with both -libraryjars and -dontskipnonpubliclibraryclassmembers included:

-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontskipnonpubliclibraryclassmembers
-dontpreverify
-verbose
-libraryjars libs/android-support-v4.jar

Does not make a difference. I tried all sorts of combinations of adding the library to the BaseLibrary project / MainProject, fully qualified path names. Nothing seems to help.

Most stackoverflow questions on proguard seem to deal with setting up Ant. Any idea what could be causing this problem and how to get Proguard working on this project that uses several libraries?

THanks in advance,

like image 665
Gerrit Beuze Avatar asked Apr 09 '12 12:04

Gerrit Beuze


1 Answers

The release of ADT 17 brought many improvements to the way Proguard works including better defaults, which I think should solve your support library problem.

See - http://tools.android.com/recent/proguardimprovements

Eclipse (project.properties)

As of ADT 17 the default project.properties file now includes the following line which references a standard Proguard configuration file (proguard-android.txt) and a project specific Proguard configuration file (proguard-project.txt) ...

proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt

I recommended creating a new Android project to see how it's laid out and using these new files. Your app will benefit long term as there are improvements to Proguard and the default configuration.

Update

Gradle (build.gradle)

The following will use both the default standard proguard config & the local project proguard rules.

android {
    release {
        runProguard true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
    }
 }
like image 198
denizmveli Avatar answered Nov 20 '22 15:11

denizmveli