gpt4 book ai didi

android - JNI CallVoidMethod 导致致命信号 6 和无效的间接引用

转载 作者:行者123 更新时间:2023-11-30 17:14:48 46 4
gpt4 key购买 nike

我正在尝试从 android-ndk 内发送短信。当我尝试调用 SmsManager 中的 sendTextMessage 方法时,我的应用程序崩溃,错误代码为 6(中止)。此外,我收到一条错误消息“decodeIndirectRef 中的间接引用 0xe7f03658 无效”。我认为这与我的对象引用有关,但据我所知,我正在使用的对象并未使用所述地址。

执行最后一行时应用程序崩溃。我检查了所有内容是否有异常,但没有一个出现异常。

#ifndef NULL
#define NULL ((void *) 0)
#endif

#include <string.h>
#include <jni.h>
#include <android/log.h>

JNIEXPORT void JNICALL Java_tss_challenges_hybrid_App_sendSMS(JNIEnv* env,
jobject thiz) {
jclass smsManagerClz = (*env)->FindClass(env,
"android/telephony/SmsManager");
jmethodID getDefaultMethodID = (*env)->GetStaticMethodID(env, smsManagerClz,
"getDefault", "()Landroid/telephony/SmsManager;");
jobject smsManagerObj = (*env)->CallStaticObjectMethod(env, smsManagerClz,
getDefaultMethodID);
jmethodID sendSMSMethodID = (*env)->GetMethodID(env, smsManagerClz,
"sendTextMessage",
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;"
"Landroid/app/PendingIntent;Landroid/app/PendingIntent;)V");

jstring number = (*env)->NewStringUTF(env, "1234");
jstring text = (*env)->NewStringUTF(env, "sms content");
jstring nullString = (*env)->NewStringUTF(env, NULL);

__android_log_print(ANDROID_LOG_VERBOSE, "MyApp", "%x,%x,%x,%x,%x,%x,%x,%x", number, text, nullString,smsManagerObj,sendSMSMethodID,env,smsManagerClz,getDefaultMethodID);
(*env)->CallVoidMethod(env, smsManagerObj, sendSMSMethodID, number, nullString, text, NULL, NULL);
}

日志:

05-11 14:17:00.718: D/dalvikvm(2376): Trying to load lib /data/app-lib/tss.chalenges.hybrid-1/libnativeSMSManager.so 0xb2d5b2d0
05-11 14:17:00.718: D/dalvikvm(2376): Added shared lib /data/app-lib/tss.chalenges.hybrid-1/libnativeSMSManager.so 0xb2d5b2d0
05-11 14:17:00.718: D/dalvikvm(2376): No JNI_OnLoad found in /data/app-lib/tss.chalenges.hybrid-1/libnativeSMSManager.so 0xb2d5b2d0, skipping init
05-11 14:17:00.848: V/MyApp(2376): c2900025,a0f00029,0,ba100021,b0be31c0,b82cff30,b680001d,b0be2f18
05-11 14:17:00.948: W/dalvikvm(2376): Invalid indirect reference 0xe7f03658 in decodeIndirectRef
05-11 14:17:00.948: I/dalvikvm(2376): "main" prio=5 tid=1 RUNNABLE
05-11 14:17:00.948: I/dalvikvm(2376): | group="main" sCount=0 dsCount=0 obj=0xb2a94ca8 self=0xb82d3398
05-11 14:17:00.958: I/dalvikvm(2376): | sysTid=2376 nice=0 sched=0/0 cgrp=apps handle=-1225264812
05-11 14:17:00.958: I/dalvikvm(2376): | state=R schedstat=( 100000000 380000000 94 ) utm=6 stm=4 core=0
05-11 14:17:00.958: I/dalvikvm(2376): at tss.challenges.hybrid.App.sendSMS(Native Method)
05-11 14:17:00.958: I/dalvikvm(2376): at tss.challenges.hybrid.App.onCreate(App.java:36)
05-11 14:17:00.958: I/dalvikvm(2376): at android.app.Activity.performCreate(Activity.java:5231)
05-11 14:17:00.958: I/dalvikvm(2376): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
05-11 14:17:00.958: I/dalvikvm(2376): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
05-11 14:17:00.958: I/dalvikvm(2376): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
05-11 14:17:00.958: I/dalvikvm(2376): at android.app.ActivityThread.access$800(ActivityThread.java:135)
05-11 14:17:00.958: I/dalvikvm(2376): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
05-11 14:17:00.958: I/dalvikvm(2376): at android.os.Handler.dispatchMessage(Handler.java:102)
05-11 14:17:00.958: I/dalvikvm(2376): at android.os.Looper.loop(Looper.java:136)
05-11 14:17:00.958: I/dalvikvm(2376): at android.app.ActivityThread.main(ActivityThread.java:5017)
05-11 14:17:00.958: I/dalvikvm(2376): at java.lang.reflect.Method.invokeNative(Native Method)
05-11 14:17:00.958: I/dalvikvm(2376): at java.lang.reflect.Method.invoke(Method.java:515)
05-11 14:17:00.958: I/dalvikvm(2376): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
05-11 14:17:00.958: I/dalvikvm(2376): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
05-11 14:17:00.958: I/dalvikvm(2376): at dalvik.system.NativeStart.main(Native Method)
05-11 14:17:00.998: E/dalvikvm(2376): VM aborting
05-11 14:17:01.018: A/libc(2376): Fatal signal 6 (SIGABRT) at 0x00000948 (code=-6), thread 2376 (halenges.hybrid)

最佳答案

你不需要传递NULL STRING,你可以在参数的那个地方直接传递NULL

避免这种情况

jstring nullString = (*env)->NewStringUTF(env, NULL);

尝试使用NULL

jstring nullString = (*env)->NewStringUTF(env, "");

关于android - JNI CallVoidMethod 导致致命信号 6 和无效的间接引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30175062/

46 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com