Getting error while generating the .apk file if proguard is ON - android

I am using proguard to obfuscate the code.
I am getting the following error in console
Proguard returned with error code 1. See console
Warning: org.apache.cordova.CameraLauncher: can't find referenced class org.apache.commons.codec.binary.Base64
Warning: org.apache.cordova.CameraLauncher: can't find referenced class org.apache.commons.codec.binary.Base64
Warning: org.apache.cordova.CordovaWebView: can't find referenced method 'WebView(android.content.Context,android.util.AttributeSet,int,boolean)' in class android.webkit.WebView
Warning: org.apache.cordova.CordovaWebViewClient: can't find referenced method 'android.webkit.WebResourceResponse shouldInterceptRequest(android.webkit.WebView,java.lang.String)' in class android.webkit.WebViewClient
Warning: org.apache.cordova.CordovaWebViewClient: can't find referenced class android.webkit.WebResourceResponse
Warning: org.apache.cordova.CordovaWebViewClient: can't find referenced class android.webkit.WebResourceResponse
Warning: org.apache.cordova.CordovaWebViewClient: can't find referenced class android.webkit.WebResourceResponse
Warning: org.apache.cordova.CordovaWebViewClient: can't find referenced class android.webkit.WebResourceResponse
Warning: org.apache.cordova.CordovaWebViewClient: can't find referenced class android.webkit.WebResourceResponse
Warning: org.apache.cordova.FileUtils: can't find referenced class org.apache.commons.codec.binary.Base64
Warning: org.apache.cordova.FileUtils: can't find referenced class org.apache.commons.codec.binary.Base64
Warning: there were 9 unresolved references to classes or interfaces.
You may need to specify additional library jars (using '-libraryjars').
Warning: there were 2 unresolved references to program class members.
Your input classes appear to be inconsistent.
You may need to recompile them and try again.
Alternatively, you may have to specify the option
'-dontskipnonpubliclibraryclassmembers'.
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)
My project.properties file is here
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system edit
# "ant.properties", and override values to adapt the script to your
# project structure.
#
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
proguard.config=~/Desktop/Android/android-sdk-macosx/tools/proguard/proguard-android.txt:proguard-project.txt
# Project target.
target=android-10
My proguard-project.txt is here
# To enable ProGuard in your project, edit project.properties
# to define the proguard.config property as described in that file.
#
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in ${sdk.dir}/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
How to solve this?

I fixed it by adding this in my proguard-project.txt
-keep public class * extends com.phonegap.api.Plugin
-keep public class org.apache.cordova.DroidGap
-keep public class org.apache.cordova.**
-libraryjars /Users/Nasir/Desktop/libs/commons-codec.jar
-dontwarn android.webkit.*

You can add the following to your proguard-project.txt. It worked for me on Cordova (PhoneGap) 2.1:
-keep public class * extends com.phonegap.api.Plugin
-keep public class * extends org.apache.cordova.api.Plugin
-keep public class org.apache.cordova.DroidGap
-keep public class org.apache.cordova.**
-libraryjars libs/commons-codec-1.7.jar
-dontwarn android.webkit.*
-dontwarn org.apache.**

Related

Using proguard to generate apk with the common libaries

I have the following library in my project
As jar:
httpcore-4.3.1.jar
httpmime-4.3.2.jar
libGoogleAnalyticsServices.jar (latest GA version)
As import project
facebookSDK 3.6
I have added the following to proguard-project.txt
# To enable ProGuard in your project, edit project.properties
# to define the proguard.config property as described in that file.
#
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in ${sdk.dir}/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
-keep class org.apache.**
-keep interface org.apache.**
-keep class com.facebook.** { *; }
-keepattributes Signature
-dontwarn org.apache.**
and in the properties
proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
It can generate the signed apk, but it will throw exception
NoSuchMethodError: org.apache.http.params.HttpConnectionParams...
How to fix the problem? As I have add the keep class already? Thanks for helping
put { *; } at the end of -keep interface org.apache.** and those -keep rules

Proguard Returned With Error Code 1 Without Any Specific Information

