1

This error is occurring in a release based APK, not in debug APK

JNI DETECTED ERROR IN APPLICATION: JNI NewGlobalRef called with pending exception java.lang.ClassNotFoundException: Didn't find class "com.google.android.filament.NioUtils"

it arises on this line when an Intent is being started

Intent intent = new Intent(v.getContext() ,MainActivity.class);
                startActivity(intent);

I am using the scene from the library and wasn't able to figure out why is this issue happening

I referenced this question but still wasn't able to understand because I have added everything as a maven dependency.

I am using a SceneForm Library maintained here https://github.com/ThomasGorisse/sceneform-android-sdk

and have added that as a Maven Dependency

here is the Gradle App file

plugins {
    id 'com.android.application'
    id 'com.google.gms.google-services'
}

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.3"

    defaultConfig {
        applicationId "com.pinakulo.piar"
        minSdkVersion 24
        targetSdkVersion 30
        versionCode 8
        versionName "1"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    implementation 'com.google.ar:core:1.23.0'
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'androidx.fragment:fragment:1.3.3'
    implementation("com.gorisse.thomas.sceneform:sceneform:1.18.10")
    implementation 'com.google.firebase:firebase-storage:20.0.0'
    implementation 'com.google.firebase:firebase-firestore'
    implementation 'androidx.cardview:cardview:1.0.0'
    // Import the BoM for the Firebase platform
    implementation platform('com.google.firebase:firebase-bom:28.0.1')
    // Declare the dependency for the Firebase Authentication library
    // When using the BoM, you don't specify versions in Firebase library dependencies
    implementation 'com.google.firebase:firebase-auth'
    implementation 'com.google.android.material:material:1.3.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    implementation 'com.google.android.gms:play-services-auth:19.0.0'


    //Image Load Library
    implementation 'com.squareup.picasso:picasso:2.8'

}
Akshat Bahety
  • 41
  • 2
  • 7
  • So your prior JNI exception checking is inadequate. So fix that. You should never have pending exceptions anywhere in JNI. Every JNI call must be exception-checked. – user207421 May 25 '21 at 10:29
  • @user207421 Some guidance on how to would help me a lot, that would be great really new to anroid development. – Akshat Bahety May 25 '21 at 10:35
  • @user207421 and another thing is most of what is on Google is related to NDK I am building the application on Android SDK and SceneForm which is part of Google AR core. – Akshat Bahety May 25 '21 at 10:39
  • The guidance is already present in the JNI Specification. There is no need for anybody to repeat it all here, or for you to waste time in Google. – user207421 May 25 '21 at 10:46

1 Answers1

2

I thought the problem was with JNI or with ARCore but the actual problem was with proguard as pointed out by an amazing user here Github AR Core.

Sounds like your application has some wrong proguard rules; the symbol com.google.android.filament.NioUtils is probably being renamed in production builds, but not in debug builds.

I just needed to edit the proguard file to the following specification

# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.

# Keep the annotations that proguard needs to process.
-keep class com.google.android.filament.proguard.UsedBy*

# Just because native code accesses members of a class, does not mean that the
# class itself needs to be annotated - only annotate classes that are
# referenced themselves in native code.
-keep @com.google.android.filament.proguard.UsedBy* class * {
  <init>();
}
-keepclassmembers class * {
  @com.google.android.filament.proguard.UsedBy* *;
}

So there you go that solved the issues.

Proguard Rules

Akshat Bahety
  • 41
  • 2
  • 7