简体   繁体   English

Android(ART)崩溃,错误JNI DETECTED ERROR IN APPLICATION:jstring是无效的本地引用

[英]Android (ART) crash with error JNI DETECTED ERROR IN APPLICATION: jstring is an invalid local reference

I am writing an Android application that processes a picture(RAW format) from the native C (NDK r15b). 我正在编写一个处理本机C(NDK r15b)图片(RAW格式)的Android应用程序。 Im getting the following errors: 我收到以下错误:

 08-14 18:08:25.407 6107-6107/compresor.app.tfg.compresor E/art: 0xa3f20b80 SpaceTypeMallocSpace begin=0x12c00000,end=0x12e17000,limit=0x2ac00000,size=2MB,capacity=384MB,non_growth_limit_capacity=384MB,name="main rosalloc space"] 08-14 18:08:25.407 6107-6107/compresor.app.tfg.compresor E/art: 0xa3f1fa80 allocspace main rosalloc space live-bitmap 3[begin=0x12c00000,end=0x2ac00000] 08-14 18:08:25.407 6107-6107/compresor.app.tfg.compresor E/art: 0xa3f1fac0 allocspace main rosalloc space mark-bitmap 3[begin=0x12c00000,end=0x2ac00000] 08-14 18:08:25.407 6107-6107/compresor.app.tfg.compresor E/art: 0xaf99b780 SpaceTypeImageSpace begin=0x6fbf5000,end=0x6fcf9288,size=1040KB,name="/data/dalvik-cache/x86/system@framework@boot.art"] 08-14 18:08:25.407 6107-6107/compresor.app.tfg.compresor E/art: 0xaf92f1e0 imagespace /data/dalvik-cache/x86/system@framework@boot.art live-bitmap 0[begin=0x6fbf5000,end=0x6fcf9300] 08-14 18:08:25.407 6107-6107/compresor.app.tfg.compresor E/art: 0xaf92f1e0 imagespace /data/dalvik-cache/x86/system@framework@boot.art live-bitmap 0[begin=0x6fbf5000,end=0x6fcf9300] 08-14 18:08:25.407 6107-6107/compresor.app.tfg.compresor E/art: 0xaf99b900 SpaceTypeImageSpace begin=0x6fdf7000,end=0x6fe5f5a8,size=417KB,name="/data/dalvik-cache/x86/system@framework@boot-core-libart.art"] 08-14 18:08:25.407 6107-6107/compresor.app.tfg.compresor E/art: 0xaf92f400 imagespace /data/dalvik-cache/x86/system@framework@boot-core-libart.art live-bitmap 1[begin=0x6fdf7000,end=0x6fe5f600] 08-14 18:08:25.407 6107-6107/compresor.app.tfg.compresor E/art: 0xaf92f400 imagespace /data/dalvik-cache/x86/system@framework@boot-core-libart.art live-bitmap 1[begin=0x6fdf7000,end=0x6fe5f600] 08-14 18:08:25.407 6107-6107/compresor.app.tfg.compresor E/art: 0xaf99b940 SpaceTypeImageSpace begin=0x6ff12000,end=0x6ff258f8,size=78KB,name="/data/dalvik-cache/x86/system@framework@boot-conscrypt.art"] 08-14 18:08:25.407 6107-6107/compresor.app.tfg.compresor E/art: 0xaf92f500 imagespace /data/dalvik-cache/x86/system@framework@boot-conscrypt.art live-bitmap 2[begin=0x6ff12000,end=0x6ff25900] 08-14 18:08:25.407 6107-6107/compresor.app.tfg.compresor E/art: 0xaf92f500 imagespace /data/dalvik-cache/x86/system@framework@boot-conscrypt.art live-bitmap 2[begin=0x6ff12000,end=0x6ff25900] 08-14 18:08:25.407 6107-6107/compresor.app.tfg.compresor E/art: 0xaf99ba80 SpaceTypeImageSpace begin=0x6ff3c000,end=0x6ff4b040,size=60KB,name="/data/dalvik-cache/x86/system@framework@boot-okhttp.art"] 08-14 18:08:25.407 6107-6107/compresor.app.tfg.compresor E/art: 0xaf92f640 imagespace /data/dalvik-cache/x86/system@framework@boot-okhttp.art live-bitmap 3[begin=0x6ff3c000,end=0x6ff4b100] 08-14 18:08:25.407 6107-6107/compresor.app.tfg.compresor E/art: 0xaf92f640 imagespace /data/dalvik-cache/x86/system@framework@boot-okhttp.art live-bitmap 3[begin=0x6ff3c000,end=0x6ff4b100] 08-14 18:08:25.407 6107-6107/compresor.app.tfg.compresor E/art: 0xaf99bbc0 SpaceTypeImageSpace begin=0x6ff66000,end=0x6ff66260,size=608B,name="/data/dalvik-cache/x86/system@framework@boot-core-junit.art"] 08-14 18:08:25.407 6107-6107/compresor.app.tfg.compresor E/art: 0xaf92f780 imagespace /data/dalvik-cache/x86/system@framework@boot-core-junit.art live-bitmap 4[begin=0x6ff66000,end=0x6ff66300] 08-14 18:08:25.407 6107-6107/compresor.app.tfg.compresor E/art: 0xaf92f780 imagespace /data/dalvik-cache/x86/system@framework@boot-core-junit.art live-bitmap 4[begin=0x6ff66000,end=0x6ff66300] 08-14 18:08:25.407 6107-6107/compresor.app.tfg.compresor E/art: 0xaf99bd00 SpaceTypeImageSpace begin=0x6ff68000,end=0x6ff81ad0,size=102KB,name="/data/dalvik-cache/x86/system@framework@boot-bouncycastle.art"] 08-14 18:08:25.407 6107-6107/compresor.app.tfg.compresor E/art: 0xaf92fcc0 imagespace /data/dalvik-cache/x86/system@framework@boot-bouncycastle.art live-bitmap 5[begin=0x6ff68000,end=0x6ff81b00] 08-14 18:08:25.407 6107-6107/compresor.app.tfg.compresor E/art: 0xaf92fcc0 imagespace /data/dalvik-cache/x86/system@framework@boot-bouncycastle.art live-bitmap 5[begin=0x6ff68000,end=0x6ff81b00] 08-14 18:08:25.407 6107-6107/compresor.app.tfg.compresor E/art: 0xaf99be40 SpaceTypeImageSpace begin=0x6ffa0000,end=0x6ffb7f58,size=95KB,name="/data/dalvik-cache/x86/system@framework@boot-ext.art"] 08-14 18:08:25.407 6107-6107/compresor.app.tfg.compresor E/art: 0xaf92fdc0 imagespace /data/dalvik-cache/x86/system@framework@boot-ext.art live-bitmap 6[begin=0x6ffa0000,end=0x6ffb8000] 08-14 18:08:25.407 6107-6107/compresor.app.tfg.compresor E/art: 0xaf92fdc0 imagespace /data/dalvik-cache/x86/system@framework@boot-ext.art live-bitmap 6[begin=0x6ffa0000,end=0x6ffb8000] 08-14 18:08:25.407 6107-6107/compresor.app.tfg.compresor E/art: 0xaf99bf80 SpaceTypeImageSpace begin=0x6ffd7000,end=0x702246e0,size=2MB,name="/data/dalvik-cache/x86/system@framework@boot-framework.art"] 08-14 18:08:25.407 6107-6107/compresor.app.tfg.compresor E/art: 0xaf92ff20 imagespace /data/dalvik-cache/x86/system@framework@boot-framework.art live-bitmap 7[begin=0x6ffd7000,end=0x70224700] 08-14 18:08:25.407 6107-6107/compresor.app.tfg.compresor E/art: 0xaf92ff20 imagespace /data/dalvik-cache/x86/system@framework@boot-framework.art live-bitmap 7[begin=0x6ffd7000,end=0x70224700] 08-14 18:08:25.407 6107-6107/compresor.app.tfg.compresor E/art: 0xaf99b7c0 SpaceTypeImageSpace begin=0x7058e000,end=0x705dbed8,size=311KB,name="/data/dalvik-cache/x86/system@framework@boot-telephony-common.art"] 08-14 18:08:25.407 6107-6107/compresor.app.tfg.compresor E/art: 0xaf9fd840 imagespace /data/dalvik-cache/x86/system@framework@boot-telephony-common.art live-bitmap 8[begin=0x7058e000,end=0x705dbf00] 08-14 18:08:25.407 6107-6107/compresor.app.tfg.compresor E/art: 0xaf9fd840 imagespace /data/dalvik-cache/x86/system@framework@boot-telephony-common.art live-bitmap 8[begin=0x7058e000,end=0x705dbf00] 08-14 18:08:25.407 6107-6107/compresor.app.tfg.compresor E/art: 0xaf92d340 SpaceTypeImageSpace begin=0x7060c000,end=0x7060d520,size=5KB,name="/data/dalvik-cache/x86/system@framework@boot-voip-common.art"] 08-14 18:08:25.407 6107-6107/compresor.app.tfg.compresor E/art: 0xaf92f180 imagespace /data/dalvik-cache/x86/system@framework@boot-voip-common.art live-bitmap 9[begin=0x7060c000,end=0x7060d600] 08-14 18:08:25.407 6107-6107/compresor.app.tfg.compresor E/art: 0xaf92f180 imagespace /data/dalvik-cache/x86/system@framework@boot-voip-common.art live-bitmap 9[begin=0x7060c000,end=0x7060d600] 08-14 18:08:25.407 6107-6107/compresor.app.tfg.compresor E/art: 0xaf92d380 SpaceTypeImageSpace begin=0x70612000,end=0x70618850,size=26KB,name="/data/dalvik-cache/x86/system@framework@boot-ims-common.art"] 08-14 18:08:25.407 6107-6107/compresor.app.tfg.compresor E/art: 0xaf9fd9a0 imagespace /data/dalvik-cache/x86/system@framework@boot-ims-common.art live-bitmap 10[begin=0x70612000,end=0x70618900] 08-14 18:08:25.407 6107-6107/compresor.app.tfg.compresor E/art: 0xaf9fd9a0 imagespace /data/dalvik-cache/x86/system@framework@boot-ims-common.art live-bitmap 10[begin=0x70612000,end=0x70618900] 08-14 18:08:25.407 6107-6107/compresor.app.tfg.compresor E/art: 0xaf92d4c0 SpaceTypeImageSpace begin=0x7061d000,end=0x7061d118,size=280B,name="/data/dalvik-cache/x86/system@framework@boot-apache-xml.art"] 08-14 18:08:25.407 6107-6107/compresor.app.tfg.compresor E/art: 0xaf9fdaa0 imagespace /data/dalvik-cache/x86/system@framework@boot-apache-xml.art live-bitmap 11[begin=0x7061d000,end=0x7061d200] 08-14 18:08:25.407 6107-6107/compresor.app.tfg.compresor E/art: 0xaf9fdaa0 imagespace /data/dalvik-cache/x86/system@framework@boot-apache-xml.art live-bitmap 11[begin=0x7061d000,end=0x7061d200] 08-14 18:08:25.407 6107-6107/compresor.app.tfg.compresor E/art: 0xaf92d600 SpaceTypeImageSpace begin=0x70635000,end=0x70644618,size=61KB,name="/data/dalvik-cache/x86/system@framework@boot-org.apache.http.legacy.boot.art"] 08-14 18:08:25.407 6107-6107/compresor.app.tfg.compresor E/art: 0xaf9fdba0 imagespace /data/dalvik-cache/x86/system@framework@boot-org.apache.http.legacy.boot.art live-bitmap 12[begin=0x70635000,end=0x70644700] 08-14 18:08:25.407 6107-6107/compresor.app.tfg.compresor E/art: 0xaf9fdba0 imagespace /data/dalvik-cache/x86/system@framework@boot-org.apache.http.legacy.boot.art live-bitmap 12[begin=0x70635000,end=0x70644700] 08-14 18:08:25.407 6107-6107/compresor.app.tfg.compresor E/art: 0xa5f3bdc0 SpaceTypeZygoteSpace begin=0x747ca000,end=0x748d2000,size=1056KB,name="Zygote space"] 08-14 18:08:25.407 6107-6107/compresor.app.tfg.compresor E/art: 0xaf9fdca0 allocspace zygote / non moving space live-bitmap 0[begin=0x747ca000,end=0x748d2000] 08-14 18:08:25.407 6107-6107/compresor.app.tfg.compresor E/art: 0xaf9fdce0 allocspace zygote / non moving space mark-bitmap 0[begin=0x747ca000,end=0x748d2000] 08-14 18:08:25.407 6107-6107/compresor.app.tfg.compresor E/art: 0xa3f20a80 

