I add '-android' in my project's proguard-rules.pro file,but when I release my project,the Gradle Console gives the Warning:
Warning: Exception while processing task java.io.IOException: proguard.ParseException: Unknown option '-android' in line 31 of file '/Users/yushuifeng/workspace/cccx_app_3.0/app/proguard-rules.pro'
:app:transformClassesAndResourcesWithProguardForRelease FAILED
why?
I add this option because the official website says
-android
Specifies that the processed class files are targeted at the Android platform. ProGuard then makes sure some features are compatible with Android. For example, you should specify this option if you are processing an Android application.
refs:https://www.guardsquare.com/en/proguard/manual/usage#preverificationoptions
sorry I don't know how to format the text,so I can post my code in proguard-rules.pro file, just a standard proguard with an additional option
-android
Try adding -ignorewarnings in your proguard-rules.pro file, then clean & build your project.
The option -android was added in ProGuard 6.0. It is very likely that your standard gradle setup uses a different version of ProGuard. The version being used should be printed if you enable -i for your gradle build and possibly add -verbose to your proguard rules.
Related
I want to obfuscate my android apk file using proguard or any other method. tried many ways including :-
copy-pasting proguard.txt and proguard-optimise.txt file from sdk folder (sdk-tools-progurad) to my app module within the project directory
I have written minifyEnabled=true in gradle file of app.
After doing so facing further issue of some proguard errors giving warnings for external library class files.
Error: -Error:Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease'.
java.io.IOException: Please correct the above warnings first.
Even I am unable to generate signed apk.
It is strongly advised to investigate the warnings that ProGuard prints to the console and try to fix them. For this you will have to either include additional libraries or add -dontwarn directives to your proguard-project.txt file.
As a last resort, you can also use -ignorewarnings which will instruct ProGuard to continue regardless of any remaining warning.
When I try to generate a release version for my app I get the bellow error :
Error:Execution failed for task ':app:proguardRelease'.
java.io.IOException: Please correct the above warnings first.
Blockquote
You may need to add missing library jars or update their versions.
If your code works fine without the missing classes, you can suppress
the warnings with '-dontwarn' options.
(http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass)
How can I force Android Studio Gradle plugin to use -dontwarn option ?
This occurs because the release build is using Proguard. You will need to add Proguard rules in proguard-rules.pro for some of the dependencies you are using. Most libraries provide the Proguard rules needed; look on their README page.
The -dontwarn option isn't an option for Android Studio or the Android Gradle Plugin. It is a ProGuard option used to tell ProGuard not to warn you about potential problems.
From the ProGuard manual:
-dontwarn
Specifies not to warn about unresolved references and other important problems at all. The optional filter is a regular expression; ProGuard doesn't print warnings about classes with matching names. Ignoring warnings can be dangerous. For instance, if the unresolved classes or class members are indeed required for processing, the processed code will not function properly. Only use this option if you know what you're doing!
If you need to use this option, then it should go in your project-specific ProGuard file (see here if you don't know how to add your own ProGuard file).
I try to run proguard on an Android project contain classes.jar (library from Unity3d software) in attachement. I have error:
[2014-03-04 15:28:55 - Test0289_0304] Proguard returned with error code 1. See console
[2014-03-04 15:28:55 - Test0289_0304] Error: Can't read [F:\140303\Test0289_0304\lib\untiy-classes.jar] (Can't process class [com/unity3d/player/UnityPlayer.class] (Unknown verification type [251] in stack map frame))
I add one line in proguard-project.txt:
-libraryjars lib/untiy-classes.jar
I use proguard 4.11.
This is an issue with the classes in the Unity library: some of the preverification metadata are corrupt. You should check if there is a more recent version. Otherwise, you could modify ProGuard to accept the corrupt classes, as discussed on its issue tracker.
Note that you should not add -libraryjars or -injars to your configuration. The Android build process (Ant, Eclipse, Gradle) already specifies those options for you.
After updating to ADT 20 I can no longer successfully export any of my Android projects. I get:
Proguard returned with error code 1. See console
In the console I get tons of the can't find referenced class warnings and occasionally the can't find superclass or interface warning. At the end of the warnings I get something like this:
You should check if you need to specify additional program jars.
Warning: there were 199 unresolved references to classes or interfaces.
You may need to specify additional library jars (using '-libraryjars').
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)
Each time I attempt to build I get different numbers of warnings (it's not very consistent). Also, when I perform a clean before export, the export completes without producing any warnings, but the resulting APK crashes on launch often due to ClassNotFoundException.
My proguard-project.txt includes the necessary -keep class rules for the Android Support Library and ActionBarSherlock.
I had no problems building this project before ADT 20. I even tried building my last release (which obviously built fine when I released it), but I get the same proguard warnings and failed export.
I've tried adding -libraryjars and/or -dontwarn rules as many other SO questions suggest, but to no avail. It will sometimes build successfully, but the APK created crashes on launch.
Any suggestions?
There is a bug in AAPT where it will only process
<fragment android:name"..." />
but not
<fragment class="..." />
We'll fix AAPT but in the meantime you can use the other attribute and it'll work.
In ADT 20, we use a feature of aapt (see the -G flag) which can create a proguard file which contains keep rules for exactly the custom views used by your code.
The old proguard config files would keep all views. When you used a library project such as the compatibility library, where you might be using only a small subset of the available code, this could end up including a lot of stuff you don't need. By removing the generic keep rules, and adding a new keep file based on your application, your .apks would get smaller since a lot of unused stuff can be removed.
One area where this can go wrong is if you update to Tools 20 (so you have the new smaller proguard-android.txt file), and you continue to use ADT 18. Make sure to use ADT 20, since it will add in not just the proguard files specified in your project.properties setting, but the generated proguard file listing the keep files from aapt -G as well. I believe the ant build will also use the -G feature.
(Note - see http://code.google.com/p/android/issues/detail?id=35107 for any followups on this)
Reportedly, there are problems with a recent update of the Eclipse plugin in the ADT, which doesn't properly recompile all source code. In that case, ProGuard will print out warnings about your program classes (as opposed to the library classes). You should check if the export (and the resulting application) works without ProGuard. You should also check if the Ant build works ("ant release"). That could then be a workaround.
I am trying to use progurard with my android applications.
The proguardGui accepts an input, and an output, the input requires a jar file. but the APK file for android doesn't contain any jar?
I tried passing the apk file, and also the dex file inside the apx, but proguard doesn't accept them as an input. proguard only accepts jars, ears, wars, zips so how can i use the proguard gui with my android application?
I detailed complete instructions on how to do it here: http://www.androidengineer.com/2010/07/optimizing-obfuscating-and-shrinking.html
Basically, you have to first set up an Ant build for your Android project, which is relatively painless. Then, you add in the ProGuard Ant target between the Java compilation step and the DEX step. Remember, ProGuard only works on Java bytecode, and Android uses the Dalvik JVM which uses .dex bytecode, so that's why it happens between those two steps.
Actually the Android SDK already integrates ProGuard.
You only need to uncomment the line "proguard.config=....." in the file project.properties (created or updated by Android SDK 17 or higher), in order to enable ProGuard.
Source: ProGuard examples -> a complete Android Application