Create Android Library project jar - android

I have a project that is an Android Library. It uses two external jars (universal image loader and ksoap).
I need to create a jar from this project to distribute it, but when I do this and use this project, I always get a java.lang.NoClassDefFoundError, saying that the ksoap classes are not found.
When I open the jar file, I see the both jars included, but it seems that the final project does not see them.
How can I do this?
Thanks!

Create a regular Java library and do the following steps:
Add "android.jar" as a library in your project
How to locate it?
android.jar is located in Android SDK
<Android SDK path> / platforms / android-XX / android.jar (XX = API number)
It's simple to do, and it not requires to include "android.jar" in your JAR file, because "android.jar" is already included by default in Eclipse ADT / Android Studio.
NOTE:
For Android Studio, add the library uniquely in this way:
Add this on your build.gradle.
dependencies {
compile files('libs/your-jar-library.jar')
}
For include these two external jars, you need to do following steps:
Unzip both JARS
Unzip your JAR file
Copy the files of the unzipped libraries to your unzipped JAR (Only package folders)
Zip your JAR file with the external libraries included, you don't need to put a JAR inside JAR.

Related

Using features of an android library

I have downloaded a library to use in my android application and I added it to my eclipse workspace as a project. After I marked it as a library in the project's properties, I added the library to my app project, but still, I can't access the features of the libraries. Is there something to do before you can start using a library after adding it to a project?
is it a jar? Can you see .jar in lib folder ? you can try this:
your prokects- properties - java build path - Add External JARs - select the jar - (keep it in lib folder)

AAR in Eclipse ANT project

is there any way to use .aar library (with resources) in eclipse ant project? I know that there is no simply way to use .aar format like in gradle, but maybe there is some workaround to unzip it and import it manually?
This solution was helpful for me
EDIT: A .aar file is simply a zip file with the following contents:
AndroidManifest.xml (Required file)
classes.jar (required file)
Res / (compulsory folder)
R.txt (Required file)
Assets / (Optional folder)
libs/*.jar (folder option)
jni//*.so (optional folder)
proguard.txt (optional file)
lint.jar (optional file)
You see, within the .aar file you have everything you need to operate the library in eclipse.
to create library:
CREATE a new project (hereafter library project ) to your workspace. Do not forget to mark it as a library.
Leave empty src folder library project .
.aar Decompresses the file. You can rename it to .zip and unzip or
use any tools.
Copy the file classes.jar into the libs file folder library project .
Res folder replaces the library project with .aar res file folder.
You've created the project that contains almost everything you need.
Now let's see how to configure your project to reference the library project.
In the project you want to use the library (henceforth, project goal ) added as the dependency library project .
Open AndroidManifest.xml .aar within the file and make sure to copy
everything it takes (permits, activities, services, receivers ...)
in the file AndroidManifest.xml project objective .
If there is, copy the entire contents of the folder assets .aar file in the assets folder target project .
If there is, copy the entire contents of the file .aar libs folder
in folder libs target project .
Make a Clean the workspace and recompiled.
http://www.iphonedroid.com/blog/utilizar-ficheros-aar-en-eclipse/#.Vh3krye1Gko
Indeed, aar files are just archive files. So you can unzip it and find jar files along with ressources files. The question have already been partially answered here:
https://stackoverflow.com/a/21485222/1836870
If you want to get the ressources inside your jar, you could try repackage like it's suggested in this answer:
https://stackoverflow.com/a/21417599/1836870
The brunt of the work can be done by a wonderful script called deaar. The gist explains things, but basically you run:
ruby deaar.rb [path/to/aar] [output_directory]
It outputs an almost ready to use library. Next, you need to run:
cd [output_directory]
android update lib-project -p . -t android-xx
Replace xx with the Android version you're targeting. Now put that directory where your build.xml and project.properties are. Finally, add a line like this to your project.properties:
android.library.reference.1=./output_directory
Replace the directory name with the one you created. You can use ".2" and so on for additional libraries. And that's it!
Twitter Fabric(Crashlytics) has a kits-libs plugin for dependencies management http://docs.fabric.io/android/fabric/eclipse.html.
And there's another gradle plugin project https://github.com/ksoichiro/gradle-eclipse-aar-plugin.

How to put an external library project to my one?

I want to use a svg-android library to work with *.svg files in Android. For the same, I've installed the apache ant, created a folder in workspace called: SVGAndroid and then added
android.library.reference.1=C:\Android\workspace\SVGAndroid
to project.properties file.
There were no documentation for functions in ReadMe, so I'm wondering if the installation correct or not, how to reinstall an external lib in the second case and where are the examples of using svg-android?
For your including of the project, just include the project into your workspace and in your respective application under the properties of that project just add a dependency on a library that references svgandroid. Make SURE to include the files and ensure that the compile class files are present in the final output of the apk. This typically means that you add the project to your build path/order.
Another approach is to just take the entire project and compile it into a jar file and then include that jar in your libs folder and add that dependency on the jar file of that respective project to your core application.
Useful links
How can I use external JARs in an Android project?
I would rather suggest to not add the path to the project manually, but from Project Properties -> Android and you will have a list with all the library projects in the workspace from which you can choose the desired project.
Also I suggest adding in project.properties the following line:
manifestmerger.enabled=true
in order to have all the AndroidManifest.xml files of the referenced library projects merged into the main project's manifest.
If you want to include a library file in to your project follow the below steps;
Download a jar file and save it in any folder.
open your project.
Right click--> Build path--> Add External Archives---> Add your external jar file to your project

Can't use a Jar file in Android Project

I'm trying to use an external jar file in my Android project, I follwed this step for including it:
I put the jar file in libs.
I configured the build path and now I can see the jar file in the Referenced Libraries section of the project.
I use the import to bring the class that I need inside the program.
But I always get NoClassDefFoundError. This jar already works with a classic java program.
Make sure that the jar is being built with the app. In eclipse,
right click on project --> build path --> configure build path.
Make sure the library is checked in the Order and Export tab.
Since Android SDK 17 there is not even necessary to manually add the jar files to buildpath, because they are added automatically, as stated here. Then I would suggest to:
remove the library from buildpath
clean the project
make sure the jar file is located in a folder called libs (not lib) located in the root folder of your project
refresh the project
run the project
The solution found was recompile the library with the version 6 of java and using the jar fail obtained

Android add jar to custom library

I have made an android project in eclipse. This project has a library project:
the library project (marked with "is library") has included a jar file.
this library project does a lot of stuff with the use of the jar file.
in code everything is fine.
The problem is that the reference to the jar file doesn't exist anymore when it is compiled and installed to my phone.
When i add the jarfile also to my base project. Then the program works.
However, i don't believe that this is the right solution.
So what does i do wrong?
You should add a libs folder to your project
Then, add the jar to the folder and right click on the .jar file and go to Build Path, and select Add To Path or Build To Path. This way the library will be a part of your project. This should help.
The library jar you used in your Android Library Project must be manually added to the dependent application project's build path, not the Android library project build path itself, check out API here

Categories

Resources