The code I run in Java is: 我在Java中运行的代码是:

package compresor.app.tfg.compresor;

   import android.support.v7.app.AppCompatActivity;
   import android.os.Bundle;
   import android.view.View;
   import android.widget.Button;
   import android.widget.TextView;

  public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    Button boton=(Button)findViewById(R.id.button);




    boton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            // Code here executes on main thread after user presses button

            MyNDK myNDK=new MyNDK();
            char[] arguments;
            arguments= new char[]{' '};

            myNDK.compresion(arguments);


        }
    });



}
 }



package compresor.app.tfg.compresor;



 public class MyNDK {

   static {

    System.loadLibrary("ndkmain");
 }

public native void compresion(char[] argv);

     }

The corresponding native code is: 相应的本机代码是:

      #include <jni.h>
      #include<Principal.h>
      #include <compresor_app_tfg_compresor_MyNDK.h>


    JNIEXPORT void JNICALL 
    Java_compresor_app_tfg_compresor_MyNDK_compresion(JNIEnv* env, jobject , 
    jobjectArray jargv){


   //jargv is a Java array of Java strings
    int argc = env->GetArrayLength(jargv);
    typedef char *pchar;
    pchar *argv = new pchar[argc];
    int i;
    for (i = 0; i < argc; i++) {
        jstring js = (jstring) env->GetObjectArrayElement(jargv, i); //A Java string
        const char *pjc = env->GetStringUTFChars(js,NULL); //A pointer to a Java-managed char buffer
        size_t jslen = strlen(pjc);
        argv[i] = new char[jslen + 1]; //Extra char for the terminating null
        strcpy(argv[i], pjc); //Copy to *our* buffer. We could omit that, but IMHO this is cleaner. Also, const correctness.
        env->ReleaseStringUTFChars(js, pjc);
    }

    //Call main

     Principal *pa = Principal::CreateInstance(argc, argv);
     pa->Run();
      pa->FreeInstance();

    //Now free the array
    for (i = 0; i < argc; i++)
        delete[] argv[i];
    delete[] argv;




}

