Reading the docs on proguard . . .
android docs
I'm supposed to have a ProGuard.cfg as it says...
"When you create an Android project, a proguard.cfg file is automatically generated in the root directory of the project. "
If I google the issue there are answers all over the place most of them saying to modify a file that starts with a warning not to modify the file.
Are the docs out of date? How to I get this enabled for release builds?
thanks, Gary
If you're using ADT 17 or newer, the documentation is slightly inaccurate. The generated file is proguard-project.txt and will be in the root directory of your project.
To enable Proguard, you will need to ignore the "do not modify" warning in project.properties and uncomment the following line:
proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
The Android toolchain will sometimes make changes to project.properties, but your Proguard path will be preserved.
In my case, the entire Proguard folder was missing at the location specified in the error. Make sure that the folder is present.
Related
I want to minimize the size of .apk file, so I follow the Android Developer guide (http://developer.android.com/tools/help/proguard.html), but there are some problems I encountered as follows:
I create a new project via Android Studio, but it doesn't generate a proguard.cfg file. And there exists a local. Properties file rather than project. Properties file.
How can I figure out this issue?
In the new version of the ADT, the file generated is not proguard.cfg but proguard-project.txt. Proguard must be activated in the file project.properties.
You can check this link: http://tools.android.com/recent/proguardimprovements
Reading the docs on proguard . . .
android docs
I'm supposed to have a ProGuard.cfg as it says...
"When you create an Android project, a proguard.cfg file is automatically generated in the root directory of the project. "
If I google the issue there are answers all over the place most of them saying to modify a file that starts with a warning not to modify the file.
Are the docs out of date? How to I get this enabled for release builds?
thanks, Gary
If you're using ADT 17 or newer, the documentation is slightly inaccurate. The generated file is proguard-project.txt and will be in the root directory of your project.
To enable Proguard, you will need to ignore the "do not modify" warning in project.properties and uncomment the following line:
proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
The Android toolchain will sometimes make changes to project.properties, but your Proguard path will be preserved.
In my case, the entire Proguard folder was missing at the location specified in the error. Make sure that the folder is present.
I was asked to crate a simple app for android. The first one in fact that I'll be paid for, so I really don't want to screw it up :). One of the requirements was that the code must be obfuscated.
I learned the general idea of obfuscating, but I don't want to make any silly mistakes.
What precisely do I have to do to make the code obfuscated? Does exporting it as release do the job, or some other steps are required? Any remarks are also appreciated.
PS. I'm using Eclipse if it matters.
EDIT
From the article suggested in the anwsers:
To enable ProGuard so that it runs as part of an Ant or Eclipse build,
set the proguard.config property in the
/project.properties file. The path can be an absolute
path or a path relative to the project's root.
If you left the proguard.cfg file in its default location (the
project's root directory), you can specify its location like this:
proguard.config=proguard.cfg
I indeed have the project.properties file in my project's dir. But I don't have the proguard.cfg file. Instead I have the proguard-project.txt file. I guess it's a replacement.
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-7
Originally everything but the last line is commented out.
In proguard-project.txt everything is commented out.
I guess I'm lost here, so I'd be very thankful If somebody could tell me step by step what I am supposed to do and also how to check if it actually works.
The article on the official dev site is out of date. Starting with SDK Tools r17 they changed the way the ProGuard configuration works. Basically they split what used to be proguard.cfg into two files (and also simply made them .txt files): proguard-android.txt and proguard-project.txt. proguard-android.txt resides in your {SDK dir}\tools\proguard directory and proguard-project.txt is in each of your project directories.
They split the file so that general configuration/flags that the Android team deems pretty standard will be in the proguard-android.txt file and can be updated (basically silently) with each SDK Tools revision. And then any developer/project specific flags, the developer can add to the proguard-project.txt file.
This is why you noticed everything in your proguard-project.txt file was commented out, because in general most people don't have any project specific needs, they just want to run ProGuard with standard settings and be done with it.
For reference (a very good explanation): http://tools.android.com/recent/proguardimprovements
Step-by-Step (day by day :P)
(Using Eclipse IDE) To enable ProGuard and it's shrinking and obfuscation using only the default settings:
First update your SDK Tools to newest (r19 at time of writing)
In project.properties uncomment the line that says:
proguard.config=${sdk.dir}\tools\proguard\proguard-android.txt:proguard-project.txt
If you created the project before r17 then you might not see the same things. If that's the case I suggest you create a new dummy project (after updating SDK Tools) and just copy over the proguard-project.txt and project.properties files.
That's it! ProGuard will now be enabled and it will run, but only on release builds (when you use Android Tools and export a signed/unsigned apk).
When you make a release build you'll notice that a new ProGuard folder will be created in your project folder. Within this folder you find four files with stuff like what classes/methods were kept or removed. Also note that when you obfuscate, you'll also obfuscate your stacktraces in the event of errors.
Edit: (9/4/12) Just wanted to update this answer to reflect changes in Tools r20.
The Android team has now added one additional proguard configuration file. It is proguard-android-optimize.txt and it also resides in the {SDK dir}\tools\proguard directory. This file is the same as the original proguard-android.txt config file, except it has proguard optimization turned on.
This additional file was added for convenience for those who wanted to turn on optimizations (maybe so they can do stuff like strip out Log calls, which requires optimizations be turned on). Now you can simply point to this file instead in your project.properties file like so:
proguard.config=${sdk.dir}\tools\proguard\proguard-android-optimize.txt:proguard-project.txt
As before, don't try to alter any of the proguard-android... config files. Any project specific flags should go in the proguard-project.txt file in your project folder.
I stumbled across something I can't figure out myself.
I have an android project with a reference to a library project. Now, the weird thing is that it seems like my default.properties file is no longer needed. Android creates a project.properties file. So my questions is: what is the difference between the two? Isn't a project.properties file standard java and default.properties android specific? What do they do exactly?
I believe you've got an issue where (some of) your project files have become obsolete after an update to a newer Android SDK.
Run this command in your project directory (you'll need to have ${ANDROID_HOME}/tools in your path):
android update project -p .
It will output something similar to (As of SDK 15):
Updated and renamed default.properties to project.properties
Updated local.properties
No project name specified, using Activity name 'MainActivity'. If you wish to change it, edit the first line of build.xml.
Added file ./build.xml
Updated file ./proguard.cfg
My guess is that the Android team decided to become more standardized and to do away with their own deviations from standards.
I am using Eclipse to build my Android Application. When I export the project as an Android Application I can use my keystore and key to sign the apk just fine. Before exporting I also added the Proguard config location to the properties file, I also changed my Android SDK file path to one without spaces, and I have debuggable set to false in my manifest.
With all of those done, the proguard folder in my project that is created does not contain any files and the Android documentation claims it will contain several.
http://developer.android.com/guide/developing/tools/proguard.html
What have I missed?
Stupid error on my part. It looked like it was succeeding because it was. Its just the proguard files weren't imported into eclipse so they didn't show up in package explorer. Manually entering workspace I found them.
That is indeed a little embarrassing. Oh well.