googlearchive / tango-examples-c

JNI example projects for Project Tango [deprecated] C-API
https://developers.google.com/ar
Apache License 2.0
337 stars 204 forks source link

LoadLibrary fails when including tango .SO #104

Open chipweinberger opened 7 years ago

chipweinberger commented 7 years ago

When adding the shared tango libs into an existing Android Studio project, load Library fails with this exception

JNI DETECTED ERROR IN APPLICATION: JNI NewGlobalRef called with pending exception java.lang.NoSuchFieldError: no "I" field "mNativePtr" in class "Landroid/os/Parcel;" or its superclasses'

backtrace:
05-23 17:45:10.254 546-546/? A/DEBUG:     #00 pc 00044320  /system/lib/libc.so (tgkill+12)
05-23 17:45:10.254 546-546/? A/DEBUG:     #01 pc 00041f21  /system/lib/libc.so (pthread_kill+32)
05-23 17:45:10.254 546-546/? A/DEBUG:     #02 pc 0001ba4f  /system/lib/libc.so (raise+10)
05-23 17:45:10.254 546-546/? A/DEBUG:     #03 pc 00018bf1  /system/lib/libc.so (__libc_android_abort+34)
05-23 17:45:10.254 546-546/? A/DEBUG:     #04 pc 000167b0  /system/lib/libc.so (abort+4)
05-23 17:45:10.255 546-546/? A/DEBUG:     #05 pc 003216c9  /system/lib/libart.so (_ZN3art7Runtime5AbortEv+212)
05-23 17:45:10.255 546-546/? A/DEBUG:     #06 pc 000f3c6d  /system/lib/libart.so (_ZN3art10LogMessageD2Ev+2212)
05-23 17:45:10.255 546-546/? A/DEBUG:     #07 pc 0024f7fd  /system/lib/libart.so (_ZN3art9JavaVMExt8JniAbortEPKcS2_+1524)
05-23 17:45:10.255 546-546/? A/DEBUG:     #08 pc 0024fb9f  /system/lib/libart.so (_ZN3art9JavaVMExt9JniAbortVEPKcS2_St9__va_list+54)
05-23 17:45:10.255 546-546/? A/DEBUG:     #09 pc 000fc013  /system/lib/libart.so (_ZN3art11ScopedCheck6AbortFEPKcz+30)
05-23 17:45:10.255 546-546/? A/DEBUG:     #10 pc 00100eef  /system/lib/libart.so (_ZN3art11ScopedCheck5CheckERNS_18ScopedObjectAccessEbPKcPNS_12JniValueTypeE.constprop.95+5054)
05-23 17:45:10.255 546-546/? A/DEBUG:     #11 pc 001126a5  /system/lib/libart.so (_ZN3art8CheckJNI12NewGlobalRefEP7_JNIEnvP8_jobject+376)
05-23 17:45:10.255 546-546/? A/DEBUG:     #12 pc 003362f5  /system/lib/libart.so (_ZN3art6Thread22SetClassLoaderOverrideEP8_jobject+32)
05-23 17:45:10.255 546-546/? A/DEBUG:     #13 pc 00250101  /system/lib/libart.so (_ZN3art9JavaVMExt17LoadNativeLibraryEP7_JNIEnvRKNSt3__112basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEEP8_jobjectPS9_+1228)
05-23 17:45:10.256 546-546/? A/DEBUG:     #14 pc 002c203f  /system/lib/libart.so (_ZN3artL18Runtime_nativeLoadEP7_JNIEnvP7_jclassP8_jstringP8_jobjectS5_+178)
05-23 17:45:10.256 546-546/? A/DEBUG:     #15 pc 0212fdc5  /system/framework/arm/boot.oat (offset 0x1f23000)

There is another person on stackoverflow with the same tango issue, but no posted answer.

chipweinberger commented 7 years ago

I'm also using the Lenovo Phab II tablet, and am having the same issue as this guy

https://stackoverflow.com/questions/43979666/jni-detected-error-in-application-jni-newglobalref-called-with-pending-exceptio

chipweinberger commented 7 years ago

May have solved it. Needed to load the tango_client_api.so first:


public class MainActivity extends AppCompatActivity {

    // Used to load the 'native-lib' library on application startup.
    static {
        // This project depends on tango_client_api, so we need to make sure we load
        // the correct library first.
        if (com.projecttango.examples.cpp.util.TangoInitializationHelper.loadTangoSharedLibrary() ==
                com.projecttango.examples.cpp.util.TangoInitializationHelper.ARCH_ERROR) {
            Log.e("TangoJNINative", "ERROR! Unable to load libtango_client_api.so!");
        }
        System.loadLibrary("native-lib");
    }