I do not understand where the error comes from but it seems to have something to do with the native code that is not well written and I am writing in a part of the inappropriate memory 我不知道错误是从哪里来的,但似乎与编写得不好的本机代码有关,我正在写不适当的内存的一部分

Thank you in adavance 谢谢你

UPDATE UPDATE

I have modifier the code with Strings as follows: 我用String修改了代码,如下所示:

package compresor.app.tfg.compresor;

   import android.support.v7.app.AppCompatActivity;
   import android.os.Bundle;
   import android.view.View;
   import android.widget.Button;
   import android.widget.TextView;

 public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    Button boton=(Button)findViewById(R.id.button);


    boton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            // Code here executes on main thread after user presses button

            MyNDK myNDK = new MyNDK();
            String[] arguments = new String[]{"-C","-Qt","1"};

            myNDK.compresion(arguments);



        }
    });

        }}

The application quits without giving any error message. 该应用程序退出而没有给出任何错误消息。 The application in C++ works fine, the comprresor generate a file(out.bts) when you give an image, for example image.bmp or image.dng. C ++中的应用程序运行良好,当您提供图像(例如image.bmp或image.dng)时,编译器会生成一个文件(out.bts)。 The parameters on comprresor.exe in C++ are: C ++中的comprresor.exe的参数为:

