android .so files not getting extracted in /data/data/<package>/lib - android

I am developing a native android application and using an open source library with .so file generated. Facing a strange behavior.
For the first few times, the application worked perfectly well, with the library getting loaded. But now its not able to find the library and gives -
java.lang.UnsatisfiedLinkError: Couldn't load : findLibrary
returned null
.Below are few observations: 1. when I extract the .apk file, the library (.so) is present under "lib/armeabi" folder. 2. but when I try to search the library (.so) into the devices extracted path of
/data/data//lib/
, its not present. Any suggestions as to why this strange behavior is happening and why the .so file is not getting extracted under /data/data/com.ibm.homeScreen/lib/ folder.
Thanks in advance!

If you use eclipse, check the buildpath settings:
Right click on your project --> Properties --> JavaBuildPath --> Order and Export (is a Tab) and check there if the librar has been marked (checkbox) to export.
There is also a possibility to set the native library path. You can find that option in the Library Tab --> Android Private Libraries --> EDIT Button on the right
This could also help

For eclipse project, simply put all your *.so files inside armeabi or armeabi-v7a folder, and put the folder inside /libs folder in your project. Compile, the *.so files will automatically be imported into /data/data//lib
For Android studio, the above approach didn't work for me. instead I have to place the armeabi and armeabi-v7a folders into /jniLibs instead of /libs. Note that I am using Gradle 0.10.+ though, not sure if it works on older Gradle.

You can find some further information about this problem here:
Why do some Android phones cause our app to throw an java.lang.UnsatisfiedLinkError?
https://code.google.com/p/android/issues/detail?id=59420
The stackoverflow link also contains some code with a workaround in the (currently) last answer.

Related

How to fix missing jar files issue in android projects

I am using SVN in Eclipse. I opened an android project and it shows errors. It says some jar files are missing. Initially I developed this project in ubuntu and now I am opening this in windows. So those jar files are referring from ubuntu file path. I have attached a screen shot as well.
I am using actionbar sherlock library and though I added it correctly it gives that error.(android support v4) , because it is referring from ubuntu file path. How to fix this errors?
Thanks.
You may take these support libraries from appcompat libs folder and copy those into your project libs folder and then Add To Build Path by right click and going to add to build path. This will do the trick. Similarly you can took the neede jar files and copy those into your project

"Native method not found" in android studio

i have looked through all the other posts here about this subject but none of them helped me.
i am using a third party SDK (oovoo) and it contains a .jar file and .so file (armeabi-v7a)
as stated in allot of places, i put the .jar file in the libs folder and the armeabi-v7a folder (which contains the .so file) in a folder named jniLibs inside src/main
after building, when i unzip the .apk i see a folder named lib and inside it a folder named armeabi-v7a which contains the .so file
yet i still get this exception:
java.lang.UnsatisfiedLinkError: Native method not found: com.oovoo.core.ClientCore.VideoChannelPtr.nCreate:(Ljava/lang/String;)J
why cant it reach the implementation?
if it is in the lib folder in
the .apk does it mean it will for it at runtime?
thanks allot!
android studio version 0.8.6
gradle version 1.12
oovoo version 1.2.4
To answer your questions specifically :
It can't reach the implementation because at runtime, when the java environment tries to load a native method named java_com_oovoo_core_ClientCore_VideoChannelPtr_nCreate with the prototype int (string) it doesn't find such a method loaded. This can be caused by the following :
the .so library isn't loaded by the time you called that method , hence java doesn't know about it (so it's your mistake, you called the functions in wrong order)
the .so library doesn't export such a function, which means you have no chance of fixing this
the .so library loaded at runtime by the phone requires a different architecture besides armv7s. Be sure your device is armv7s.
the folder in which the Android system is looking for native libs is different than you expect. I know this was an old issue, so create in your apk, in your lib folder both "armeabi-v7a" and "armeabi" , and copy that .so file in both
Regarding your 2nd question, yes, if you have the lib inside the apk you will have it at runtime.

Android NDK library: findLibrary returned null

I'm trying to build a medium-size project in Eclipse. It consists of main app project and two Android libraries. Everything worked fine until I added a very simple JNI library to main project.
When I run the app on device I see this exception in LogCat:
01-11 17:19:01.421: E/AndroidRuntime(26569):at
java.lang.Runtime.loadLibrary(Runtime.java:429)
Couldn't load xxx: findLibrary returned null
I googled around for similar problems and I believe that I did everything correctly:
The only .c file and Android.mk file are placed in the 'jni' folder
I build the library with ndk-build tool
The .so library is correctly placed in the 'libs\armeabi' folder
I see that the resulting apk file does indeed contain my native library
When I create a test project and link to the very same native code - it works fine. The problem persists in the main project. I already tried to create Eclipse project from scratch but it didn't help
I use Android SDK Tools v.16
Can anyone please help me with a suggestion?
Thanks!
Ok, after two days fighting the Android SDK I managed to solve my problem. Here's some explanation just in case it may help anybody else.
My previous project structure:
Android Lib1 project (with it's own jni code)
Android Lib2 project (depends on Lib1)
App1 project (depends on Lib2)
App2 project (with it's own jni code; depends on Lib2)
The original problem has been seen when I tried to load jni library in App2. I still don't understand what was preventing the runtime from finding the jni in the App2.
However the solution was to remove the Lib1 project from the workspace and add it as JAR file to Lib2 and both Apps. Now I'm finally able to use load the jni lib in the App2.

How to include jar files in android library project

I am trying to use phonegap inside an android library project. The library project compiles just fine but when i try to start an activity that extends DroidGap, i get this error
01-02 10:12:17.575: W/dalvikvm(316): Unable to resolve superclass of Lcom/***/***.
I think this is because the phonegap.jar file is not included in the compiled jar file of the android library project. I have tried using ant to build but it doesn't seem to work.
Edit: I am building a android library that can be used in other android projects. I am using the standard android library project but activities in this lib project that extended DroidGap class in phonegap.jar are crashing with the above error.
I´m afraid that is not possible yet. The result jar file will contain all classes and resources defined in the android library project, but will not include external jar files added to the build path. You will have to add those to your final Android Projects using that library. You can also find similar questions in SO like this one
create one folder 'lib' in your project. put your .jar file in lib folder. select your .jar file right clicked on ,select buid path --->'add to build'. will add your .jar file. now you can use this .jar file classes.
I would suggest not making the 'lib' folder manually.
Instead:
Right click Project --> Properties --
Select Java Build Path
Make sure Libraries is the tab selected at the top
Click Add External JARs
Then find your JAR...
Basically, the same way you may have added the PhoneGap.jar
The ADT (Android Development Tool Eclipse plug-in) has built-in support for the creation and reference of library projects. See the example in section 5 of this tutorial.
Try changing the name of the folder to libs instead of lib.
have you added required permission in manifest file..
see the below links
http://docs.phonegap.com/en/1.4.0/guide_getting-started_android_index.md.html

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