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

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.

Related

Warning: com.google.android.gms.internal.zzig: can't find referenced class android.security.NetworkSecurityPolicy

I'm exporting android application (in Eclipse) and get the following error:
[2016-07-31 09:21:57 - EnglishPhonics] Proguard returned with error code 1. See console
[2016-07-31 09:21:57 - EnglishPhonics] Warning: com.google.android.gms.internal.zzig: can't find referenced class android.security.NetworkSecurityPolicy
[2016-07-31 09:21:57 - EnglishPhonics] Warning: com.google.android.gms.internal.zzig: can't find referenced class android.security.NetworkSecurityPolicy
[2016-07-31 09:21:57 - EnglishPhonics] Warning: com.google.android.gms.internal.zzig: can't find referenced class android.security.NetworkSecurityPolicy
[2016-07-31 09:21:57 - EnglishPhonics] You should check if you need to specify additional program jars.
[2016-07-31 09:21:57 - EnglishPhonics] Warning: there were 3 unresolved references to classes or interfaces.
[2016-07-31 09:21:57 - EnglishPhonics] You may need to specify additional library jars (using '-libraryjars').
[2016-07-31 09:21:57 - EnglishPhonics] java.io.IOException: Please correct the above warnings first.
[2016-07-31 09:21:57 - EnglishPhonics] at proguard.Initializer.execute(Initializer.java:321)
[2016-07-31 09:21:57 - EnglishPhonics] at proguard.ProGuard.initialize(ProGuard.java:211)
[2016-07-31 09:21:57 - EnglishPhonics] at proguard.ProGuard.execute(ProGuard.java:86)
[2016-07-31 09:21:57 - EnglishPhonics] at proguard.ProGuard.main(ProGuard.java:492)
I'm using Google Billing service with lastest version. Does anyone know how to solve this problem?

Android - can't export apk with Proguard, when using Joda Time

