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..
Related
Is there a way to make changes in jar which doesnot have source code in it and rebuild it with this change as a jar in eclipse.
You can look into using Java decompilers; in order to turn the .class files within the JAR archive back into .java source code. The process and some tools for that are outlined here.
But: understand that *decompiling" can be a tough business! Plus: there is always the question if the licence terms of the library you are using allows you to do that. Being able to do something isn't the same as being allowed to do that!
Finally: keep in mind that a JAR is just a deployment artifact. A lot of libraries are open source, and you can most often download that source and build the corresponding JARs completely on your own.
There are lots of posts about this already but I have not found one that describes my exact situation. Which is:
I have a preexisting build system that generates a C++ shared library in both .dll and .so format (depends on OS).
The build system also produces a set of java files generated by swig.
I also have a pom.xml file that builds the java source into a package.
What I need is a plugin for maven that simply copies the native shared library into the jar. It would be nice if the native shared library was also loadable from within the jar so clients don't have to manually add it to the library path. This seems like a problem that has been solved before.
I have looked at maven-dependency-plugin. Which seems to be able to copy artifacts that are in a maven repository (not my case). Or if you use an assembly it might be possible. However, if it is possible, it seems overly complicated for what I want to accomplish. I would like to accomplish it with only a pom.xml.
I have also looked at nar-maven-plugin, but this seems like it focuses only on building the native library and adding it to a .nar file. This is not what I need since I can already build the C++ library.
Finally, I looked at one-jar which I got to place the native library inside the jar. However, I was not able to import the classes from within that jar, and the clients of this library will expect to be able to do that.
If what I want is possible and I don't need to install the shared library into my local repository please provide a link or an example of how you accomplished it. If it is not possible, please state why.
I am working with Paho project for Android. According to the instructions, while testing Android sample app, it is required to have both AndroidService.jar and JavaClient.jar included in the project. I import them in Android Studio and the app is working perfectly.
However, and that is my problem, I want to edit these precompiled java classes. But the problem is that, since they are imported as .jar files and that they are already compiled, they are uneditable in Android Studio.
I have the source code of the libraries I want to include into the project. Unfortunately, when I import them in the Android Studio, I get bunch of errors (which I do not usually get when I import .jar files).
The methods I tried up until now are to copy the source java classes into the project by creating new classes with same names and content. I also tried to import the whole source project as the module to my project. I get same errors. I also know about this great fork of the Paho project which lets you just to import whole project in Android Studio and it simply works. However, the AndroidService classes are still uneditable.
As I said, I have the needed source code. I can generate these .jar files without any problem from the source and then import them in the project. That method works. But to edit the java classes, then to compile them, then to import them in the Android Studio to test everything, and to do it every time when I change something, is a bit tiring. That is why I am asking for help.
Please, let me know if you know some approach which will let me to edit these two "libraries" while I am still in Android Studio, so I can test changes I make immediately.
P.S. I have been Googling this so much and I believe that there is no ready solution for these online. However, If you find one, I will be really happy if you point to it.
Fist of all I have no idea why you want to edit the Paho Android Service because it doesn't make to much sense. You are able to overwrite every class if necessary. Any way you would need to change the Android Service build from Maven to Gradle to include the source into you project.
To help you out I have just done that and pushed to the "withSouce" branch of my repository. https://github.com/sandro-k/org.eclipse.paho.android.service.sample/tree/withSource
If you now want to replace the compile org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.0.2 with your sources as well you have to replace that with a local dependency as well.
Jar files are really just compressed (zipped) versions of .class files (and a few other essential documents). Class files are compiled .java files. The only way to edit these jar files would be to unzip the jar with a program such as 7zip or WinRAR, then decompile the class to get the source code, edit it, and recompile. Decompiling is a very difficult, time consuming process, and would require external software. Your best bet would be to continue the process you've been using.
Note: If you still wish to decompile, you might want to check out Cavaj, a free java decompiler. But beware, it may not return the exact source code used in the jar.
Sources: Experience
I'm programming in Java, and I usually prefer git when programming in Python. So I want to use it for Java too. I'm using Eclipse, but other people may use Netbeans or IntelliJ IDEA or whatever. How is this usually managed when putting Java code into version control?
I'm making a game which uses the library LWJGL, and that library needs to be added to the project file to be used. Therefore, I still need to check the project file into my project.
Short answer, it doesn't matter at all. Create a file called .gitignore in the root of your project file to ignore your IDE's project files or anything like that, then add your code into the git repository. For example, a good Eclipse .gitignore can be found here.
That way the other collaborators won't see your project files, and if they do the same with their .gitignore for their IDE, you won't see theirs.
I am trying to enhance a library. The library is in the Referenced folder of eclipse. I presume in that folder I can't just edit the code so I guess I have to import the whole .jar file as kind of a project, but how can I do it in eclipse .....
The right way to do it is to find/download the source code for the library. The ugly way to do it is to decompile the library.
After that, edit the source code, and run against your custom version.
You probably need some sort of Java code decompiler to get the source code for that library and then make an eclipse project based on its source. It will be tedious and you will need to setup the dependencies and all that. However you might want to see if the source for that project is already somewhere on internet, eg open source libraries. One better approach could also be extending that library by means of extending classes and that.