While exporting my Android Application, Proguard returned with error code 1. I am using twitter4j external jars in my app.
I already added library jars, rt.jar (For
Try adding the next line to your proguard file:
-keep public class com.google.code.linkedinapi.**
-keepclassmembers public class com.google.code.linkedinapi.client.impl.LinkedInApiXppClient {
public <init>(java.lang.String, java.lang.String);
}
And also add
-keep class twitter4j.**
-keepclassmembers class twitter4j.** {
<init>(...);
<methods>;
<fields>;
}
and also a good idea to add
-keep public class * extends android.view.View {
public <init>(android.content.Context);
public <init>(android.content.Context, android.util.AttributeSet);
public <init>(android.content.Context, android.util.AttributeSet, int);
public void set*(...);
}
-keepclassmembers class **.R$* {
public static <fields>;
}
Thank you so much for all. Finally after so much struggling I found my foolish mistake. I have configured wrong config file in project.properties.
I was changing code in proguard.cfg, but the project.properties file contains wrong config file path i.e.
proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
Fixed with this changes:
proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard.cfg
proguard.cfg working version
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontskipnonpubliclibraryclassmembers
-dontpreverify
-dontshrink
-verbose
-injars bin/classes
-injars libs
-outjars bin/classes-processed.jar
-libraryjars C:/glassfish3/jdk7/jre/lib/rt.jar
-libraryjars C:/glassfish3/jdk7/lib/tools.jar
-dontwarn org.apache.**
-dontwarn org.slf4j.**
-dontwarn org.json.*
-dontwarn org.mortbay.**
-dontwarn org.apache.log4j.**
-dontwarn org.apache.commons.logging.**
-dontwarn org.apache.commons.logging.**
-dontwarn org.apache.commons.codec.binary.**
-dontwarn javax.xml.**
-dontwarn javax.management.**
-dontwarn java.lang.management.**
-dontwarn android.support.**
-dontwarn com.google.code.**
-dontwarn oauth.signpost.**
-dontwarn twitter4j.**
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-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
-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService
-keep public class com.google.code.linkedinapi.**
-keep class javax.** { *; }
-keep class org.** { *; }
-keep class twitter4j.** { *; }
-keep class java.lang.management.** { *; }
-keep class com.google.code.** { *; }
-keep class oauth.signpost.** { *; }
-keepclassmembers public class com.google.code.linkedinapi.client.impl.LinkedInApiXppClient {
public <init>(java.lang.String, java.lang.String);
}
-keepclasseswithmembernames class * {
native <methods>;
}
-keepclasseswithmembernames class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembernames class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
I was getting a "Proguard returned with error code 1. See console" error. In my case the problem was in the "sdk\tools\proguard\bin\proguard.bat" file which the ADT uses to start ProGuard. It contained the line "java -jar "%PROGUARD_HOME%"\lib\proguard.jar %*". In my environment the simple command "java" doesn't work. I never use it because I specify specific JVMs in different circumstances.
Anyway, changing "java" to the absolute path of the JDK 1.7 bin\java.exe resolved the issue.
I guess Android does not support jdk 1.7, May be that's your problem. Can the Android SDK work with JDK 1.7?
Given these -dontwarn
options, you can't be getting these warnings from your build. You should double-check that you are editing the proper configuration file (proguard-project.txt
as of Android SDK r20).
I found a few things while integrating Proguard maybe it's helpful to you.
1>While using Google's License Verification Library we want to keep an additional class from being obfuscated in the additional library. for that I used proguard/config.txt file:
**-keep class com.android.vending.licensing.ILicensingService**
2> While using Google api for MapActivity, I got warnings:
can't find referenced classes for all come.google.android.maps classes, and "Note: the configuration refers to the unknown class 'com.google.android.maps'"`
When we use Google APIs, there is an additional library used to build the program. for that we need to adjust the path.
Normally there is just android.jar located in your SDK. but Google API adds another library, maps.jar, hidden away at android-sdk-windows\add-ons\addon_google_apis_google_inc_8\libs\maps.jar. We need to add this to the build.xml file. Find the optimize target in build.xml, and add the following text in bold to the proguard command by adjusting the path:
<arg value="-libraryjars ${android.jar}"/>
<arg value="-libraryjars ${sdk.dir}/add-ons\addon_google_apis_google_inc_8\libs\maps.jar"/>
Have a look at this ref: http://goo.gl/Ifgyj
3> Ref: Android Proguard skip external jar