I use joda-time.jar in my app, and when exporting signed apk proguard saying something like (it is pretty common problem as I can see, when I look over internet):
[2014-01-07 12:44:53 - XYZ] Proguard returned with error code 1. See console
[2014-01-07 12:44:53 - XYZ] Warning: org.joda.time.DateMidnight: can't find referenced class org.joda.convert.FromString
[2014-01-07 12:44:53 - XYZ] Warning: org.joda.time.DateTime: can't find referenced class org.joda.convert.FromString
[2014-01-07 12:44:53 - XYZ] Warning: org.joda.time.Days: can't find referenced class org.joda.convert.FromString
...
[2014-01-07 12:44:53 - XYZ] Warning: org.joda.time.Years: can't find referenced class org.joda.convert.FromString
[2014-01-07 12:44:53 - XYZ] Warning: org.joda.time.Years: can't find referenced class org.joda.convert.ToString
[2014-01-07 12:44:53 - XYZ] Warning: org.joda.time.base.AbstractDuration: can't find referenced class org.joda.convert.ToString
[2014-01-07 12:44:53 - XYZ] Warning: org.joda.time.base.AbstractInstant: can't find referenced class org.joda.convert.ToString
[2014-01-07 12:44:53 - XYZ] Warning: org.joda.time.base.AbstractPeriod: can't find referenced class org.joda.convert.ToString
[2014-01-07 12:44:53 - XYZ] You should check if you need to specify additional program jars.
[2014-01-07 12:44:53 - XYZ] Warning: there were 37 unresolved references to classes or interfaces.
[2014-01-07 12:44:53 - XYZ] You may need to specify additional library jars (using '-libraryjars').
[2014-01-07 12:44:53 - XYZ] java.io.IOException: Please correct the above warnings first.
[2014-01-07 12:44:53 - XYZ] at proguard.Initializer.execute(Initializer.java:321)
[2014-01-07 12:44:53 - XYZ] at proguard.ProGuard.initialize(ProGuard.java:211)
[2014-01-07 12:44:53 - XYZ] at proguard.ProGuard.execute(ProGuard.java:86)
[2014-01-07 12:44:53 - XYZ] at proguard.ProGuard.main(ProGuard.java:492)
Everywhere in forums or also here (Android - Proguard didn't compile with Joda Time jar file) they say solution should be downloading joda-convert.jar, adding to buildpath. But for me it just DOESN'T WORK, after I did it, proguard again says something similar:
[2014-01-07 12:41:39 - XYZ] Proguard returned with error code 1. See console
[2014-01-07 12:41:39 - XYZ] Warning: org.joda.convert.JDKStringConverter$9: can't find referenced class javax.xml.bind.DatatypeConverter
[2014-01-07 12:41:39 - XYZ] Warning: org.joda.convert.JDKStringConverter$9: can't find referenced class javax.xml.bind.DatatypeConverter
[2014-01-07 12:41:39 - XYZ] Warning: org.joda.convert.JDKStringConverter$9: can't find referenced class javax.xml.bind.DatatypeConverter
[2014-01-07 12:41:39 - XYZ] You should check if you need to specify additional program jars.
[2014-01-07 12:41:39 - XYZ] Warning: there were 3 unresolved references to classes or interfaces.
[2014-01-07 12:41:39 - XYZ] You may need to specify additional library jars (using '-libraryjars').
[2014-01-07 12:41:39 - XYZ] java.io.IOException: Please correct the above warnings first.
[2014-01-07 12:41:39 - XYZ] at proguard.Initializer.execute(Initializer.java:321)
[2014-01-07 12:41:39 - XYZ] at proguard.ProGuard.initialize(ProGuard.java:211)
[2014-01-07 12:41:39 - XYZ] at proguard.ProGuard.execute(ProGuard.java:86)
[2014-01-07 12:41:39 - XYZ] at proguard.ProGuard.main(ProGuard.java:492)
How to fix this issue? I spend few hours of trying everything, but I just can't find it out...Many thanks!
Ok I figured it out. Actually adding joda-convert.jar to build path works, but only for older version (1.4 and lower, if you download latest one - 1.5 joda-convert.jar, it doesn't work)...

Error while creating android release build from eclipse

I'm trying to generate apk using Android tools > Export Signed apllication project, but I'm getting this error:
Proguard return with error code 1. See console
Console says:
[2013-08-21 17:03:56 - DisplayMetrics] Warning: there were 23 unresolved references to classes or interfaces.
[2013-08-21 17:03:56 - DisplayMetrics] You may need to specify additional library jars (using '-libraryjars').
[2013-08-21 17:03:56 - DisplayMetrics] java.io.IOException: Please correct the above warnings first.
[2013-08-21 17:03:56 - DisplayMetrics] at proguard.Initializer.execute(Initializer.java:321)
[2013-08-21 17:03:56 - DisplayMetrics] at proguard.ProGuard.initialize(ProGuard.java:211)
[2013-08-21 17:03:56 - DisplayMetrics] at proguard.ProGuard.execute(ProGuard.java:86)
[2013-08-21 17:03:56 - DisplayMetrics] at proguard.ProGuard.main(ProGuard.java:492)
This is happening from the time I added 3 jar files in libs folder. How can I fix this?

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

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.**

include jar in ant compilation android - command line linux

I'm trying to use a jar file in an android application on the linux command line. I've read:
Android include .jar in ant compilation
Which is the same thing but never got a working answer.
Tried this:
How to add external jar libraries to an android project from the command line
but it didn't work, still gave the same error message.
The error is:
-compile:
[javac] Compiling 4 source files to /home/bianca/Documents/sem12012/FIT3140 /code/jackson-example/bin/classes
[javac] messagemain.java:4: package org.codehaus.jackson.map does not exist
[javac] import org.codehaus.jackson.map.ObjectMapper;
[javac] ^
[javac] messagemain.java:21: cannot find symbol
[javac] symbol : class ObjectMapper
[javac] location: class messagemain
[javac] ObjectMapper mapper = new ObjectMapper();
[javac] ^
[javac] messagemain.java:21: cannot find symbol
[javac] symbol : class ObjectMapper
[javac] location: class messagemain
[javac] ObjectMapper mapper = new ObjectMapper();
[javac] ^
[javac] 3 errors
BUILD FAILED
/home/bianca/Downloads/android-sdk-linux/tools/ant/build.xml:602: The following error occurred while executing this line:
/home/bianca/Downloads/android-sdk-linux/tools/ant/build.xml:622: Compile failed; see the compiler error output for details.
So I'm guessing it's a problem with importing the jar. I have the jar stored in ./lib.
EDIT:
I put the jar in libs according to a suggestion in an answer, it gives the same error.
ant.properties is all comments, local.properties and project.properties have not been changed from the automatically generated one. build.xml has not been changed, it's just the automatically generated one.
Use libs/, not lib/. The JAR will automatically be included as part of the compile process, and the JAR's contents will be packaged into your APK.
When building using Eclipse "run", you can have imported JARs even in subfolders of the libs folder - you can, for example, have it in libs/somefodler/somJar.jar. The Ant script shipped with the SDK, however, expects it directly in the libs folder, and not a subfolder.

Categories

Resources