I downloaded the 25.1.6 release of Android tools today and I'm noticing that proguard is falling over with this error:
Error:Execution failed for task ':app:transformClassesWithNewClassShrinkerForDebug'.
> /usr/local/opt/android-sdk/tools/proguard/proguard-android.txt line 43:15 extraneous input '[]' expecting ')'
I'm certain that I've not changed anything in the proguard-android.txt file. Line 43 reads for me as follows:
void set*(%[]);
I'm noticing that the file here...
https://android.googlesource.com/platform/sdk/+/android-6.0.1_r43/files/proguard-android.txt
... is different to what I have on my machine? Is that file the latest version of the file that I should have?
Just to know several options:
The thing that helped me is replacing corresponding proguard-android.txt file with the one from this page
And just in case the page goes away saving its content here:
# This is a configuration file for ProGuard.
# http://proguard.sourceforge.net/index.html#manual/usage.html
-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);
}
-keepclassmembers class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator 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.**
Hmm, it looks the tools/proguard folder in my local copy of the Android SDK is not updated by the Android SDK Manager. I just downloaded the Android SDK afresh from here...
http://developer.android.com/sdk/index.html
... and replaced the tools/proguard folder in that distribution over the tools/proguard in my local copy of the Android SDK and the error's gone.
Would be great if the tools/proguard folder was updated via the Android SDK Manager.
Seems that's happening to some of us. I downloaded just the folder attached in this answer and copied it to android-sdk/tools folder overwriting what's there and now it works without problems.
https://code.google.com/p/android/issues/detail?id=210012
In debug mode I set minifyEnabled to false
Related
i am working on xamarin application. When i enable "ProGuard" in android properties, while building the application, I'm getting the following error:
"java.exe" exited with code1.
proguard cfg file has the following:
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
Developing Environment:
Visual Studio 2015
Xamarin 4.0.4.4
I had the same issue when enabling ProGuard. By following the advice on this link, I fixed the issue by updating my proguard manually. The steps are fairly easy to follow and they fixed the problem. Hope this helps you.
Download the ProGuard zip file available from: https://sourceforge.net/projects/proguard/files/. At time of writing the latest version of ProGuard was 5.3.
ProGuard does not have a setup program, so you will need to unzip the file and copy the proguard folder structure into the location identified in the steps below.
Launch the SDK Manager and note the path in the top left under the menu options. In my case this was C:\Users\Sahar\AppData\Local\Android\android-sdk. The proguard folder is located in the tools folder of this path (in my case this was C:\Users\Sahar\AppData\Local\Android\android-sdk\tools\proguard).
Close any development environments that might be accessing the SDK and rename the proguard folder to proguard.old.
Copy the proguard folder of the new version into the tools folder and rename it to proguard if necessary (in my case the copied folder was renamed from proguard5.3).
Finally copy the configuration files from the proguard.old folder to the new folder. In my case these were:-
proguard-android.txt, proguard-android-optimize.txt and proguard-project.txt.
Clean and rebuild your project with ProGuard enabled.
I had a problem where Proguard was removing the Google Play Services libraries from my app.
I had to add the following lines of text to the proguard-android.txt file found in this folder:
/(Path to your Android SDK Folder)/tools/proguard
-keep public class com.google.android.gms.* { public *; }
-dontwarn com.google.android.gms.**
Complete proguard-android.txt File
-keep public class com.google.android.gms.* { public *; }
-dontwarn com.google.android.gms.**
# This is a configuration file for ProGuard.
# http://proguard.sourceforge.net/index.html#manual/usage.html
-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);
}
-keepclassmembers class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator 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.**
# Understand the #Keep support annotation.
-keep class android.support.annotation.Keep
-keep #android.support.annotation.Keep class * {*;}
-keepclasseswithmembers class * {
#android.support.annotation.Keep <methods>;
}
-keepclasseswithmembers class * {
#android.support.annotation.Keep <fields>;
}
-keepclasseswithmembers class * {
#android.support.annotation.Keep <init>(...);
}
EDIT: For future devs who may be suffering from the same issues, I'm afraid I can't be of much use. The problem apparently solved itself during future versions of the app, but I have been unable to ascertain the cause.
I've been testing an application through the Google Play closed beta testing system, using my friends as beta testers. After pushing an update where the .apk was obfuscated using ProGuard, two testers started reporting crashes. The crashes are unpredictable and sporadic, and they have been unable to ascertain any reason or pattern for them. To make things worse, the crash reports I'm getting in the Dev Console contain no information at all, simply stating "Native crash at (no location available)", no stack trace, not even any device information.
I do know the device information through just asking the testers in question, and both devices are Sony phones, an Xperia Z3 and an Xperia Z3 Compact. However, I also have a Z3 Compact available for testing and have been unable to reproduce the crash while running the same obfuscated apk. We are running the same OS version as well.
I have sent one of the testers and unobfuscated apk, and he was unable to reproduce the crash running that version. This, and the fact that the crash first occurred after a patch that introduced ProGuard obfuscation, leads me to believe that to be the cause.
At first, I ran ProGuard using only the default configuration file from the SDK:
# This is a configuration file for ProGuard.
# LINK REMOVED
-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 LINK REMOVED
-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);
}
-keepclassmembers class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator 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.**
I have since added the following lines to proguard-project.txt, which is also included in the proguard configuration variable for the project:
-keep class * extends java.util.ListResourceBundle {
protected java.lang.Object[][] getContents();
}
# Keep SafeParcelable value, needed for reflection. This is required to support backwards
# compatibility of some classes.
-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
public static final *** NULL;
}
# Keep the names of classes/members we need for client functionality.
-keepnames #com.google.android.gms.common.annotation.KeepName class *
-keepclassmembernames class * {
#com.google.android.gms.common.annotation.KeepName *;
}
# Needed for Parcelable/SafeParcelable Creators to not get stripped
-keepnames class * implements android.os.Parcelable {
public static final ** CREATOR;
}
# Needed when building against the Marshmallow SDK
-dontwarn org.apache.http.**
# Needed when building against pre-Marshmallow SDK.
-dontwarn android.security.NetworkSecurityPolicy
-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
-libraryjars D:/Docs/Android/spaceprog/spaceprogr/libs/android-support-v4.jar
-keep class com.viewpagerindicator.** { *; }
-keep class com.google.android.gms.** { *; }
-keep class com.google.example.games.basegameutils.** { *; }
-printmapping out.map
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable
The upper part (with comments) of these additions comes directly from the README of the Google Play Services as a recommendation to be added whenever using the library. The rest I added myself while trying to research and debug the problem.
If anyone notices any omissions or other signs of trouble in my ProGuard configuration I'd be happy to know. I'd also be greatful for any suggestions on how to further debug the problem. Keep in mind that full module testing where only one module is obfuscated at a time is impossible in this case, because I do not have a device that can reproduce the issue and I cannot ask volunteer testers to install 30+ different versions of the .apk and play until it either crashes or until they are confident it will not.
I'm having troubles compiling an app that uses ProGuard and Google Analytics v4. A single other thread that seems to be similar is here, except there aren't very many details.
I've tried the following to no avail:
Doing keep com.google.** { *; }
Doing a -keep android.support.** { *; } package. This error continues to crop up with every other bit of obfuscated code, as if joining the newly obfuscated code with the pre-obfuscated Google Analytics code always causes errors.
Using -keepattributes Signature in case there's an issue with generics.
Using an obfuscated dictionary of four-letter words (such as rNqp, sSlq) in case something to do with Android dexing causes the pre-obfuscated Google Analytics classes to conflict with the obfuscated project files.
Here is the exception:
11-08 22:45:01.644 2206-2226/com.example.helloworld E/GAV3﹕ Thread[GAThread,5,main]: Error on GAThread: java.lang.ClassCastException: android.net.ConnectivityManager cannot be cast to android.support.v4.d.a
at com.google.a.a.a.at.a(Unknown Source)
at com.google.a.a.a.am.a(Unknown Source)
at com.google.a.a.a.s.h(Unknown Source)
at com.google.a.a.a.s.g(Unknown Source)
at com.google.a.a.a.s.a(Unknown Source)
at com.google.a.a.a.u.run(Unknown Source)
at com.google.a.a.a.ab.run(Unknown Source)
11-08 22:45:01.644 2206-2226/com.example.helloworld E/GAV3﹕ Thread[GAThread,5,main]: Google Analytics is shutting down.
Proguard configuration file (99.9% vanilla):
# This is a configuration file for ProGuard.
# http://proguard.sourceforge.net/index.html#manual/usage.html
# Optimizations: If you don't want to optimize, use the
# proguard-android.txt configuration file instead of this one, which
# turns off the optimization flags. Adding optimization introduces
# certain risks, since for example not all optimizations performed by
# ProGuard works on all versions of Dalvik. The following flags turn
# off various optimizations known to have issues, but the list may not
# be complete or up to date. (The "arithmetic" optimization can be
# used if you are only targeting Android 2.0 or later.) Make sure you
# test thoroughly if you go this route.
#-optimizations !code/simplification/cast,!field/*,!class/merging/*
#-optimizationpasses 5
#-allowaccessmodification
#-dontpreverify
# The remainder of this file is identical to the non-optimized version
# of the Proguard configuration file (except that the other file has
# flags to turn off optimization).
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-verbose
-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.**
-keepattributes Signature
It seems like you're using a copy of proguard-android-optimize.txt (a more common approach is to refer to the original, maintained file in the Android SDK). You can try disabling optimization:
-dontoptimize
If this indeed avoids the problem, you can report the issue in ProGuard's bug tracker or to me directly.
Make sure that you are using the latest version of ProGuard (version 5.1 at this time of writing) and the latest version of the GMS library.
(I am the developer of ProGuard)
I've found the solution. It just involves not obfuscating the ConnectivityManager. I've used:
-keep android.net.** { *; }
which is working fine.
My project is working perfectly on android device and emulator.
But, If i export and taken the .apk file after enabled with proguard application getting struck, I cant install this .apk file with proguard.
My assumption, Service is not called while installing the .apk file and i did't get any error on my log.
Please kindly share your ideas.
Here is my proguard file.
-optimizationpasses 5
-dontskipnonpubliclibraryclasses
-dontskipnonpubliclibraryclassmembers
-dontpreverify
-verbose
-dontoptimize
# -optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-libraryjars /usr/local/android-sdk/add-ons/google_apis-7_r01/libs/maps.jar
-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
-keepattributes JavascriptInterface
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
-keep class mypackage.MyCallbackClass {
void myCallbackMethod(java.lang.String);
}
-dontwarn android.support.**
-dontwarn org.w3c.dom.bootstrap.DOMImplementationRegistry
and my ** project.properties file**
# 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
#proguard.config=proguard.cfg
# Project target.
target=Google Inc.:Google APIs:11
android.library.reference.1=../Library1
android.library.reference.2=../Library2
Please kindly share your ideas.
Thank You.
I suppose you are signing this version with a release key.
If you have an older installation on your phone(with a debug key),please uninstall it first.(You can't have the same app with two different signatures on your device)
FAILED BINDER TRANSACTION usually occurs when you have overflowed the Binder process. If you are not using large bitmaps on your splash page (which is the most common reason for a failed binder transaction) then it might be a ParcelFormatException, since I notice you're trying to use a Parcelable in your apk.
Assuming you're keeping ADT up to date..
If you're building the release version of your application using Eclipse export, it will load Proguard settings from the file specified by the proguard.config property in project.properties.
If you are using ant release, it will load the Proguard settings from the file specified by the proguard.config property in ant.properties.
That being said, are you getting any kind of errors or warnings during your build? These are especially helpful when diagnosing Proguard since it's purpose is to remove classes and methods that it doesn't think are being used by your application.
I uninstall my apps using:
adb shell pm uninstall -k com.*example*.*app*
And reinstall using:
adb install App-release.apk
If it gives an error about compatability, I discard the previous application data by excluding the -k switch from the uninstall command:
adb shell pm uninstall com.*example*.*app*
I am using the code from proguard-android.txt file below
# This is a configuration file for ProGuard.
# http://proguard.sourceforge.net/index.html#manual/usage.html
-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.**
to obfuscate Android code.
My Question Does Proguard remove all the comments from the Java source file when we use the above settings in Proguard?
ProGuard doesn't remove anything from the source files, regardless of settings. ProGuard makes sure that the compiled files have obfuscated method/class names and strips appropriate methods/classes completely when possible.
Compiled Java binaries don't include regular code comments whether you're using ProGuard or not.