I have problem with proguard, I have tried with many possible solutions but still does not solve my problem.
The only information I get from console is
Proguard returned with error code 1. See console
nothing more, this is a really bad error message I ever met.
I have set
proguard.config=proguard-project.txt
and nothing in proguard-project.txt that I believe only a couple of comments.
# To enable ProGuard in your project, edit project.properties
# to define the proguard.config property as described in that file.
#
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in ${sdk.dir}/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# This is a configuration file for ProGuard.
# http://proguard.sourceforge.net/index.html#manual/usage.html
After couples of hours finding the solution, I found the solution. I just moved the proguard.jar to another directory which there is no space in the path, then I edited the proguard.bat in /bin folder to that directory. Eventually, the proguard is running fine and give me the error log that I expected.
Sample script.
#ECHO OFF
REM Start-up script for ProGuard -- free class file shrinker, optimizer,
REM obfuscator, and preverifier for Java bytecode.
rem Change current directory and drive to where the script is, to avoid
rem issues with directories containing whitespaces.
cd /d %~dp0
IF EXIST "%PROGUARD_HOME%" GOTO home
SET PROGUARD_HOME=..
:home
java -jar C:\bin\proguard.jar %*
You have commented text file, it should be like this :
# To enable ProGuard in your project, edit project.properties
# to define the proguard.config property as described in that file.
#
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in ${sdk.dir}/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
-keepclassmembers class fqcn.of.javascript.interface.for.webview {
public *;
}
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-verbose
# Optimization is turned off by default. Dex does not like code run
# through the ProGuard optimize and preverify steps (and performs some
# of these optimizations on its own).
-dontoptimize
-dontpreverify
# Note that if you want to enable optimization, you cannot just
# include optimization flags in your own project configuration file;
# instead you will need to point to the
# "proguard-android-optimize.txt" file instead of this one from your
# project.properties file.
-keepattributes *Annotation*
-keep public class com.google.vending.licensing.ILicensingService
-keep public class com.android.vending.licensing.ILicensingService
# For native methods, see http://proguard.sourceforge.net/manual/examples.html#native
-keepclasseswithmembernames class * {
native <methods>;
}
# keep setters in Views so that animations can still work.
# see http://proguard.sourceforge.net/manual/examples.html#beans
-keepclassmembers public class * extends android.view.View {
void set*(***);
*** get*();
}
# We want to keep methods in Activity that could be used in the XML attribute onClick
-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}
# For enumeration classes, see http://proguard.sourceforge.net/manual/examples.html#enumerations
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
-keepclassmembers class **.R$* {
public static <fields>;
}
# The support library contains references to newer platform versions.
# Don't warn about those in case this app is linking against an older
# platform version. We know about them, and they are safe.
-dontwarn android.support.**
Build using following commands:
cd <you project directory>
#update project properties
android update project -t 3 -p .
#clean the code
ant clean
# build the application
ant release

Android Proguard - Internet connectivity issue after exporting application

