We are making an application that needs to convert one file format to another.
I am not sure whether we can add a JAR file in which we develop the code to convert the file format to our required file format, to our android project.
You should be able to create a folder called libs in your main project directory and add any jar that you want to use to this folder. If during testing on the emulator you get a class not found exception or something like that you may add the jar in the order and export tab of your build path configuration.
Related
I have one android myLibrary.jar file. But myLibrary.jar file will load the native 3 different so file. I have a.so, b.so and c.so.
When i using in my own application, it just simply put the jar file to the Android Dependencies and all 3 so files put in the libs/armeabi of the main application package.
When deploy and install on the device, these so file will be in the data/data/my-appname/lib/*.so.
Now i need to provide the sdk solution. The user side doesn't want the main application. They just want the myLibrary.jar. So i am considering about packing all 3 *.so files to the jar. I searched for the how to add to the so files to myLibrary.jar. But i still don't understand.
In this following post:
[Ant]How to add .so file into a jar and use it within jar(set the java.library.path)?
It mentioned about adding the so file to the jar and extract at runtime. But i still don't understand how to achieve that.
After trying that mentioned in the following post:
Creating a product SDK: How do I add a native lib (.so) and a jar with the SDK I am creating?
After my sample application reference the the compiled jar that included the .so file. After installing to the device, the libs/armeabi/xxx is not unpacked on the install. So i would like to know how to extract them dynamically and save them to data/data/my-appname/lib/ so that i can use with System.loadlibary(.so).
Thanks a lot.
How to load a jar file from assets folder of android application during run time. Loading from assets folder is my requirement. Is there any way to do this. Please help ..
I got the answer.I am adding this answer here. Because this may be helpful to some others searching.
There are steps to accomplish this.
You have to make a copy of your JAR file into the private internal storage of your aplication.
Using the dx tool inside the android folder, you have to generate a classes.dex file associated with the JAR file. The dx tool will be at the location /android-sdks/build-tools/19.0.1 (this file is needed by the Dalvik VM, simply jar can not be read by the dalvik VM))
Using the aapt tool command which is also inside the same location, you have to add the classes.dex to the JAR file.
This JAR file could be loaded dynamically using DexClassLoader.
If you are making a JAR from any one your own library, you have to do this steps (1-4) every time when there is a change in your library source code. So you can automate this steps by creating a shell script(in Mac/Linux/Ubuntu) or batch scripts(in Windows). You can refere this link to understand how to write shell scripts.
Note : One situation for implementing this method is, when it is impossible to add the JAR files directly to the build path of core project and need to be loaded dynamically at run time. In normal cases the JAR files could be added to the build path.
please check this link for the detailed code and implementation.
How to load a jar file at runtime
Android: How to dynamically load classes from a JAR file?
I have read lots of questions on this site and come to the decision that if you wish to use your already developed code with its resources in android then you have to use it as a library.
But from the Building Android applications with Gradle tutorial I read something like...
Gradle supports a format called Android ARchive (AAR) . An AAR is similar to a JAR file, but it can contain resources as well as compiled bytecode. This allows that an AAR file is included similar to a JAR file**.
Does it means that we can use .aar file as an .jar file but with facility of using resources also?
Then I have tried to crate .aar file with the help of Android Studio, but .aar file doesn't contain layout XMLs or images -- it contains some layout and resources but it doesn't contain projects other resources file.
At last I am having the only same, annoying, stupid question: Can we use whole project with its resources with only one file like .jar or .aar or any other file format?
RajaReddy is quite mistaken. The JAR contains only code; you cannot access resources that way.
Google distributes their own "Google Play Services Library" as an Android library project, containing the binary code in a JAR file in the lib directory, the resources in the res directory, and an UnusedStub class in the src directory. If a better approach were viable yet I think they'd be using it.
UPDATE: While Android Studio is still in beta, it includes (buggy) support for AAR files. Seems this will eventually be the way to go.
Library projects bin folder contains jar file, copy that jar file in your main Application ( project ) libs folder we can get all the resource folders like this.
Follow these steps !
1) make your library project a normal project by deselecting IsLibrary flag.
2) Execute your project as Android Application. (It will not show any error)
3) you'll find a .jar file in bin folder..
4) Copy .jar in libs folder of your main application.
this will works fine with all the resources.
I was looking for the same thing for years. Combining byte code of java and resources (xml and other files) into one package. Currently I don't think its possible because even google has to include add resources separately in google play services lib available in the SDK .
What you can do best is generate a .aar or .jar file and add a folder of missing resource files.
I need Simple xml parser for my project. I read throu it's site but i couldnt find how should i add it to my project to use it properly.
I programming in android using eclipse.
This is the site of Simple.
You have to do the following:
Download jar or zip of the Simple parser here
Copy it into the directory where the libraries of your project is located.
Let Eclipse knowing it by adding the library into the classpath
In order for the jar to be available at runtime, you need to:
Put the jar under your assets folder
Include this copy of the jar in your build path
Go to the export tab on the same popup window
Check the box against the newly added jar
last part is from here
I am trying to add SQLCipher to my project. I am able to link the jar files to the project but there is problem linking the .so files provided.
Due to that I am getting UnSatisfiedLinkError when i try to open the DB.
Can anyone please let me know the best possible way to add .so files to the project and get it running.
In addition to jar files you need to include .so files. In my project I have:
jar files in project_root/libs/
.so files in project_root/libs/armeabi/
Also make sure that you have added the .jar files properly. Go to Project Properties -> Java Build Path -> Libraries tab make sure commonc-codec.jar, gueva-r09.jar, sqlcipher.jar are added there.
EDIT
1) Add a single sqlcipher.jar and a few .so’s to the application libs directory
2) Update the import path from android.database.sqlite.* to info.guardianproject.database.sqlite.* in any source files that reference it. The original android.database.Cursor can still be used unchanged.
3) Init the database in onCreate() and pass a variable argument to the open database method with a password*:
SQLiteDatabase.loadLibs(this); //first init the db libraries with the context
SQLiteOpenHelper.getWritableDatabase(“thisismysecret”):
Can you use the adb shell command to verify what files are being deployed to your simulator after it has been unpacked. I have seen an issue where the .so files are not packaged up in the .apk file before, which is due to the IDE not pointing to the correct native library path for your application.