How can I go about creating an obfuscate jar file? As of now I can easily export my Android lib project to a jar and use it. How do I obfuscate the jar file?
My end goal is to allow others to use my lib.jar in their projects. I just want to protect the code as much as I can... :)
you to enable proguard for your project - its very easy. http://developer.android.com/guide/developing/tools/proguard.html
one common error that can occur is that methods aren't found when using reflection. This is because the obfuscation removes method names and sometimes even whole classes. If you have custom views the same thing can happen.
You configure what classes to keep by using the "-keep" flag in proguard.cfg
here are some common ones this is from a maven build - but the concept is the same
quite a big area, but hope it helps ...
figuring this out was not easy, but once done, repeating the steps is not that hard:
proguard.cfg example
…
that's it. the output will contain your obfuscated .jar file.
from that point, i copy over a few items from my project (.project file minus external tools builder for NDK; res folder, libs folder for my jni code, and project.properties and AndroidManifest.xml) into MyReleaseSDK, then create a .zip out of it. that .zip can then be used by someone else as an Eclipse "import" project; it will create an empty src folder, gen the resources properly, and anyone who wants to can now use it as a regular Android library project despite it being obfuscated.
To create an obfuscated jar file you can do that by adding build.xml file to it and making changes in your proguard-project.txt file and running ant release from command line and you will find the obfuscated.jar under a proguard folder in your bin folder of project
Steps
To add build.xml in your project in linux:
open a terminal and go to android/tools/ant folder and run
and you will find build.xml in your project root directory.
to enable obfuscation in your project:
In your editor open a project.properties file and remove comment from
add your changes to proguard-project.txt file and in terminal go to your project and run
If it is an external jar, then if you have it in "libs" folder and compile with say Android 2.2+ SDK, it automatically uses proguard to obfuscate the apk. If you want this jar as a library and also obfuscate it before using it in your apk, then it may not be possible. If you are talking of apk obfuscation than Android does this from 2.2 on I think (with proguard), and you dont have to worry about it.
Turns out it is possible and it's not that hard. After 3hrs of trying I finally figured it out!
Android provides a convenient proguard GUI under:
Using the GUI you just select the in.jar and the out.jar. Than you must select the android.jar and remove the selected default rt.jar.
Once that's done you must carefully select the Shrinking and Obfuscation options.
I hope in some way or another this helps!