I've been developing an NDK app for quite some time and it's been working well. However, today the app randomly decided to not start anymore, after I compiled it after making some nominal change. It's caused by a cryptic problem with loading the app's main library. Here's some log output:
08-11 18:38:11.220 D/dalvikvm( 1237): Added shared lib /mnt/asec/com.audia.rta-1/lib/libqtandroid.so 0x40513bd8
08-11 18:38:11.220 D/dalvikvm( 1237): No JNI_OnLoad found in /mnt/asec/com.audia.rta-1/lib/libqtandroid.so 0x40513bd8, skipping init
08-11 18:38:11.220 D/dalvikvm( 1237): Trying to load lib /mnt/asec/com.audia.rta-1/lib/librta.so 0x40513bd8
08-11 18:38:11.260 D/AndroidRuntime( 1237): Shutting down VM
08-11 18:38:11.260 W/dalvikvm( 1237): threadid=1: thread exiting with uncaught exception (group=0x40015560)
08-11 18:38:11.260 E/AndroidRuntime( 1237): FATAL EXCEPTION: main
08-11 18:38:11.260 E/AndroidRuntime( 1237): java.lang.UnsatisfiedLinkError: Cannot load library: reloc_library[1311]: 67 cannot locate '_ZNSaIcEC1Ev'...
08-11 18:38:11.260 E/AndroidRuntime( 1237):
08-11 18:38:11.260 E/AndroidRuntime( 1237): at java.lang.Runtime.loadLibrary(Runtime.java:434)
08-11 18:38:11.260 E/AndroidRuntime( 1237): at java.lang.System.loadLibrary(System.java:554)
08-11 18:38:11.260 E/AndroidRuntime( 1237): at com.audia.rta.RTA.onCreate(RTA.java:139)
According to some Google results, _ZNSaIcEC1Ev is part of libstdc++. I've checked, and it gets linked in the build process, and g++ is being used for linking.
Oddly enough, reverting to an older apk of the app fixes the problem, but compiling an old revision and installing that doesn't fix the problem. Everything in my build system is checked into version control, and I've done several clean builds. All my builds were working today and then they just stopped working. I didn't upgrade or install anything; it happened while I was in the middle of testing new code. What happened?
Update: Building from a freshly checked out copy doesn't fix the problem.
Update 2: Is there any way I can track down the link to that symbol, maybe with objdump? Maybe this could provide some clues.
I ended up compiling everything with a fresh NDK install, and it worked. It's as if the old one was corrupted somehow, though I have no idea how.
It was also an upgrade from r5b to r6, so maybe it's related to the NDK version.
Related
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.
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.
I've created the sample app given in the latest version (current master) of Apache Cordova Facebook Plugin several times:
https://github.com/phonegap/phonegap-facebook-plugin
Currently, I'm working on Android only.
The first time I created this sample app (about two weeks ago) everything worked fine. I successfully logged in with my facebook account, posted a status to my wall and logged out (all the other actions worked fine as well).
But since than I've created this sample app several more times (in the exact same way), and it has never worked again (the last time I tried was today). In the new apps (with the very same code as the first app, which still works), I press "LOGIN WITH FACEBOOK", and my app crashes immediately. Sometimes the app doesn't crash immediately, and I can get the message "Argument 'session' cannot be null". Then I press "LOGIN WITH FACEBOOK" again, and the app crashes. Sometimes I can get this message several times before the app eventually crashes.
If I press "LOGOUT WITH FACEBOOK", I get the message: "No valid session found, must call init and login before logout".
I also don't think that the problem is that I have a wrong hash key or something like that, because I've been careful with the settings of the facebook app every time.
I also believe that I've installed the plugin correctly each time, because I've always done it the same way I did it the first time, which worked fine.
So how is it that in my latest attempts the session variable is NULL??
Why did it work only in the first time??
I'm very frustrated..
Edit:
Here is the relevant segment of the LogCat log:
D/ConnectPlugin( 7064): login FB
W/dalvikvm( 7064): VFY: unable to resolve static field 2130 (com_facebook_internet_permission_error_title) in Lcom/facebook/android/R$string;
D/dalvikvm( 7064): VFY: replacing opcode 0x60 at 0x0010
I/dalvikvm( 7064): DexOpt: unable to optimize static field ref 0x0851 at 0x18 in Lcom/facebook/AuthorizationClient;.checkInternetPermission
W/dalvikvm( 7064): VFY: unable to resolve static field 2120 (com_facebook_login_activity_layout) in Lcom/facebook/android/R$layout;
D/dalvikvm( 7064): VFY: replacing opcode 0x60 at 0x0003
W/dalvikvm( 7064): VFY: unable to resolve static field 2103 (com_facebook_login_activity_progress_bar) in Lcom/facebook/android/R$id;
D/dalvikvm( 7064): VFY: replacing opcode 0x60 at 0x0008
I/ActivityManager( 2112): START {intent.toShortString} from pid 7064
I/power ( 2112): *** acquire_dvfs_lock : lockType : 1 freq : 1000000
D/PowerManagerService( 2112): acquireDVFSLockLocked : type : DVFS_MIN_LIMIT frequency : 1000000 uid : 1000 pid : 2112 tag : ActivityManager
W/ActivityManager( 2112): mDVFSLock.acquire()
D/dalvikvm( 7064): GC_CONCURRENT freed 455K, 6% free 12931K/13639K, paused 4ms+5ms
W/PluginManager( 7064): THREAD WARNING: exec() call to FacebookConnectPlugin.login blocked the main thread for 207ms. Plugin should use CordovaInterface.getThreadPool().
D/CordovaActivity( 7064): Paused the application!
D/CordovaWebView( 7064): Handle the pause
D/FirewallPolicy( 2112): getURLFilterEnabled(true)
D/FirewallPolicy( 2112): isUrlBlocked - Policy disabled
D/webkit ( 7064): Firewall not null
D/FirewallPolicy( 2112): getURLFilterEnabled(true)
D/FirewallPolicy( 2112): isUrlBlocked - Policy disabled
I/ClipboardServiceEx( 2112): mCBPickerDialog enter case. MSG_DISMISS_DIALOG
D/webkit ( 7064): euler: isUrlBlocked = false
D/FirewallPolicy( 2112): getURLFilterEnabled(true)
D/FirewallPolicy( 2112): isUrlBlocked - Policy disabled
D/ActivityManager( 2112): Trying to launch applicationName
D/KeyguardViewMediator( 2112): setHidden false
I/ClipboardServiceEx( 2112): mCBPickerDialog enter case. MSG_DISMISS_DIALOG
D/AndroidRuntime( 7064): Shutting down VM
W/dalvikvm( 7064): threadid=1: thread exiting with uncaught exception (group=0x40c6c1f8)
E/AndroidRuntime( 7064): FATAL EXCEPTION: main
E/AndroidRuntime( 7064): java.lang.NoClassDefFoundError: com.facebook.android.R$layout
E/AndroidRuntime( 7064): at com.facebook.LoginActivity.onCreate(LoginActivity.java:57)
E/AndroidRuntime( 7064): at android.app.Activity.performCreate(Activity.java:4562)
E/AndroidRuntime( 7064): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1053)
E/AndroidRuntime( 7064): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1934)
E/AndroidRuntime( 7064): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
E/AndroidRuntime( 7064): at android.app.ActivityThread.access$600(ActivityThread.java:128)
E/AndroidRuntime( 7064): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
E/AndroidRuntime( 7064): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 7064): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime( 7064): at android.app.ActivityThread.main(ActivityThread.java:4514)
E/AndroidRuntime( 7064): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 7064): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime( 7064): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
E/AndroidRuntime( 7064): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
E/AndroidRuntime( 7064): at dalvik.system.NativeStart.main(Native Method)
W/ActivityManager( 2112): Force finishing activity com.yomama.test/com.facebook.LoginActivity
W/ActivityManager( 2112): Force finishing activity com.yomama.test/.Test
Another strange thing that happened to me yesterday was that I recompiled and re-installed (on my phone) the first working app, and suddenly it didn't work either (I got the same message after pressing "LOGIN WITH FACEBOOK", and then the app crashed). Then I recompiled and re-installed the app again, and it was working fine again. Weird.
Try the following steps (from this GitHub issue; had worked for me):
+### Android Setup without Eclipse (just CLI)
+Follow the steps above:
cordova create myApp
cd myApp/
cordova platform add android
cordova -d plugin add https://github.com/phonegap/phonegap-facebook-plugin.git --variable APP_ID="123456789" --variable APP_NAME="myApplication"
// add FacebookLib
echo "android.library.reference.2=com.phonegap.plugins.facebookconnect/FacebookLib" >> platforms/android/project.properties
cp platforms/android/local.properties platforms/android/com.phonegap.plugins.facebookconnect/FacebookLib
android update project -p platforms/android/
cd platforms/android/
ant clean
cd com.phonegap.plugins.facebookconnect/FacebookLib
ant clean
open -e AndroidManifest.xml
// change your minSdkVersion and your targetSdkVersion to your environment settings.
ant release
cd ../../../..
cordova build android
With this steps you can add the Plugin without using Eclipse
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).
I'm newbie.
Trying to run HelloWorld example comming with cocos2dx (cocos2d-2.0-rc2-x-2.0.1),
Android SDK 20.0.1, Android NDK r8, on 64bit Linux machine (openSuse 12.1).
When running emulation from Eclipse got following exception:
W/dalvikvm( 644): threadid=13: thread exiting with uncaught exception (group=0x40a13300)
E/AndroidRuntime( 644): FATAL EXCEPTION: GLThread 77
E/AndroidRuntime( 644): java.lang.IllegalArgumentException: No configs match configSpec
E/AndroidRuntime( 644): at android.opengl.GLSurfaceView$BaseConfigChooser.chooseConfig(GLSurfaceView.java:863)
E/AndroidRuntime( 644): at android.opengl.GLSurfaceView$EglHelper.start(GLSurfaceView.java:1024)
E/AndroidRuntime( 644): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1401)
E/AndroidRuntime( 644): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)
D/gralloc_goldfish( 644): Emulator without GPU emulation detected.
Any ideas?
for 2.0, you need to run on a device because the Emulator does not support OpenGL 2.0
for those are interested in how to get OpenGL 2.0 runs on Emulator, here is the link http://www.cocos2d-x.org/boards/6/topics/12563