compressor.exe -C -Qt 1 -i image.bmp -o out.bts -c config.txt -w 512 -h 
512 -b  2.0 -a 0 -Q 0.8 -Xi 0.375 -d 0.5

My Android.mk file looks like: 我的Android.mk文件如下所示:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := ndkmain
LOCAL_SRC_FILES :=ndkmain.cpp CodificadorAritmetico.cpp cuentasim.cpp 
Estima.cpp principal.cpp sb_utils.cpp TBitsContainer.cpp TBitStream.cpp 
TFichero.cpp TFormatTransform.cpp TImg_SLTWFloat.cpp TImgCoder.cpp 
TQMatrix.cpp TTransformada.cpp totales.cpp
LOCAL_CPP_FEATURES += exceptions
LOCAL_LDLIBS := -llog -landroid -lEGL -lGLESv2 -lz -lm
LOCAL_LDFLAGS := -Wl,--allow-multiple-definition
include $(BUILD_SHARED_LIBRARY)

and my Application.mk looks like: 我的Application.mk看起来像:

APP_MODULES:=ndkmain
APP_ABI := all
APP_STL:=stlport_shared

I am not able to see where the error comes from 我无法看到错误的来源

In Java, char[] and String are not synonyms. 在Java中, char []String不是同义词。 Your method is defined as compresion(char[] argv) , and you do pass char array to it. 您的方法定义为compresion(char [] argv) ,您确实将char数组传递给了它。 So, your native code must deal with jchar array, not array of strings: 因此,您的本机代码必须处理jchar数组,而不是字符串数组:

