0

I'm trying to send a sms from within the android-ndk. When I try to call the sendTextMessage method in SmsManager, my app crashes with an error code of 6 (abort). Furthermore, I get an errormessage saying "Invalid indirect reference 0xe7f03658 in decodeIndirectRef". I think it has something to do with my object-refs, but the stated address isn't used by the objects I am using as far as I can see.

The app crashes when the last line is executed. I checked everything for exceptions, but none are rising.

#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);
}

Logs:

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)
Manuel
  • 21
  • 5
  • With regards to the post's tags, is this being compiled as C or C++ code? Seeing how I cannot see your function being declared `extern "C"`, and `JNIEnv` is differently typed based on whether `__cplusplus` is defined (see `jni.h`), I'm not sure how your current `env->...` calls would behave in C++. – zenzelezz May 12 '15 at 05:45
  • I changed the tag to C. I am pretty sure it is compiled as pure C code. The file containing the code is a ".c" file. Is there another place where I could derive this information from? – Manuel May 12 '15 at 11:29
  • Can you show the native stack crash trace? Should follow the "Fatal signal 6". If you turn CheckJNI on (http://developer.android.com/training/articles/perf-jni.html#extended_checking) you should get more detailed info. – fadden May 12 '15 at 16:20

1 Answers1

0

You no need to pass NULL STRING, you can directly pass NULL in that place of argument.

Avoid this

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

Try using NULL or

jstring nullString = (*env)->NewStringUTF(env, "");
Michael
  • 57,169
  • 9
  • 80
  • 125
Suman
  • 4,221
  • 7
  • 44
  • 64
  • I used to deliver just NULL. But then I found this: http://stackoverflow.com/questions/11055609/invalid-indirect-reference-on-newobject-call and changed my code acordingly. Both versions lead to the problem stated above. I definitely want to pass NULL to the function. jstring nullString = (*env)->NewStringUTF(env, ""); is the empty string, isn't it? – Manuel May 12 '15 at 11:35