How to create jar file from Android Library project - java

I have a Android library project need to convert this in to a jar file and use it on my Android project.like we are doing on Adds network integrations,Is there any way to achieve this?.

An Android project can't really fit into a .jar file, unless you just wanna use the compiled java files, which you would certainly have done it via a normal Java library project instead of a Android Library Project in first place.
Android Library Projects are packaged into aar files. Read more about it here: http://tools.android.com/tech-docs/new-build-system/aar-format and it is automatically handled by Gradle builds and late Android Maven scripts...this last one used to use a 'apklib' format which has been deprecated to be replaced by aar format. You can read more about it here: https://code.google.com/p/maven-android-plugin/wiki/ApkLib

I've done this before.
But, due to my requirements, i only needed implementation (no android specific resources). Although you can still include Android actual code (if the project you're going to use it in is also an Android project in which you can load the SDK which includes the classes you're exporting in the jar)
Now the .jar file that is automatically generated in the bin folder, will not allow you to do this because it includes all the Android's project resources (which is not understood in the Jar format). Therefore, you must exclude all except the src folder. Note : Make sure you also exclude the files in the root folder of the project (i.e, AndroidManifest.xml, etc .. )
In Eclipse : Project properties -> Export -> Jar -> (Include only src folder)
If you're project library includes native code ( NDK ), there is a few other workaround that you need to do to get it to work. If this is the case, comment below, i'll help you out.
Cheers

Related

Build *.aar file with NDK Headers

i am using the android ndk with the new gradle-experimental plugin. Now i have my project structure like this:
module with java and c++ code
app with java and c++ code
Both are in one android studio project. Now my app c++ classes have dependencies to the module headers. I want to modify my build.gradle so that the headers i want to export are automatically exported (all headers in a file structure usually).
Can you give me a hint what the best way is to realize this? I will use this a lot so a beautiful solution with a bit more work is prefered.
I am thinking of a way to put headers inside the aar file, so that they are under the "exploded-aar" folder, where i can reimport them from my app.

Connecting AAR with Mobile First application

I Have a AAR file , in Mobile First Project I have to do a call which should open the activity from AAR file . How to do that? I have a Eclipse with MFP 7.0 .
As suggested by Andrew in the comments, there is nothing specifically in the MobileFirst framework that will help you here. You will need to write native code in order to use whatever is inside the AAR file.
Create a Cordova plug-in as described in the following tutorial in order to access the AAR file and use its provided functionality: https://developer.ibm.com/mobilefirstplatform/documentation/getting-started-7-0/adding-native-functionality/android-adding-native-functionality-hybrid-application-apache-cordova-plugin/
However I believe this may also require handling it via Gradle: cordova plugin add external .aar file (not .jar)
Another suggestion that comes up is to extract the .jar file that is inside the AAR file and then that's much easier to handle...

How to use a jar file with shared object in another java project

I have some C files which I wanted to use in my java-android project. Used JNI wrappers and NDK to create SO. I was able to access the C methods from my java code. Everything works fine.
Now I want to create a jar file of this project, for providing it further to other developers(So that the C code can be hidden from others).
This is where I am facing some issues. When I am trying to use the created JAR in some other project I start getting the "UnsatisfiedLink Error" while loading the SO.
The SO is loading perfectly fine in the same project, however when creating the jar with same project and trying to use it in another project, it is causing issues.
*Using Eclipse.
When using eclipse/ant, you need to distribute your .jar and your .so files separately. Other developers will have to reintegrate the .so files themselves inside their lib/ABI folders.
You may find some hacky ways to get .so files integrated using additional jar files containing only the .so files, but that doesn't change the fact that you need to distribute them separately.
To distribute your library with its .so files as a single file, you should build an .aar instead of a .jar. Android Studio/gradle can directly consume these, with .so files integrated directly under the jni/ABI folders of the aar file.

Convert a whole android package to jar file in eclipse

i know we can convert a java class file into a jar file , but i want to know , is there any way to convert a whole Android Package into a jar file or another format , so i can use them in another project ?
and if with any way we can convert it , and the main app has some permissions , are they added to second app or i must add them in second app manifest ?
You can create an Android Archive Library i.e. an AAR file (*.aar) if you make your project a library. As far as I know a JAR file cannot contain all the Android specific components of the project. You can find a very brief JAR/AAR comparison in this discussion.
You can have a look at these tutorials by Vogella and Android By Code for creating such a library and you may find relevant Stackoverflow discussions with the "aar" tag. But as this is a rather new feature and support in Android Studio (or Eclipse ADT) has improved from version to version some of the older discussion might not be up-to-date anymore.
The permissions specified in the library's manifest will apply to the library code even in the app. that is using the library. Commonsware has explained the manifest aspect in more detail.
Firstly, you must go in Eclipse, to File -> Export -> Java (jar file) -> and there you select the package you want to export as a .jar file.
Concerning your second question, you must add the permissions again to the second application.

Exporting android project to jar (that includes other jars)

I've written a Android Game Engine library and would like to export it to a jar file. I've tried to do this with the following:
export > Jar File > Finish
As soon as I add the jar to the build path of another Android project, I get a little box in my code saying:
The type foo cannot be resolved. It is indirectly
referenced from required .class files
I believe this is because my Game Engine library includes other libraries in forms of jars.
How can I add those jar files to my Game Engine jar file?
You can decompile the other jar file using JDui, take what you need, and add it to your library. It all depends on how big is what you need..
Also, check whether you are using proguard in the export. You would have to be careful on how to configure it.
I assuming you are using Eclipse. You also need to use Properties->Java Build Path->Libraries->Add Jar button to add your jar file to the target project

Categories

Resources