我正在尝试使用Crashlytics-NDK进行日志记录来处理C ++中的一些JNI代码,但如果我声明并定义crashlytics_context_t
实例并运行应用程序,我会得到一个
ClassNotFoundException: Didn't find class "com.crashlytics.android.core.CrashlyticsCore" on path: DexPathList[[directory "."],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
使用类似的堆栈跟踪:
3139-3139/org.xyz.abc E/art: Unexpected exception:
3139-3139/org.xyz.abc W/System.err: java.lang.ClassNotFoundException: Didn't find class "com.crashlytics.android.core.CrashlyticsCore" on path: DexPathList[[directory "."],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
3139-3139/org.xyz.abc W/System.err: at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
3139-3139/org.xyz.abc W/System.err: at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
3139-3139/org.xyz.abc W/System.err: at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
3139-3139/org.xyz.abc W/System.err: at java.lang.Runtime.nativeLoad(Native Method)
3139-3139/org.xyz.abc W/System.err: at java.lang.Runtime.doLoad(Runtime.java:435)
3139-3139/org.xyz.abc W/System.err: at java.lang.Runtime.loadLibrary(Runtime.java:370)
3139-3139/org.xyz.abc W/System.err: at java.lang.System.loadLibrary(System.java:1076)
3139-3139/org.xyz.abc W/System.err: at org.xyz.efg.NativeEngine.<clinit>(NativeEngine.java:51)
3139-3139/org.xyz.abc W/System.err: at org.xyz.efg.AbcService.initializeAbcEngine(AbcService.java:100)
3139-3139/org.xyz.abc W/System.err: at org.xyz.efg.AbcService.onCreate(AbcService.java:88)
3139-3139/org.xyz.abc W/System.err: at android.app.ActivityThread.handleCreateService(ActivityThread.java:2877)
3139-3139/org.xyz.abc W/System.err: at android.app.ActivityThread.-wrap4(ActivityThread.java)
3139-3139/org.xyz.abc W/System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1427)
3139-3139/org.xyz.abc W/System.err: at android.os.Handler.dispatchMessage(Handler.java:102)
3139-3139/org.xyz.abc W/System.err: at android.os.Looper.loop(Looper.java:148)
3139-3139/org.xyz.abc W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5417)
3139-3139/org.xyz.abc W/System.err: at java.lang.reflect.Method.invoke(Native Method)
3139-3139/org.xyz.abc W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
3139-3139/org.xyz.abc W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
3139-3139/org.xyz.abc W/System.err: Suppressed: java.lang.ClassNotFoundException: com.crashlytics.android.core.CrashlyticsCore
3139-3139/org.xyz.abc W/System.err: at java.lang.Class.classForName(Native Method)
3139-3139/org.xyz.abc W/System.err: at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
3139-3139/org.xyz.abc W/System.err: at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
3139-3139/org.xyz.abc W/System.err: at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
3139-3139/org.xyz.abc W/System.err: ... 17 more
3139-3139/org.xyz.abc W/System.err: Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
我在头文件中将crashlytics_context_t
实例全局声明为extern
以进行日志记录,并在其中一个源文件中将其全局定义为crashlytics_context_t* crashlytics_context_1 = crashlytics_init();
。
Crashlytics NDK适用于标准崩溃报告(即,无需登录C / C ++代码),Crashlytics可以在Java代码中完美地使用日志记录和键值对。
我启用了multidex支持,因为我们支持API 19及更高版本。我的build.gradle
文件:
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
}
android {
compileSdkVersion 25
buildToolsVersion '26.0.0'
defaultConfig {
applicationId 'org.xyz.abc'
minSdkVersion 19
targetSdkVersion 25
multiDexEnabled true
versionCode 5
versionName '1.1.1'
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
ndkBuild {
abiFilters "x86", "armeabi", "armeabi-v7a", "mips"
arguments "APP_PLATFORM=android-19", "NDK_APPLICATION_MK=src/main/jni/Application.mk"
}
}
}
externalNativeBuild {
ndkBuild {
path "src/main/jni/Android.mk"
}
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
jniDebuggable true
}
}
productFlavors {
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha4'
compile 'com.android.support:design:25.3.1'
compile('com.crashlytics.sdk.android:crashlytics:2.6.8@aar') {
transitive = true;
}
compile('com.crashlytics.sdk.android:crashlytics-ndk:1.1.6@aar') {
transitive = true;
}
testCompile 'junit:junit:4.12'
}
crashlytics {
enableNdk true
}
答案 0 :(得分:-4)
尝试清理项目并重建它。