2

I'am trying to load some native c libraries into my Andoid app, and I'm getting the following error :

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

Here is a part of the logcat message :

    05-15 14:08:03.177 21078-21078/fr.limsi.registration A/art: art/runtime/java_vm_ext.cc:410] 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
    05-15 14:08:03.177 21078-21078/fr.limsi.registration A/art: art/runtime/java_vm_ext.cc:410]   at java.lang.String java.lang.Runtime.nativeLoad(java.lang.String, java.lang.ClassLoader, java.lang.String) (Runtime.java:-2)
    05-15 14:08:03.177 21078-21078/fr.limsi.registration A/art: art/runtime/java_vm_ext.cc:410]   at java.lang.String java.lang.Runtime.doLoad(java.lang.String, java.lang.ClassLoader) (Runtime.java:435)
    05-15 14:08:03.177 21078-21078/fr.limsi.registration A/art: art/runtime/java_vm_ext.cc:410]   at void java.lang.Runtime.loadLibrary(java.lang.String, java.lang.ClassLoader) (Runtime.java:370)
    05-15 14:08:03.177 21078-21078/fr.limsi.registration A/art: art/runtime/java_vm_ext.cc:410]   at void java.lang.System.loadLibrary(java.lang.String) (System.java:1076)
    05-15 14:08:03.177 21078-21078/fr.limsi.registration A/art: art/runtime/java_vm_ext.cc:410]   at void fr.limsi.registration.utils.NativeInterface.<clinit>() (NativeInterface.java:12)
    05-15 14:08:03.177 21078-21078/fr.limsi.registration A/art: art/runtime/java_vm_ext.cc:410]   at void fr.limsi.registration.utils.NativeInterface.tangoInitServices() (NativeInterface.java:-2)
    05-15 14:08:03.177 21078-21078/fr.limsi.registration A/art: art/runtime/java_vm_ext.cc:410]   at void fr.limsi.registration.activities.ProjectViewActivity.onStart() (ProjectViewActivity.java:63)
    05-15 14:08:03.177 21078-21078/fr.limsi.registration A/art: art/runtime/java_vm_ext.cc:410]   at void android.app.Instrumentation.callActivityOnStart(android.app.Activity) (Instrumentation.java:1238)
    05-15 14:08:03.177 21078-21078/fr.limsi.registration A/art: art/runtime/java_vm_ext.cc:410]   at void android.app.Activity.performStart() (Activity.java:6302)

I interpret this as :

The class android.od.Parcel doesn't have any field called "mNativePtr".

I'm using a Lenovo PHAB II tablet, running with Abdroid 6.0, and the art virtual machine. It the first time I have this issue when running some native code on Android, and I don't understand why I get this message. It happens when the app performs a call to System.loadLibrary(), and the app crashes before executing my native code. Does anyone have any idea?

Thanks a lot!

P.S : I proguard is disabled

aarnaud
  • 21
  • 1
  • 3
  • just look at [this](http://stackoverflow.com/questions/34891686/android-jni-detected-error-in-application-jni-getmethodid-called-with-pending-e) – Mehran Zamani May 15 '17 at 12:43
  • The problem occurs when I try to load a library, not when i'm using it. it seems that it's the code run by System.loadLibrary() that fails when finding the mNativePtr, but there is no reason at all. – aarnaud May 15 '17 at 12:59

2 Answers2

2

I ran into this with the Google Tango libraries, but I have not found a solution. Sorry, I don't have enough karma to comment yet.

Given you're using a Google Tango device, I assume your problem is the same as mine. Something with Google Tango.

edit:

solved it. Needed to load the tango_client_api.so first, before loading anything else:

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");
}
randyrand
  • 433
  • 1
  • 4
  • 9
0

Android has changed its internal implementation of class android.os.Parcel from version 4.0 to 4.1.

In version 4.1.1 there is:

@SuppressWarnings({"UnusedDeclaration"})
private int mNativePtr; // used by native code
/**
 * Flag indicating if {@link #mNativePtr} was allocated by this object,
 * indicating that we're responsible for its lifecycle.
 */
private boolean mOwnsNativeParcelObject;

In version 4.0.4 there was:

@SuppressWarnings({"UnusedDeclaration"})
private int mObject; // used by native code
@SuppressWarnings({"UnusedDeclaration"})
private int mOwnObject; // used by native code

It seems your other native C libraries are compatible to Android 4.1, but not to Android 4.0.

Thomas Fritsch
  • 9,639
  • 33
  • 37
  • 49
  • I'm compiling with the android API 23 Platform. The Parcel class contains the field mNativePtr, but is not used by the Java code. Maybe this field is auto removed during the build. – aarnaud May 15 '17 at 14:31