JNI在应用程序中检测到错误:调用JNI NewGlobalRef时出现挂起异常java.lang.ClassNotFoundException:仅在版本APK中发生
此错误发生在基于版本的APK中,而不是在调试APK中JNI在应用程序中检测到错误:调用JNI NewGlobalRef时出现挂起异常java.lang.ClassNotFoundException:仅在版本APK中发生,java,android,Java,Android,此错误发生在基于版本的APK中,而不是在调试APK中 JNI DETECTED ERROR IN APPLICATION: JNI NewGlobalRef called with pending exception java.lang.ClassNotFoundException: Didn't find class "com.google.android.filament.NioUtils" 当意图开始时,它在这一行出现 Intent intent = new Inte
JNI DETECTED ERROR IN APPLICATION: JNI NewGlobalRef called with pending exception java.lang.ClassNotFoundException: Didn't find class "com.google.android.filament.NioUtils"
当意图开始时,它在这一行出现
Intent intent = new Intent(v.getContext() ,MainActivity.class);
startActivity(intent);
我正在使用库中的场景,但无法找出发生此问题的原因
我引用了这个问题,但仍然无法理解,因为我已经添加了作为maven依赖项的所有内容
我正在使用此处维护的SceneForm库
并将其添加为Maven依赖项
这是Gradle应用程序文件
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'
}
我原以为问题出在JNI或ARCore上,但实际问题出在proguard上,正如这里一位了不起的用户所指出的那样 听起来你的应用程序有一些错误的proguard规则;象征 com.google.android.filame.NioUtils可能在年被重命名 生产版本,但不在调试版本中 我只需要将proguard文件编辑为以下规范
# 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* *;
}
#在此处添加特定于项目的程序规则。
#您可以使用
#在build.gradle中设置proguardFiles。
#保留proguard需要处理的注释。
-保持com.google.android.filame.proguard.UsedBy类*
#仅仅因为本机代码访问类的成员,并不意味着
#类本身需要注释-仅注释
#在本机代码中引用了它们自己。
-keep@com.google.android.filame.proguard.UsedBy*class*{
();
}
-keepclassmembers类*{
@com.google.android.filame.proguard.UsedBy**;
}
这就解决了问题
因此您之前的JNI异常检查是不充分的。所以要解决这个问题。在JNI中任何地方都不应该有挂起的异常。每个JNI调用都必须进行异常检查。@user207421关于如何调用的一些指导将对我有很大帮助,这对于anroid开发来说真是太棒了。@user207421还有一件事是Google上的大部分内容都与NDK有关。我正在Android SDK和SceneForm上构建应用程序,这是Google AR core的一部分。JNI规范中已经提供了指导。没有必要让任何人在这里重复这一切,也没有必要让你在谷歌浪费时间。