我一直在调试此错误3天。在我的Android项目中,我试图从Native Code中抛出异常。我创建了自己的异常类,它扩展了标准Java异常类。以下是我从Native Code中抛出Exception的方法。
extern "C" JNIEXPORT void JNICALL Java_com_company_MyClass_nativeCall(JNIEnv *env, jclass type)
{
// Other code stuffs
jclass clazz = env->FindClass("com/company/MyExceptionClass");
env->ThrowNew(clazz, "Error");
}
但是当执行ThrowNew()时,它会跟随
崩溃F/libc (19699): Fatal signal 4 (SIGILL) at 0x7191ed06 (code=1), thread 19699 (mythread.myclass)
I/DEBUG ( 6189): signal 4 (SIGILL), code 1 (ILL_ILLOPC), fault addr 7191ed06
I/DEBUG ( 6189): r0 00000000 r1 41641d00 r2 4017b394 r3 61ff270f
I/DEBUG ( 6189): r4 61ff270f r5 41579870 r6 00000003 r7 bec33238
I/DEBUG ( 6189): r8 bec33360 r9 6d4fdbf0 sl 41579880 fp bec33374
I/DEBUG ( 6189): ip 00000000 sp bec331f0 lr 415c02e3 pc 7191ed06 cpsr 600e0030
I/DEBUG ( 6189): d0 0000000000000000 d1 0000000000000000
I/DEBUG ( 6189): d2 0000000000000000 d3 0000000000000000
I/DEBUG ( 6189): d4 6d582ab06d582a78 d5 6d582b206d582ae8
I/DEBUG ( 6189): d6 6d582b906d582b58 d7 3f8000003f800000
I/DEBUG ( 6189): d8 0000000000000000 d9 0000000000000000
I/DEBUG ( 6189): d10 0000000000000000 d11 0000000000000000
I/DEBUG ( 6189): d12 0000000000000000 d13 0000000000000000
I/DEBUG ( 6189): d14 0000000000000000 d15 0000000000000000
I/DEBUG ( 6189): d16 6d5396b8416499f8 d17 6d5396b84164a1e8
I/DEBUG ( 6189): d18 6d5041986d539560 d19 6d5396086d5041d0
I/DEBUG ( 6189): d20 6d5042786d504240 d21 6d5394486d5042b0
I/DEBUG ( 6189): d22 6d5395286d539480 d23 6d5395d06d539598
I/DEBUG ( 6189): d24 0000000000000000 d25 0000000000000000
I/DEBUG ( 6189): d26 0000000000000000 d27 0000000000000000
I/DEBUG ( 6189): d28 0000000000000000 d29 0000000000000000
I/DEBUG ( 6189): d30 0000000000000000 d31 0000000000000000
I/DEBUG ( 6189): scr 60000010
我也尝试过使用throwable Object的env-> Throw()。但行为是一样的。我认为它可能是平板电脑设备(索尼Z2)的动态libc支持问题所以我使用静态libc ++编译与Follow gradle文件。但它没有任何效果。我仍然得到了崩溃。
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
arguments "-DANDROID_PLATFORM=android-23", "-DANDROID_NATIVE_API_LEVEL=android-23", "-DANDROID_PIE=ON", "-DANDROID_STL=c++_static"
cppFlags "-DANDROID_NATIVE_API_LEVEL=android-23", "-DANDROID_PLATFORM=android-23", "-DANDROID_STL=c++_static"
cFlags "-DANDROID_NATIVE_API_LEVEL=android-23", "-DANDROID_PLATFORM=android-23"
}
}
ndk {
abiFilters 'armeabi-v7a', 'arm64-v8a'
}
}
publishNonDefault true
productFlavors {
internal {
versionName "0.0.1-internal"
}
consumer {
versionName "0.0.1-public"
}
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
debuggable true
jniDebuggable true
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
}
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:appcompat-v7:23.0.1'
testCompile 'junit:junit:4.12'
}
我真的很感激任何帮助。