I am currently exporting application while proguard is enabled and the issue is that the application works fine but application is deployed without proguard but if exported and deployed while proguard is enabled the application gives error that internet is not connected. following is the proguard file text
-dontshrink
-dontoptimize
-dontwarn com.example.google.tv.**
-dontwarn android.support.**
-dontwarn org.ksoap.**
-dontwarn android.view.**
-dontwarn android.graphics.**
-dontwarn android.content.**
-dontwarn android.util.**
-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
#-libraryjars libs/ksoap2-android-assembly-2.5.2-jar-with-dependencies.jar
#-libraryjars libs/android-support-v4.jar
If I remove
-dontwarn android.view.**
-dontwarn android.graphics.**
-dontwarn android.content.**
-dontwarn android.util.**
then here is the log that I receive
[2013-08-02 10:29:04 - Project] Proguard returned with error code 1. See console
[2013-08-02 10:29:04 - Project] Note: there were 4 duplicate class definitions.
[2013-08-02 10:29:04 - Project] Warning: library class android.content.res.XmlResourceParser extends or implements program class org.xmlpull.v1.XmlPullParser
[2013-08-02 10:29:04 - Project] Warning: library class android.content.Intent depends on program class org.xmlpull.v1.XmlPullParser
[2013-08-02 10:29:04 - Project] Warning: library class android.content.IntentFilter depends on program class org.xmlpull.v1.XmlSerializer
[2013-08-02 10:29:04 - Project] Warning: library class android.content.IntentFilter depends on program class org.xmlpull.v1.XmlPullParser
[2013-08-02 10:29:04 - Project] Warning: library class android.content.res.ColorStateList depends on program class org.xmlpull.v1.XmlPullParser
[2013-08-02 10:29:04 - Project] Warning: library class android.graphics.drawable.BitmapDrawable depends on program class org.xmlpull.v1.XmlPullParser
[2013-08-02 10:29:04 - Project] Warning: library class android.graphics.drawable.ColorDrawable depends on program class org.xmlpull.v1.XmlPullParser
[2013-08-02 10:29:04 - Project] Warning: library class android.graphics.drawable.Drawable depends on program class org.xmlpull.v1.XmlPullParser
[2013-08-02 10:29:04 - Project] Warning: library class android.graphics.drawable.Drawable depends on program class org.xmlpull.v1.XmlPullParser
[2013-08-02 10:29:04 - Project] Warning: library class android.graphics.drawable.Drawable depends on program class org.xmlpull.v1.XmlPullParser
[2013-08-02 10:29:04 - Project] Warning: library class android.graphics.drawable.LayerDrawable depends on program class org.xmlpull.v1.XmlPullParser
[2013-08-02 10:29:04 - Project] Warning: library class android.view.LayoutInflater depends on program class org.xmlpull.v1.XmlPullParser
[2013-08-02 10:29:04 - Project] Warning: library class android.view.LayoutInflater depends on program class org.xmlpull.v1.XmlPullParser
[2013-08-02 10:29:04 - Project] You should check if you need to specify additional program jars.
[2013-08-02 10:29:04 - Project] Warning: there were 13 instances of library classes depending on program classes.
[2013-08-02 10:29:04 - Project] You must avoid such dependencies, since the program classes will
[2013-08-02 10:29:04 - Project] be processed, while the library classes will remain unchanged.
[2013-08-02 10:29:04 - Project] java.io.IOException: Please correct the above warnings first.
[2013-08-02 10:29:04 - Project] at proguard.Initializer.execute(Initializer.java:321)
[2013-08-02 10:29:04 - Project] at proguard.ProGuard.initialize(ProGuard.java:211)
[2013-08-02 10:29:04 - Project] at proguard.ProGuard.execute(ProGuard.java:86)
[2013-08-02 10:29:04 - Project] at proguard.ProGuard.main(ProGuard.java:492)
You should remove the package org.xmlpull.v1 from your libraries. It is already present in the Android runtime (which gets precedence anyway). Adding duplicate packages increases the application size at best, and it can cause versioning problems at worst. In this case, ProGuard detects some dependency conflicts.
Note that is "ProGuard", not "Progaurd".

proguard.ParseException: Expecting class member name before '#' in Android Eclipse ADT

