java - Android (ART) crash with error JNI DETECTED ERROR IN APPLICATION: jstring is an invalid local reference -


i writing android application processes picture(raw format) native c (ndk r15b). im getting 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 run in java is:

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 java array of java strings     int argc = env->getarraylength(jargv);     typedef char *pchar;     pchar *argv = new pchar[argc];     int i;     (i = 0; < argc; i++) {         jstring js = (jstring) env->getobjectarrayelement(jargv, i); //a java string         const char *pjc = env->getstringutfchars(js,null); //a pointer java-managed char buffer         size_t jslen = strlen(pjc);         argv[i] = new char[jslen + 1]; //extra char terminating null         strcpy(argv[i], pjc); //copy *our* buffer. omit that, imho cleaner. also, const correctness.         env->releasestringutfchars(js, pjc);     }      //call main       principal *pa = principal::createinstance(argc, argv);      pa->run();       pa->freeinstance();      //now free array     (i = 0; < argc; i++)         delete[] argv[i];     delete[] argv;     } 

i not understand error comes seems have native code not written , writing in part of inappropriate memory

thank in adavance

update

i have modifier code strings follows:

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 error message. application in c++ works fine, comprresor generate file(out.bts) when give image, example image.bmp or image.dng. parameters on comprresor.exe in c++ are:

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:

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 application.mk looks like:

app_modules:=ndkmain app_abi := app_stl:=stlport_shared 

i not able see error comes from

in java, char[] , string not synonyms. method defined compresion(char[] argv), , pass char array it. so, native code must deal jchar array, not array of strings:

jniexport void jnicall  java_compresor_app_tfg_compresor_myndk_compresion(jnienv* env, jobject ,  jchararray jargv) {    //jargv java array of characters   int argc = env->getarraylength(jargv);   jchar *argv = new jchar[argc];   env->getchararrayregion(jargv, 0, argc, argv);  

note jchar not c char, rather uint16_t.

but guess little snippet not wanted.

most likely, intention pass array of java strings. means java should different:

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.

ps few improvement suggestions:

  • if declare native method static, don't need construct myndk.
  • you can use strdup() instead of new char[] + strcpy.
  • you should call env->deletelocalref(js) if argc may more few.
  • you should not perform heavy calculations (e.g. compression) on ui thread.
  • in english, both 'compression' , 'compressor' spell double s.

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -