Can't use libspotify 12 in android app - android

I'm trying to load libspotify in my android app using NDK.
I'm using the library libspotify++ and jlibspotify. everything seems to be loaded but it crashes when libspotify is trying to load the library "libspotify.so.12"
I cannot use symbolic links in android.
Code:
public class Session {
static {
System.loadLibrary("spotify");
System.loadLibrary("jlibspotify");
}
}
Log:
05-29 17:27:22.559: D/dalvikvm(32606): threadid=1: still suspended after undo (sc=1 dc=1)
05-29 17:27:25.527: D/dalvikvm(32606): Trying to load lib /data/data/se.warting.spotify/lib/libspotify.so 0x41692100
05-29 17:27:25.535: D/dalvikvm(32606): Added shared lib /data/data/se.warting.spotify/lib/libspotify.so 0x41692100
05-29 17:27:25.535: D/dalvikvm(32606): No JNI_OnLoad found in /data/data/se.warting.spotify/lib/libspotify.so 0x41692100, skipping init
05-29 17:27:25.543: D/dalvikvm(32606): Trying to load lib /data/data/se.warting.spotify/lib/libjlibspotify.so 0x41692100
05-29 17:27:27.637: W/dalvikvm(32606): Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lse/sony/tunefeud/spotiwrap/Session;
05-29 17:27:28.824: D/AndroidRuntime(32606): Shutting down VM
05-29 17:27:28.824: W/dalvikvm(32606): threadid=1: thread exiting with uncaught exception (group=0x40a421f8)
05-29 17:27:28.855: E/AndroidRuntime(32606): FATAL EXCEPTION: main
05-29 17:27:28.855: E/AndroidRuntime(32606): java.lang.ExceptionInInitializerError
05-29 17:27:28.855: E/AndroidRuntime(32606): at se.warting.spotify.PocActivity.onCreate(PocActivity.java:18)
05-29 17:27:28.855: E/AndroidRuntime(32606): at android.app.Activity.performCreate(Activity.java:4465)
05-29 17:27:28.855: E/AndroidRuntime(32606): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
05-29 17:27:28.855: E/AndroidRuntime(32606): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
05-29 17:27:28.855: E/AndroidRuntime(32606): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
05-29 17:27:28.855: E/AndroidRuntime(32606): at android.app.ActivityThread.access$600(ActivityThread.java:123)
05-29 17:27:28.855: E/AndroidRuntime(32606): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
05-29 17:27:28.855: E/AndroidRuntime(32606): at android.os.Handler.dispatchMessage(Handler.java:99)
05-29 17:27:28.855: E/AndroidRuntime(32606): at android.os.Looper.loop(Looper.java:137)
05-29 17:27:28.855: E/AndroidRuntime(32606): at android.app.ActivityThread.main(ActivityThread.java:4424)
05-29 17:27:28.855: E/AndroidRuntime(32606): at java.lang.reflect.Method.invokeNative(Native Method)
05-29 17:27:28.855: E/AndroidRuntime(32606): at java.lang.reflect.Method.invoke(Method.java:511)
05-29 17:27:28.855: E/AndroidRuntime(32606): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-29 17:27:28.855: E/AndroidRuntime(32606): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-29 17:27:28.855: E/AndroidRuntime(32606): at dalvik.system.NativeStart.main(Native Method)
05-29 17:27:28.855: E/AndroidRuntime(32606): Caused by: java.lang.UnsatisfiedLinkError: Cannot load library: link_image[1936]: 118 could not load needed library 'libspotify.so.12' for 'libjlibspotify.so' (load_library[1091]: Library 'libspotify.so.12' not found)
05-29 17:27:28.855: E/AndroidRuntime(32606): at java.lang.Runtime.loadLibrary(Runtime.java:370)
05-29 17:27:28.855: E/AndroidRuntime(32606): at java.lang.System.loadLibrary(System.java:535)
05-29 17:27:28.855: E/AndroidRuntime(32606): at se.warting.spotify.spotiwrap.Session.<clinit>(Session.java:6)
05-29 17:27:28.855: E/AndroidRuntime(32606): ... 15 more
This is what i get from objdump:
$arm-linux-androideabi-objdump -p libs/armeabi/libjlibspotify.so | grep NEEDED
NEEDED libspotify.so.12
NEEDED libstdc++.so
NEEDED libm.so
NEEDED libc.so
NEEDED libdl.so
$arm-linux-androideabi-objdump -p libs/armeabi/libspotify.so | grep NEEDED
NEEDED libm.so
NEEDED libc.so
NEEDED libdl.so
Does anyone know what do do to get it work?