i try to optimize my Android Application code using Proguard with eclipse ADT v21.1.0-569685 on MAC.
i used project->Android Tools->export asigned Application package option for signing with my private certificate,on finish of signing i got following error,
project.properties
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system edit
# "ant.properties", and override values to adapt the script to your
# project structure.
#
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
# Project target.
target=android-17
android.library.reference.1=../google-play-services_lib
proguard-project.txt
# To enable ProGuard in your project, edit project.properties
# to define the proguard.config property as described in that file.
#
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in ${sdk.dir}/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
Console Log:
[2013-04-12 10:41:53 - MyApp] Proguard returned with error code 1. See console
[2013-04-12 10:41:53 - MyApp] proguard.ParseException: Expecting class member name before '#' in line 82 of file '/Users/MyOrg/Android_workspace/MyApp/bin/proguard.txt',
[2013-04-12 10:41:53 - MyApp] included from argument number 6
[2013-04-12 10:41:53 - MyApp] at proguard.ConfigurationParser.readNextWord(ConfigurationParser.java:1133)
[2013-04-12 10:41:53 - MyApp] at proguard.ConfigurationParser.readNextWord(ConfigurationParser.java:1117)
[2013-04-12 10:41:53 - MyApp] at proguard.ConfigurationParser.parseMemberSpecificationArguments(ConfigurationParser.java:845)
[2013-04-12 10:41:53 - MyApp] at proguard.ConfigurationParser.parseClassSpecificationArguments(ConfigurationParser.java:697)
[2013-04-12 10:41:53 - MyApp] at proguard.ConfigurationParser.parseKeepClassSpecificationArguments(ConfigurationParser.java:490)
[2013-04-12 10:41:53 - MyApp] at proguard.ConfigurationParser.parse(ConfigurationParser.java:139)
[2013-04-12 10:41:53 - MyApp] at proguard.ProGuard.main(ProGuard.java:484)
How to solve the above issue?
In prouard.project file I read
If your project uses WebView with JS, uncomment the following and
specify the fully qualified class name to the JavaScript interface
class:
I have used webview in two activity with WebAppInterface.java class.How to do above statement?
Referring resource name like "#string/on_click_handler_name", in android:onClick attribute of your layout file is ok. However, proguard cannot resolve these references.
Check http://android.okhelp.cz/proguard-parseexception-expecting-class-member-name-before/ for more details.
Find corresponding value of #string/tha_lf_et_todate_onclick in your string.xml and update :
android:onClick="#string/tha_lf_et_todate_onclick"
to
android:onClick="onClickXXX"
in your layout file.
For the second question,
uncomment that piece of code, and replace "fqcn.of.javascript.interface.for.webview"
with the class's fully qualified name.

Android ant build.xml with proguard does not build in release

