I have a question regarding how to obfuscate an Android library project. Overall, I’d like to obfuscate an apklib file (or really the .java files for any library project) that contains both .java files (in the Android src/ directory) and XML files / external resources (in the Android res/ directory). I’d like to be able to distribute this library to other developers, similarly to the Facebook SDK library (https://github.com/facebook/facebook-android-sdk for reference). However, I want the code to be obfuscated so that my methods aren’t exposed in an easy to read manner.
I’ve tried using Proguard with Maven, but even after building my project with Proguard the files in my .apklib were not obfuscated. I also tried running Proguard manually, but I wasn’t able to have it output raw .java files (that could be referenced by another project as a library) instead of .class files.
If anybody has any information on how to obfuscate the java code in an apklib / Android library, I’d be very grateful. Additionally, it would also be very helpful to know if it isn’t possible to create an obfuscated andoroid library at all.
Thanks very much for your help.
Best,
Kevin
Depending on how you set up the proguard goal of the android maven plugin you can most likely create an apklib that is obfuscated. I have however not tried myself. Keep in mind that proguard obfuscates into a secondary artifact potentially and not into the primary apklib.
You should also keep in mind that if you obfuscate the library your users will have to use the obfuscated method names… which sort of defeats the purposed of the distribution and will make it very hard to use so it might be a bad idea. The only thing this would work is if you obfuscate all the code without obfuscating any public method and class names..