I'll just break out my Java/JVM skills here and try applying them on Android/Dalvik.
System.loadLibrary() expects a JNI library name as its argument. In this case libspotify is not (and never is) a JNI library, but libjlibspotify seems to be. Note how the first call whines in the log about the missing JNI_OnLoad function. This is usually a good hint. System.loadLibrary() does however accept any shared library as long as it can find it, and that's why the call doesn't fail in this scenario.
Dependent libraries of a JNI library are loaded automatically by the platform's built-in shared library loading mechanisms. In this case, libjlibspotify depends on libspotify.so.12, so if there is such a file available in the loader's path, then this should be loaded automatically by the system whenever libjlibspotify is loaded.
Hence, the proper Java code in this case should be:
public class Session {
static {
System.loadLibrary("jlibspotify");
}
}
However, if the dependent library is not found as part of the System.loadLibrary() invocation, then that call will fail with an UnsatisfiedLinkError (see the log about the missing dependent libspotify.so.12 file).
libspotify 12 currently ships in the archive as libspotify.so.12.1.45 (with some symlinks libspotify.so and libspotify.so.12 pointing to that file). I don't know anything about how libjlibspotify has been built in this scenario, but if it is the case that the symlinks aren't relevant in the Android setting, then libjlibspotify should instead be built to load libspotify.so.12.1.45 from the archive, no renaming needed.

It seems you need to change build process of how you are creating the libspotify to have proper name.
Easiest way would be to use Android NDK build system - it will correctly compile and link the libraries.

The answer from Mārtiņš is correct, it should be build with Android's NDK build system.
When don't having controle over the library there is a workaround:
Instead of loading the library with System.loadLibrary( "JLibSpotify" );
i manualy copied /data/data/se.warting.spotify/lib/libspotify.so to /data/data/se.warting.spotify/libspotify.so.12
And then loaded the library with:
System.load("/data/data/se.warting.spotify/libspotify.so.12");
After that i could load jlibspotify as normal:
System.loadLibrary("jlibspotify");

Related

Current AndroidStudio sample fails on phone due to runtime native library link error. Why?

Its on an HTC Aria, running 2.2 (API 8)
https://en.wikipedia.org/wiki/HTC_Aria
The aria is an armv6 device that supports opengles 2
If you open up the latest Android Studio (im working on windows 7), then import the HelloGL2 sample, then simply try to run it on the above device, it will fail as soon as it tries to make a call into the native library.
Here is the log:
01-06 11:14:08.467 12771-12813/com.android.gl2jni D/dalvikvm: Trying to load lib /data/data/com.android.gl2jni/lib/libgl2jni.so 0x44c165d0
01-06 11:14:08.467 12771-12813/com.android.gl2jni I/dalvikvm: Unable to dlopen(/data/data/com.android.gl2jni/lib/libgl2jni.so): Cannot load library: link_image[1995]: failed to link libgl2jni.so
01-06 11:14:08.477 12771-12813/com.android.gl2jni W/dalvikvm: Exception Ljava/lang/UnsatisfiedLinkError; thrown during Lcom/android/gl2jni/GL2JNILib;.<clinit>
01-06 11:14:08.497 12771-12813/com.android.gl2jni W/dalvikvm: threadid=8: thread exiting with uncaught exception (group=0x40028a00)
01-06 11:14:08.517 95-121/? I/ActivityManager: Displayed activity com.android.gl2jni/.GL2JNIActivity: 9823 ms (total 2027818 ms)
01-06 11:14:08.567 12771-12813/com.android.gl2jni E/AndroidRuntime: FATAL EXCEPTION: GLThread 9
java.lang.ExceptionInInitializerError
at com.android.gl2jni.GL2JNIView$Renderer.onSurfaceChanged(GL2JNIView.java:332)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1327)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1118)
Caused by: java.lang.UnsatisfiedLinkError: Library gl2jni not found
at java.lang.Runtime.loadLibrary(Runtime.java:461)
at java.lang.System.loadLibrary(System.java:557)
at com.android.gl2jni.GL2JNILib.<clinit>(GL2JNILib.java:24)
at com.android.gl2jni.GL2JNIView$Renderer.onSurfaceChanged(GL2JNIView.java:332) 
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1327) 
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1118) 
01-06 11:14:08.607 95-164/? W/ActivityManager: Force finishing activity com.android.gl2jni/.GL2JNIActivity
This sample works on the 3 other devices i've tried (Galaxy s5, Galaxy J1, Nexus s)
The line: 'Unable to dlopen(/data/data/com.android.gl2jni/lib/libgl2jni.so): Cannot load library: link_image[1995]: failed to link libgl2jni.so' is probably key. I tried loading the library explicitly using system.loadlibrary, but the same problem happens on that call.
I think it might be something to do with the processor being armv6?
The sample is configured to do 'armeabi' though.