JNIEXPORT void JNICALL 
Java_compresor_app_tfg_compresor_MyNDK_compresion(JNIEnv* env, jobject , 
jcharArray jargv) {

  //jargv is a Java array of characters
  int argc = env->GetArrayLength(jargv);
  jchar *argv = new jchar[argc];
  env->GetCharArrayRegion(jargv, 0, argc, argv); 

Note that jchar is not C char , but rather uint16_t . 请注意, jchar不是C char ,而是uint16_t

But I guess this little snippet is not what you really wanted. 但是我想这不是您真正想要的片段。

Most likely, your intention was to pass an array of Java strings. 您最有可能的意图是传递一组Java字符串。 This means that your Java should look different: 这意味着您的Java应该看起来与众不同:

MyNDK myNDK = new MyNDK();
String[] arguments = new String[]{"1", "2", "3"};

myNDK.compresion(arguments);
…
public native void compresion(String[] argv);

Now, your C++ code should work. 现在, 您的 C ++代码应该可以使用了。

PS few improvement suggestions: PS几点改进建议:

  • If you declare the native method static , you don't need to construct myNDK . 如果将本地方法声明为静态 ,则无需构造myNDK
  • You can use strdup() instead of new char[] + strcpy . 您可以使用strdup()代替new char [] + strcpy
  • You should call env->DeleteLocalRef(js) if argc may be more than just a few. 如果argc可能不止几个,则应调用env-> DeleteLocalRef(js)
  • You should not perform heavy calculations (eg compression) on the UI thread. 您不应该在UI线程上执行繁重的计算(例如压缩)。
  • In English, both 'compression' and 'compressor' spell with double s . 用英语,“ compression”和“ compressor”都用double s拼写。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android(ART)崩溃,错误JNI DETECTED ERROR IN APPLICATION:jarray是无效的堆栈间接引用表或无效的引用 - Android (ART) crash with error JNI DETECTED ERROR IN APPLICATION: jarray is an invalid stack indirect reference table or invalid reference JNI在应用程序中检测到错误:使用已删除的本地引用0x1 - JNI DETECTED ERROR IN APPLICATION: use of deleted local reference 0x1 Brother SDK 调用 PrintImage 导致 JNI DETECTED ERROR IN APPLICATION: GetStringUTFChars received NULL jstring - Brother SDK Calling PrintImage causes JNI DETECTED ERROR IN APPLICATION: GetStringUTFChars received NULL jstring Android JNI 在应用程序中检测到错误:调用 JNI GetMethodID 时出现未决异常 - Android JNI DETECTED ERROR IN APPLICATION: JNI GetMethodID called with pending exception JNI:jstring使应用程序崩溃在android上 - JNI: jstring make the app crash on android 如何调试:应用程序中的JNI检测到错误:使用无效的jobject - How to debug: JNI DETECTED ERROR IN APPLICATION: use of invalid jobject JNI检测到应用程序错误:使用已删除的弱全局引用 - JNI DETECTED ERROR IN APPLICATION: use of deleted weak global reference 原生崩溃:JNI在应用程序中检测到错误:[thread]使用来自[thread]的JNIEnv * - Native Crash: JNI DETECTED ERROR IN APPLICATION: [thread] using JNIEnv* from [thread] JNI在Brother SDK上的应用程序中检测到错误 - JNI DETECTED ERROR IN APPLICATION on Brother SDK JNI 在应用程序中检测到错误:为内部类调用 NewObject 时使用无效的作业 - JNI DETECTED ERROR IN APPLICATION: use of invalid jobject when calling NewObject for innerclass
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM