Converting android library project to jar file - java

I have a create an android library project which has to be given to a 3rd party application,I have two requirements,
1)convert the library project into a jar file (or),
2)Make the source code in the library project obfuscated.
Basically i dont want to 3rd party application developer to get my source code.
Please help! thanks in advance!

The ProGuard-Application lets you shrink and obfuscate your code. It is from the Android developers, so you can assume it is safe to use it.

This is the closest that you can get:
1: Create a regular Android library project, and get it working.
2: Copy that Android library project into another directory.
3: Create a JAR from the compiled Java classes from the original Android library project, and put that JAR in the libs/ directory of the copy you made in Step #2. You should be able to run ProGuard on this JAR manually, though I haven't tried that.
4: Remove everything inside the src/ directory of the copied library project, leaving behind and empty src/ directory.
5: ZIP up or otherwise distribute the copied Android library project.

This is what you need to do:
Create your library project. Write a test application that tests your library. Build your library project. You could use ant/maven through eclipse. Most libraries now need gradle support because applications are now using Android Studio. Mark your project as a library by going to Project -> Properties -> Android and select the Is Library checkbox. Check this link: http://developer.android.com/tools/projects/projects-eclipse.html.
If you don't want a 3rd party app developer to see your source files, you need to enable proguard. This tool shrinks, obfuscates your code. The application that uses your library has a lot of control over what code needs obfuscation. For example, an application can decide that it wants all packages starting with com.blah.blah* to not be obfuscated by specifying the -keep option in its proguard config file. This will prevent certain sections of code from getting obfuscated. You should allow default obfuscation for libraries unless you decide to use components which don't function with obfuscation (like annotations or reflections).
By enabling proguard, a third party developer will not get access to your source on reverse-engineering your apk. Use wisely!

Related

Create a class library in NetBeans

This it's probably going to be a question with a very easy answer... But I've been googling for a while and I didn't find any.
I'm working on a project that requires some classes to be used in more NetBeans projects (and EJB deployed on Glassfish and a client to call it).
Now, to make it work, I just imported the whole EJB project into the client project as a library, but everytime I launch the client, Netbeans redeploys the whole client and that takes a lot of time.
That's why I'd like to extract just those few interfaces I need from the server project, package them in a .jar and link that to the client.
In Eclipse it was easy enough (right click on your classes, export as jar). Here I can't really find anything of the sort. The only export option I see is used to export the whole project as a .zip.
(Copy pasting the .java files in the client project would also work but a .jar would be cleaner I think)
Not sure I understand the problem.
I use shared classes a lot, and package them into their own project.
Possible process:
Create new project, "Java class library".
Move the required classes to that project.
In your main project, open Properties, Libraries and "Add Project" to link to your library project.

Adding jar files to codenameone in NetBeans

I have an Android POS device that's equipped with a fingerprint scanner. They have a .jar library which is meant to help develop Android apps to access the fingerprint component in the device. I included the jar file in the lib folder of the NetBeans codenameone project and also in the native/android directory.
But when I run the application on the device after building on the build server, the application throws a NoClassDefFoundError. But the class is in the jar file.
You may need to treat it like a native interface, which is actually pretty easy. You just create an interface with all of the method signatures you need, right click on it, and select generate native. Then in the native sub folder there will be an Android directory. You can drop the jar file in there and in the stub file that ends with "impl", you implement the interface methods to call the methods in the jar.
The downside of that is that the auto-code completion won't work. Since you're using Netbeans, if you do the above you should then be able to compile it into a CN1LIB. That can be then placed in your libraries and the code completion will work.
Check the developers guide in the Advanced Topics Under The Hood section, and there's a tutorial video also.

Java Eclipse: Read the code of a class imported from a library

I'm working in a project environment Eclipse Luna Service Release 2 (4.4.2) in which I am using classes imported from some libraries. Currently I have to build a class diagram of the work done so far and to do that, I'm using the "ObjectAid Explorer Eclipse UML plugin" without problems. Unfortunately I can not create it anyway integrating relationships to classes imported and then I was planning to re-create them in a package so that you can create this class diagram. How can I read the code of a class imported from a jar library?
Thanks so much !
If you want to read just the method signatures, inside Eclipse from Project Explorer, navigate where the .jar is located and expand it; you will be able to view the classes and their methods.
If however you want to read the entire code of every class, you need the .jar that attaches the sources on it. Developers usually package a Java Project without the sources files and create separate JARs that contain them. Look for the a JAR named <library_name>-src.jar.

How to edit library source files on NetBeans?

I am doing JAVA project based on the SSJ (Stochastic Simulation in Java) libraries. In my project I have followed the required steps to import the SSJ library files and also the source files.
When looking at the SSJ library files in the project's Libraries branch, only class files appear shown, but when I open them I can view the source code (which I couldn't before, as I hadn't imported the sources) so I assume everything was imported correctly.
When I run the examples provided with the library everything runs fine and as expected. But if I try to change the source code for the libraries for instance, changing the text on an output, the changes I make to the source files aren't reflected in the output from the java programs.
Any hint on what I might be doing wrong?
I understand this might be hard to understand or test as I can't quite create and SSCCE for this matter. The library files are hosted here (http://www.iro.umontreal.ca/~simardr/ssj/ssj-20120216.zip) and the source code here (http://www.iro.umontreal.ca/~simardr/ssj/ssj-source.html).
Thanks in advance for all your help!
Adding source to libraries it's for debugging and documentation purposes. It does not mean that Netbeans will detect changes and recompile classes automatically.
You should create a project for the library itself to recreate it from source. Changes are that if you have the source there will be a build.xmlor a pom.xml that contains the steps to compile the library and will allow to create a Java Free Form Project or a Project with existing POM.
You'd then remove the reference to library itself and add a dependency to the project.
Other option would be to add the library source to the same project you are using (and, again, removing reference to the library) but I would not recommend this unless it's a very small simple library.
EDIT. Particular ssj information.
ssj is a library where the original source code is in .tex files and it requires several programs available to generate .java files and then compile them. All this information can be found in the COMPILE.txt original file.
Since the source distribution includes .java files it is possible to generate a .jar just using Netbeans but it requires to modify the build.xml to just compile Java source files. Also when creating the Java Free Form Project is necessary to select lib as the target to Build Project.
Here it's a minimal build xml for Netbeans 7.1 to compile from Java sources.
In order to create the new *.java file from the *.tex file, you need the tcode.jar which is available in the distribution. Have you added tcode.jar as an external jar to your project?
umontreal.iro.lecuyer.tcode.Texjava is in tcode.jar

Linking to generated Java protobuf code in Eclipse

Here's the workflow that I'm trying to build
compile my proto files using a script, putting the generated src in a specified directory
link to the generated classes in Eclipse
compile my project
I am easily able to do this for C++ using Eclipse CDT: In my project I choose File->New->Other and choose File under General. Then I click on Advanced and select link to system file.
I haven't discovered how to do this for Java, though. Once answer here suggests creating another project with the generated code and make that a dependency to my project. This works but seems redundant.
Is there a way to directly link the generated protobuf Java classes to my project?
Well Java doesn't really have a "link" phase. Your two options are really:
Build the generated code outside Eclipse, and then add a reference to the relevant directory or jar file
Include the generated code within Eclipse (e.g. by having a source path which includes the directory containing your generated code) and get Eclipse to build it along with the rest of your code.
I suspect that the first option will make it easier to keep the generated code well away from your real source, but the second option may make it easier to browse the generated source, and package everything up.

Categories