RenderScript No JNI_OnLoad found error

I am using renderscript library in my project and I perfectly run my apk on Samsung S4 I9500. But when I tried this in other phones I get crash.
No JNI_OnLoad found in /system/lib/libRSSupport.so 0x4185f0f0, skipping init
02-23 19:42:40.370 8994-8994/com.example.gameboy.gununtesti E/dalvikvm﹕ ERROR: couldn't find native method
02-23 19:42:40.370 8994-8994/com.example.gameboy.gununtesti E/dalvikvm﹕ Requested: Landroid/support/v8/renderscript/RenderScript;._nInit:()V
02-23 19:42:40.370 8994-8994/com.example.gameboy.gununtesti E/JNIHelp﹕ RegisterNatives failed for 'android/support/v8/renderscript/RenderScript', aborting
02-23 19:42:40.370 8994-8994/com.example.gameboy.gununtesti A/libc﹕ Fatal signal 11 (SIGSEGV) at 0xdeadbaad (code=1), thread 8994
Any help appreciated. Thanks.
You forgot to include libRSSupport.so + the other native libraries in your .apk. This is attempting to load the system version of the compatibility, library, which will not work with your app.

onJNILoad not being called when calling System.loadLibrary

I have add a print log statement in JNI_OnLoad, but I found that it is not being called. Here is my JNI_OnLoad method.
extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved) {
__android_log_print(ANDROID_LOG_INFO, __FUNCTION__, "onLoad");
// some init code
}
Do I need to declare JNI_OnLoad in a specific file or declare sth in Android.MK tells system where to find the JNI_OnLoad method? Now I just put to one of the many .cpp files.
compiled .so lib is attached. I try to dump the so file, and I am sure the JNI_OnLoad method is exported.
https://docs.google.com/file/d/0B089WeEZXTb3ZjZiQllaYThuUUk/edit
Actually, I am trying to port a library from android source (libcorejava.so). To avoid class path conflict, I already change the class path.
And here is the file that declares JNI_OnLoad:
https://android.googlesource.com/platform/libcore/+/master/luni/src/main/native/Register.cpp
I already change the signature to the above one in order to match the standard signature
EDIT:
I found that android source does not load it by System.loadLibrary! It says libcorejava is used to implement System.loadLibrary, so we cannot use System.loadLibrary to load it. But in my case, it should not be a problem as I only need part of the function (ICU related).
https://android.googlesource.com/platform/dalvik/+/master/vm/Init.cpp
// Most JNI libraries can just use System.loadLibrary, but you can't
// if you're the library that implements System.loadLibrary!
loadJniLibrary("javacore");
loadJniLibrary("nativehelper");
EDIT 2:
It turns out that it is because the name conflict of the library!
But it seems that libjavacore requires other library. Does there any tool that can list out what the dependency I am missing?
java.lang.UnsatisfiedLinkError: Cannot load library: reloc_library[1286]: XXX
EDIT 3:
TextClock is a new api for displaying time. It only exists in 4.2+ api up. I am trying to backport it so that older sdk can uses it. It depends on a ICU library which resides in libjavacore. So I modify the Android.mk file to make sure the libjavacore only include the icu related source file and the final compiled so file is being included in my apk.
TextClock:
http://developer.android.com/reference/android/widget/TextClock.html
It now works in the phone which originally support TextClock, but doesn't work in old devices. Here is the exception log. I think it is because libjavacore is the wrapper of ICU library. Apart from the wrapper, I still need to port the ICU library. But I am going to give up as the size of ICU library is quite large and seems doesn't worth for it...
12-13 14:07:54.859: E/AndroidRuntime(2091): java.lang.UnsatisfiedLinkError: Cannot load library: reloc_library[1306]: 36 cannot locate '_ZN6icu_516Locale14createFromNameEPKc'...
12-13 14:07:54.859: E/AndroidRuntime(2091): at java.lang.Runtime.loadLibrary(Runtime.java:370)
12-13 14:07:54.859: E/AndroidRuntime(2091): at java.lang.System.loadLibrary(System.java:535)
12-13 14:07:54.859: E/AndroidRuntime(2091): at com.example.time.MainActivity.onCreate(MainActivity.java:20)
12-13 14:07:54.859: E/AndroidRuntime(2091): at android.app.Activity.performCreate(Activity.java:5008)
12-13 14:07:54.859: E/AndroidRuntime(2091): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
12-13 14:07:54.859: E/AndroidRuntime(2091): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
12-13 14:07:54.859: E/AndroidRuntime(2091): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
12-13 14:07:54.859: E/AndroidRuntime(2091): at android.app.ActivityThread.access$600(ActivityThread.java:130)
12-13 14:07:54.859: E/AndroidRuntime(2091): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
12-13 14:07:54.859: E/AndroidRuntime(2091): at android.os.Handler.dispatchMessage(Handler.java:99)
12-13 14:07:54.859: E/AndroidRuntime(2091): at android.os.Looper.loop(Looper.java:137)
12-13 14:07:54.859: E/AndroidRuntime(2091): at android.app.ActivityThread.main(ActivityThread.java:4745)
12-13 14:07:54.859: E/AndroidRuntime(2091): at java.lang.reflect.Method.invokeNative(Native Method)
12-13 14:07:54.859: E/AndroidRuntime(2091): at java.lang.reflect.Method.invoke(Method.java:511)
12-13 14:07:54.859: E/AndroidRuntime(2091): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
12-13 14:07:54.859: E/AndroidRuntime(2091): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
12-13 14:07:54.859: E/AndroidRuntime(2091): at dalvik.system.NativeStart.main(Native Method)
You can dump the symbols in your .so file using readelf in your toolchains folder. Check to see that JNI_OnLoad is exported. The -s (symbols) command and the name of the .so file in your libs folder should do it.
In older releases of Android, the library was linked directly into the VM (libdvm.so linked against libnativehelper.so which linked against libjavacore.a). In recent releases this changed to always load the library at start time, using the internal native library load mechanism, so JNI_OnLoad will be called if present.
If I run adb shell dalvikvm Foo (where "Foo" doesn't exist), I see this in logcat:
D dalvikvm: Trying to load lib libjavacore.so 0x0
D dalvikvm: Added shared lib libjavacore.so 0x0
D dalvikvm: Trying to load lib libnativehelper.so 0x0
D dalvikvm: Added shared lib libnativehelper.so 0x0
D dalvikvm: No JNI_OnLoad found in libnativehelper.so 0x0, skipping init
So it loaded libjavacore.so and apparently found and ran JNI_OnLoad (no news is good news). It loaded libnativehelper.so and didn't find a JNI_OnLoad, so it logged a message to tell you so in case you were expecting otherwise.
If you replace the libjavacore.so in /system/lib (on a rooted device), and run the dalvikvm command, you should see your message in the log file, mixed in with messages like I've shown above. If you restart the system, you should see your message during zygote startup, and not again unless something runs a Dalvik-based command (like am).

Unable to link native library in OpenCV Android sample

I have OpenCV code (c++), which I want to use in Android. To do this I have to use Android NDK. I downloaded OpenCV package for Android development (ver. 2.4.0) and did all steps from that manual. Basic samples (Java API only) run without problems. Sample #3 (Tutorial 3 (Advanced) - Add Native OpenCV) builds from ndk-builder correctly. But always got exception when I'm trying to run/debug it on device from eclipse:
Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lorg/opencv/samples/tutorial3/Sample3View;
In this line:
System.loadLibrary("native_sample");
Here's full logcat log:
05-31 23:41:45.976: W/ActivityThread(9708): Application org.opencv.samples.tutorial3 is waiting for the debugger on port 8100...
05-31 23:41:45.983: I/System.out(9708): Sending WAIT chunk
05-31 23:41:45.983: I/dalvikvm(9708): Debugger is active
05-31 23:41:46.179: I/System.out(9708): Debugger has connected
05-31 23:41:46.179: I/System.out(9708): waiting for debugger to settle...
05-31 23:41:46.382: I/System.out(9708): waiting for debugger to settle...
05-31 23:41:46.585: I/System.out(9708): waiting for debugger to settle...
05-31 23:41:46.788: I/System.out(9708): waiting for debugger to settle...
05-31 23:41:46.983: I/System.out(9708): waiting for debugger to settle...
05-31 23:41:47.186: I/System.out(9708): waiting for debugger to settle...
05-31 23:41:47.389: I/System.out(9708): waiting for debugger to settle...
05-31 23:41:47.585: I/System.out(9708): waiting for debugger to settle...
05-31 23:41:47.788: I/System.out(9708): debugger has settled (1463)
05-31 23:41:47.819: D/szipinf(9708): Initializing inflate state
05-31 23:41:47.866: I/Sample::Activity(9708): Instantiated new class org.opencv.samples.tutorial3.Sample3Native
05-31 23:41:48.909: D/dalvikvm(9708): threadid=1: still suspended after undo (sc=1 dc=1)
05-31 23:41:51.770: I/Sample::Activity(9708): onCreate
05-31 23:41:59.283: W/dalvikvm(9708): Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lorg/opencv/samples/tutorial3/Sample3View;
05-31 23:42:01.965: D/AndroidRuntime(9708): Shutting down VM
05-31 23:42:01.965: W/dalvikvm(9708): threadid=1: thread exiting with uncaught exception (group=0x40015560)
05-31 23:42:01.999: E/AndroidRuntime(9708): FATAL EXCEPTION: main
05-31 23:42:01.999: E/AndroidRuntime(9708): java.lang.ExceptionInInitializerError
05-31 23:42:01.999: E/AndroidRuntime(9708): at org.opencv.samples.tutorial3.Sample3Native.onCreate(Sample3Native.java:21)
05-31 23:42:01.999: E/AndroidRuntime(9708): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-31 23:42:01.999: E/AndroidRuntime(9708): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1722)
05-31 23:42:01.999: E/AndroidRuntime(9708): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1784)
05-31 23:42:01.999: E/AndroidRuntime(9708): at android.app.ActivityThread.access$1500(ActivityThread.java:123)
05-31 23:42:01.999: E/AndroidRuntime(9708): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939)
05-31 23:42:01.999: E/AndroidRuntime(9708): at android.os.Handler.dispatchMessage(Handler.java:99)
05-31 23:42:01.999: E/AndroidRuntime(9708): at android.os.Looper.loop(Looper.java:130)
05-31 23:42:01.999: E/AndroidRuntime(9708): at android.app.ActivityThread.main(ActivityThread.java:3835)
05-31 23:42:01.999: E/AndroidRuntime(9708): at java.lang.reflect.Method.invokeNative(Native Method)
05-31 23:42:01.999: E/AndroidRuntime(9708): at java.lang.reflect.Method.invoke(Method.java:507)
05-31 23:42:01.999: E/AndroidRuntime(9708): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
05-31 23:42:01.999: E/AndroidRuntime(9708): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
05-31 23:42:01.999: E/AndroidRuntime(9708): at dalvik.system.NativeStart.main(Native Method)
05-31 23:42:01.999: E/AndroidRuntime(9708): Caused by: java.lang.UnsatisfiedLinkError: Couldn't load native_sample: findLibrary returned null
05-31 23:42:01.999: E/AndroidRuntime(9708): at java.lang.Runtime.loadLibrary(Runtime.java:429)
05-31 23:42:01.999: E/AndroidRuntime(9708): at java.lang.System.loadLibrary(System.java:554)
05-31 23:42:01.999: E/AndroidRuntime(9708): at org.opencv.samples.tutorial3.Sample3View.<clinit>(Sample3View.java:48)
05-31 23:42:01.999: E/AndroidRuntime(9708): ... 14 more
I find solutions for the same problem but none of them didn't help me:
Native OpenCV Samples for Android throws UnsatisfiedLinkError
java.lang.UnsatisfiedLinkError: Couldn't load opencv_java: findLibrary returned null
Major OpenCV-Android for Windows Installing and Running Issues (no answer)
Also I have tested it on different devices and Android API versions.
My system configuration:
astor#astor-K42Jv:~$ uname -a
Linux astor-K42Jv 3.2.0-24-generic-pae #39-Ubuntu SMP Mon May 21 18:54:21 UTC 2012 i686 i686 i386 GNU/Linux
I've been tried to fix this problem for 4 nights (it's my free time :) ), but with no luck. I really need this for my thesis, so any help will be appreciated.
Update: I have tested this sample on Windows 7 (64), but result is the same.
It seems that this is OpenCV bug.
Update: Build log:
astor#astor-K42Jv:/opt/eclipse-android/workspace/OpenCV-2.4.0-samples/tutorial-3-native$ ndk-build
Install : libnative_camera_r2.2.0.so => libs/armeabi-v7a/libnative_camera_r2.2.0.so
Install : libnative_camera_r2.3.3.so => libs/armeabi-v7a/libnative_camera_r2.3.3.so
Install : libnative_camera_r3.0.1.so => libs/armeabi-v7a/libnative_camera_r3.0.1.so
Install : libnative_camera_r4.0.0.so => libs/armeabi-v7a/libnative_camera_r4.0.0.so
Install : libnative_camera_r4.0.3.so => libs/armeabi-v7a/libnative_camera_r4.0.3.so
Install : libnative_sample.so => libs/armeabi-v7a/libnative_sample.so
Whoohoo!
Finally I found solution for this problem by myself!
I decided to debug line:
System.loadLibrary("native_sample");
To do this I downloaded android source code from Android-SDK and then attached source folder (/opt/android-sdk-linux/sources/android-15) to my project.
After this I found that error was:
Cannot load library: link_image[1936]: 37 could not load needed library 'libopencv_java.so' for 'libhello-jni.so' (load_library[1091]: Library 'libopencv_java.so' not found)
And really this library is not in lib directory. I don't know why but ndk-build ignored it. So i decided to copy and load it manualy. For this I copied libopencv_java.so from /opt/OpenCV-2.4.0/libs/armeabi-v7a and also edited java code:
static {
System.loadLibrary("opencv_java"); //load opencv_java lib
System.loadLibrary("native_sample");
}
Actually similar problems are:
Can not load Opencv libraries in necessitas
Android OpenCV: cannot dlopen camera wrapper library
From second solution I found that I can load libraries using dlopen, but I haven't tried it yet.
So I will write simple bash-script that will do it (just copy) for myself.
Thanks to all.
Instead of loading your native library as
static{
System.loadLibrary("YOUR_LIBRARY");
}
load your library after opencv manager is connected in "onManagerConnected" method in you "BaseLoaderCallBack". Following is my code snippet working for me
public void onManagerConnected(int status) {
switch(status){
case LoaderCallbackInterface.SUCCESS:
Toast.makeText(getApplicationContext(), "manager connected", Toast.LENGTH_LONG).show();
System.loadLibrary("MYNATIVELIB");
break;
default:
super.onManagerConnected(status);
break;
}
}
You're at a higher level than the actual problem. See "Getting started with the NDK", when you run
cd <project>
<ndk>/ndk-build
... what does it say? (Remember to use the cygwin window and not a dos prompt).

