Referencing .so files from an Android library - android

I've built OpenSSL into an Android Library that I would like to reference from another Android project.
Unfortunately,
Yes, I do need OpenSSL, as I need to change the behaviour of dependant Android classes not in the public API. (not enough space here)
My experience with native code is non-existant.
The project is selected as a library in Preferences > Android
This library is referenced from a second Android project
My Questions are these
How can I reference the .so files in my Android library from Android.mk in my second project so that I can build dependant files there? I'd prefer not to put the .so files directly in my second project - but if that is the only solution I would accept reasons and directions as an answer.
How should I include/reference the .so file in files I am building in the second project?
Surely, it is something simple.
Thanks in advance.

once you generate (.so) library file, then make a folder in your applitcation's project folder named "libs/armeabi/" put (.so) file in this folder
and in your application write
System.loadLibrary("library_name");

Related

How to make a library containing native code and pure java for android

I have cross compiled the native code for different architectures for android and have its corresponding jni wrapper class working in android studio. Now I want to make it available as a library. I have two questions:
1)Can I just jar the .so file and jni files to make the library?(not .aar because my library contains only the pure java and native code, no android related stuff such as .xml,res,etc) If so what should be its structure?
2) If I cannot create .jar file, then all I am left with is creating the .aar file. That would include the use of android studio. Can I do it without the android studio?
Edit 1:
If I jar the files, then I don't want to extract .so and then use it. If I jar the files, then add it(the .jar) as a dependency in my project then it should automatically put .so into libs/jni folder in my apk so that jni can find it. Question is how do I do that?(if possible)
Fortunately found a way. As .aar is itself a simple zip file with structure as specified here. What I did is "jar" all the .class files (inside proper package folder) into classes.jar, created an empty folder "res", put all .so files in jni folder (with proper architecture) and made a simple AndroidManifest.xml containing basic tags. Then I jar them into file with extension .aar (like mylib.aar). I have tested it by copying .aar into another project's libs folder and putting a dependency on it in app's build.gradle( like compile(name:'mylib',ext:'aar')). And it works great.

Android Library project building jar with resources using ant

Android project referencing to multiple libraries, with resource files.
I want to generate a jar with resource files from the library project and want to use it in
main android project, am not using eclipse, I want this to be done through ant .
Is it possible, because I checked few sites, where they have given to delete the src
and distributing it as zip.
If its possible please give me the process how to go with building through ant.
As far I know this is not possible. Android does not package xml files or drawables in jar files and you cannot access them from another project. You could look at *.aar files, which were introduced last year. But it only works with the Gradle system and Android Studio. It can contain xml and drawable resources from your project.

Don't want to manually copy android JNI(.so) and Jar libraries to App project each time

I'm building and Eclipse to make an Android library I want to distribute to developers.
TedLibJni:
It uses the Android NDK and so it compiles down to a .so file.
TedLibJar:
It also has a Java interface that binds the then extern'd calls in the JNI, so it has a Jar library associated with it.
TedDroidApp:
The concensus is that I need to manually copy both TedLibJni.so and TedLibJar.jar to lib/armeabi of this App for it to be used.
Question: Is there any way that TedDroidApp can pick up the externally located .so or .jar files? It seems crazy that I would have to manually copy and paste these files accross each time I iterate them.
Use an Android library project for the JNI code and the JAR. You can then attach the Android library project to other projects. With the new Gradle-based build system, you can package the library project up as an AAR and obtain it from an artifact repository as well.
CWAC-AndDown, my wrapper around the C hoedown library, works this way.

Is it possible to create jar that includes android functions?

As the topic indicates I would like to create a jar library that uses some android functions (no layouts) and that will be included in an Android project.
Is that possible and how?
From the research I've made I managed to include a simple jar file that uses pure Java (JAVA SE 1.6), but
when I tried creating a jar file I encountered the following exception when I tried to run the Andoid app: FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: mylib.pleasework.amen
I tried including android.jar in my library and removing the java library, so that the jar file is build against android sdk, but it didn't work.
I tried including the jar file under a /libs folder as it is said to be the correct way to import jars in android projects from ADT v17 and after, but that didn't work either.
The jar I want to create will not use any resources (xml layouts, strings.xml) just Log.d and WifiManager.I am aware of Android Library Project but my library source is sensitive and I am afraid that it won't be safe if exposed in a Android library project. I was thinking of creating a jar and using ProGuard ( http://developer.android.com/tools/help/proguard.html ) obfuscate it.
I think I mentioned everything. Any help will be appreciated.
Thanks,
Thomas
As the topic indicates I would like to create a jar library that uses some android functions (no layouts) and that will be included in an Android project. Is that possible and how?
Use the jar command, or the <jar> Ant task. I am sure that there are ways to export a JAR from Eclipse, but I personally have never used them.
For example, in this GitHub repo I have a reusable component and a sub-project that is a sample app. My build.xml for the repo contains the following custom task:
<target name="jar" depends="debug">
<jar
destfile="bin/CWAC-WakefulIntentService.jar"
basedir="bin/classes"
/>
</target>
This generates a JAR file, that other Android applications can use by adding to their libs/ directories.
I am aware of Android Library Project but my library source is sensitive and I am afraid that it won't be safe if exposed in a Android library project.
It won't be safe exposed as a JAR, then, either. You can create an Android library project for public consumption that replaces the src/ tree's contents with a compiled JAR in libs/ in the library.
The way I did it in the end was: to create an Android Library project (check isLibrary checkbox in project properties) export it through Eclipse (right click on the project->export->jar file, careful to deselect all resources - res folder, androidmanifest.xml, *.png etc) and put it in the project you want by importing it under /libs folder. I don't know if this is the best solution but it worked for me.Used ADT r20, Eclipse 3.7.1, Android api level 7

Adding prebuilt library to android apk

I have built a dynamic library in android using android build system. This library provides jni interface for functions inside it. Now I want to include this library in an application (.apk). I am using eclipse for application development. Now, how can I use the prebuild dynamice library (.so) in my application ? I tried putting it in a lib folder in my application but it is not working.
Any pointers are appreciated.
I am not using ndk to build my .so.
Since you write 'so' I think you're using NDK. If you're using NDK I don't know the answer.
If you're using the "Java" SDK, then in your library project go to Properties -> Android, and Check "Is Library". In your "apk" project, go to Properties -> Android -> Add . And your Library project should be available.
Also, any Library added in the "Java Build Path" Menu (again, in project properties) should be available in the APK in the end.
I know it's slightly old, but have you checked in the built APK to see if your .so library is there? Should be in the libs/armeabi folder.
Also, your .so file should be in lib/armeabi folder in your eclipse solution. I'm guessing the armeabi bit depends on which processor your .so file is build for.
Also, I know that if your library isn't called lib[name].so, it won't get copied when the apk is installed on the device. So:
libfoo.so copies
foo.so doesn't copy
foo.so doesn't copy
Also, you can use DDMS (its a view in eclipse) and it's file explorer to see if it's been copied to your device. It should be under data/data/[packagename]/lib.
Hope this helps a bit!
Andy.
I hit this same problem while building Qiqqa for Android. Under your eclipse android project, make sure you have a libs directory (not that it is plural libS not singular lib). Inside that create the armeabi/etc subdirs with their respectibe .so files.
Then when you build, eclipse will automatically pick up this libs directory and create the corresponding lib in your apk. System.loadLibrary("XXX") will then resolve to libXXX.so on your correct architecture...
Cheers,
Jimme

Categories

Resources