I have the following project setup:
Two libraries 'commoncomponents' and 'libs' that both have some activities defined e.g. with a webview and dialog helper classes.
Then there is my 'application library' which contains the app code which in turn is
referenced by the App 'Free' and the App 'Full'.
I have enabled proguard with the following additional entry
-keepclassmembers class **.R$* {
public static <fields>;
}
However the build process fails when launching ant with the release target and proguard
complains that the R$string classes are missing
If I call 'ant release' on 'commoncomponents', 'libs' or 'application library' projects proguard succeeds,
But when I launch it on either the 'app free' or 'app full' this errormessage is comes up:
[echo] ----------
[echo] Creating output directories if needed...
[mkdir] Created dir: ~/Workspace/Workspaces/workspace-indigo/MyApp/bin/classes
[echo] ----------
[echo] Resolving Dependencies for bin...
[dependency] Library dependencies:
[dependency] ------------------
[dependency] Ordered libraries:
[dependency] ------------------
[dependency] API<=15: Adding annotations.jar to the classpath.
-pre-build:
-code-gen:
[mergemanifest] No changes in the AndroidManifest files.
[echo] Handling aidl files...
[aidl] Found 2 AIDL files.
[aidl] No AIDL files to compile.
[echo] ----------
[echo] Handling RenderScript files...
[renderscript] No RenderScript files to compile.
[echo] ----------
[echo] Handling Resources...
[aapt] No changed resources. R.java and Manifest.java untouched.
[echo] ----------
[echo] Handling BuildConfig class...
[buildconfig] Build type changed: Generating new BuildConfig class.
-pre-compile:
-compile:
[javac] Compiling 12 source files to ~/Workspace/Workspaces/workspace-indigo/MyApp/bin/classes
[echo] Creating library output jar file...
[jar] Building jar: ~/Workspace/Workspaces/workspace-indigo/MyApp/bin/classes.jar
-post-compile:
-obfuscate:
[delete] Deleting: ~/Workspace/Workspaces/workspace-indigo/MyApp/bin/proguard/original.jar
[jar] Building jar: ~/Workspace/Workspaces/workspace-indigo/MyApp/bin/proguard/original.jar
[proguard] ProGuard, version 4.7
[proguard] Reading input...
[proguard] Reading program jar [~/Workspace/Workspaces/workspace-indigo/MyApp/bin/proguard/original.jar]
[proguard] Reading program jar [~/Workspace/Workspaces/workspace-indigo/CommonComponents/bin/classes.jar]
[proguard] Reading program jar [~/Workspace/Workspaces/workspace-indigo/exampleLib/bin/classes.jar]
[proguard] Reading program jar [~/Workspace/Workspaces/workspace-indigo/Bfw/bin/classes.jar]
[proguard] Reading program jar [/Developer/Java/android-sdk-macosx/tools/support/annotations.jar]
[proguard] Reading program jar [~/Workspace/Workspaces/workspace-indigo/MyApp/libs/android-support-v4.jar]
[proguard] Reading library jar [/Developer/Java/android-sdk-macosx/platforms/android-10/android.jar]
[proguard] Reading library jar [/Developer/Java/android-sdk-macosx/add-ons/addon-real3d-lge-10/libs/real3d.jar]
[proguard] Initializing...
[proguard] Warning: com.example.ApplicationBase: can't find referenced class com.example.lib.R$string
[proguard] Warning: com.example.ApplicationBase: can't find referenced class com.example.lib.R$string
[proguard] Warning: com.example.ApplicationBase: can't find referenced class com.example.lib.R$string
[proguard] Warning: com.example.ApplicationBase: can't find referenced class com.example.lib.R$string
[proguard] Warning: com.example.ApplicationBase: can't find referenced class com.example.lib.R$string
[proguard] Warning: com.example.ApplicationBase: can't find referenced class com.example.lib.R$string
[proguard] Warning: com.example.ApplicationBase: can't find referenced class com.example.lib.R
[proguard] Warning: com.example.common.HelpDialog: can't find referenced class com.example.common.R$string
[proguard] Warning: com.example.common.HelpDialog: can't find referenced class com.example.common.R$string
[proguard] Warning: com.example.common.HelpDialog: can't find referenced class com.example.common.R
[proguard] Warning: com.example.common.WebDialog: can't find referenced class com.example.common.R$layout
[proguard] Warning: com.example.common.WebDialog: can't find referenced class com.example.common.R$id
[proguard] Warning: com.example.common.WebDialog: can't find referenced class com.example.common.R$string
[proguard] Warning: com.example.common.WebDialog: can't find referenced class com.example.common.R$layout
[proguard] Warning: com.example.common.WebDialog: can't find referenced class com.example.common.R$id
[proguard] Warning: com.example.common.WebDialog: can't find referenced class com.example.common.R$string
[proguard] Warning: com.example.common.WebDialog: can't find referenced class com.example.common.R
[proguard] Warning: com.example.common.WebDialog$1: can't find referenced class com.example.common.R$string
[proguard] Warning: com.example.common.WebDialog$1: can't find referenced class com.example.common.R$string
[proguard] Warning: com.example.common.WebDialog$1: can't find referenced class com.example.common.R
[proguard] Warning: com.example.dlg.InfoDialogActivity: can't find referenced class com.example.lib.R$layout
[proguard] Warning: com.example.dlg.InfoDialogActivity: can't find referenced class com.example.lib.R$layout
[proguard] Warning: com.example.dlg.InfoDialogActivity: can't find referenced class com.example.lib.R
[proguard] Note: the configuration refers to the unknown class 'com.google.vending.licensing.ILicensingService'
[proguard] Note: the configuration refers to the unknown class 'com.android.vending.licensing.ILicensingService'
[proguard] Note: there were 2 references to unknown classes.
[proguard] You should check your configuration for typos.
[proguard] Warning: there were 23 unresolved references to classes or interfaces.
[proguard] You may need to specify additional library jars (using '-libraryjars').
BUILD FAILED
/Developer/Java/android-sdk-macosx/tools/ant/build.xml:570: The following error occurred while executing this line:
/Developer/Java/android-sdk-macosx/tools/ant/build.xml:834: Please correct the above warnings first.
The project setup seems ok to me, since 'ant debug' compiles without errors.
The package name was changed to com.example and my user dir to ~/xy in the listing above
I've searched the web for the issue and I found a lot of posts especially here on stackoverflow, but none helped me solve the issue yet, hope someone is so kind to assist although this is my very first question.
Thanks
It turned out that the application library build file had the proguard obfuscation switched on, by switching it off all symbols were found when building the free and full application stubs.

Categories

Resources