Android Hello World app crashes: IllegalArgumentException from Surface.lockCanvasNative

I am trying to run the simplest Hello World example app and looks like I can crash it even all it does is showing a TextView.
Steps to reproduce: Launch it in the emulator (1.5). Open the app - it shows the text view, then lock the phone by pressing "end call" button. Unlock by pressing "menu", then press "back". App crashes with "The process android.process.acore has stopped unexpectedly..." and Force Close button. It does not happen all the time, but I am able to reproduce it every time after wiping the user data at least.
I wonder if default Hello World is missing a detail which was considered too advanced for a hello world... Such problems with a basic example does not look very encouraging =)
Any idea what detail is missing and how to avoid this crash?
Stack (I've truncated timestamps):
37.478: DEBUG/KeyguardViewMediator(576): wakeWhenReadyLocked(82)
37.481: DEBUG/KeyguardViewMediator(576): handleWakeWhenReady(82)
37.481: DEBUG/KeyguardViewMediator(576): pokeWakelock(5000)
39.110: DEBUG/KeyguardViewMediator(576): pokeWakelock(5000)
39.140: WARN/InputManagerService(576): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy#436e3fc0
40.990: ERROR/IMemory(679): binder=0x238aa8 transaction failed fd=-2147483647, size=0, err=-2147483646 (Unknown error: 2147483646)
40.990: ERROR/IMemory(679): cannot dup fd=-2147483647, size=0, err=-2147483646 (Bad file number)
40.990: ERROR/IMemory(679): cannot map BpMemoryHeap (binder=0x238aa8), size=0, fd=-1 (Bad file number)
40.990: ERROR/Surface(679): Couldn't map Surface's heap (binder=0x238aa8, heap=0x238b00)
40.990: DEBUG/AndroidRuntime(679): Shutting down VM
40.990: WARN/dalvikvm(679): threadid=3: thread exiting with uncaught exception (group=0x4000fe70)
40.990: ERROR/AndroidRuntime(679): Uncaught handler: thread main exiting due to uncaught exception
40.990: ERROR/AndroidRuntime(679): java.lang.IllegalArgumentException
40.990: ERROR/AndroidRuntime(679): at android.view.Surface.lockCanvasNative(Native Method)
40.990: ERROR/AndroidRuntime(679): at android.view.Surface.lockCanvas(Surface.java:196)
40.990: ERROR/AndroidRuntime(679): at android.view.ViewRoot.draw(ViewRoot.java:1175)
40.990: ERROR/AndroidRuntime(679): at android.view.ViewRoot.performTraversals(ViewRoot.java:1030)
40.990: ERROR/AndroidRuntime(679): at android.view.ViewRoot.handleMessage(ViewRoot.java:1482)
40.990: ERROR/AndroidRuntime(679): at android.os.Handler.dispatchMessage(Handler.java:99)
40.990: ERROR/AndroidRuntime(679): at android.os.Looper.loop(Looper.java:123)
40.990: ERROR/AndroidRuntime(679): at android.app.ActivityThread.main(ActivityThread.java:3948)
40.990: ERROR/AndroidRuntime(679): at java.lang.reflect.Method.invokeNative(Native Method)
40.990: ERROR/AndroidRuntime(679): at java.lang.reflect.Method.invoke(Method.java:521)
40.990: ERROR/AndroidRuntime(679): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
40.990: ERROR/AndroidRuntime(679): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
40.990: ERROR/AndroidRuntime(679): at dalvik.system.NativeStart.main(Native Method)
41.000: INFO/Process(576): Sending signal. PID: 679 SIG: 3
41.000: INFO/dalvikvm(679): threadid=7: reacting to signal 3
41.030: ERROR/ActivityThread(576): Failed to find provider info for android.server.checkin
41.030: ERROR/Checkin(576): Error reporting crash: java.lang.IllegalArgumentException: Unknown URL content://android.server.checkin/crashes
41.070: INFO/dalvikvm(679): Wrote stack trace to '/data/anr/traces.txt'
50.940: WARN/ActivityManager(576): Launch timeout has expired, giving up wake lock!
50.980: WARN/ActivityManager(576): Activity idle timeout for HistoryRecord{4366ac40 {com.android.launcher/com.android.launcher.Launcher}}
sounds to me more like something wrong with your emulator. Why dont you delete your emulator and create a new one and try again with a fresh project.
Hope that will help you. BTW why are you using emulator on 1.5?? Start to build applications for min 2.1.
Good luck.

Categories

Resources