Cannot instrument .apk - Error displays

Mobile Testing, Android App Testing.
Posts: 7
Joined: Fri Jun 12, 2020 1:10 am

Cannot instrument .apk - Error displays

Post by grekha » Thu Jun 18, 2020 4:16 am

I am facing instrumentation error I have tried all ways forum suggested adding -multidex -nores -smali redist but no luck .This process is show stopper for testing further .Can someone please help me instrumenting apk file. Thank you !

I’m using ranaorex 7.1 version ,ranorex 2.0.1
Android version is 8.10

Also please suggest any settings i have to do.

Here is the Log error as below...

System.Exception: Failed to recompile the instrumented code. See details for more information: Exception in thread "main" org.jf.util.ExceptionWithContext: Exception occurred while writing code_item for method Landroid/support/v4/util/LongSparseArray;->clone()Landroid/support/v4/util/LongSparseArray;

at org.jf.dexlib2.writer.DexWriter.writeDebugAndCodeItems(

at org.jf.dexlib2.writer.DexWriter.writeTo(

at org.jf.dexlib2.writer.DexWriter.writeTo(



at brut.androlib.Androlib.buildSourcesSmali(

at brut.androlib.Androlib.buildSources(



at brut.apktool.Main.cmdBuild(

at brut.apktool.Main.main(

Caused by: org.jf.util.ExceptionWithContext: Error while writing instruction at code offset 0x13

at org.jf.dexlib2.writer.DexWriter.writeCodeItem(

at org.jf.dexlib2.writer.DexWriter.writeDebugAndCodeItems(

... 10 more

Caused by: org.jf.util.ExceptionWithContext: Unsigned short value out of range: 65554

at org.jf.dexlib2.writer.DexDataWriter.writeUshort(

at org.jf.dexlib2.writer.InstructionWriter.write(

at org.jf.dexlib2.writer.DexWriter.writeCodeItem(

... 11 more

at Ranorex.Plugin.Mobile.Tools.Android.Instrumentation.ApkFileInstrumenter.CompileApkFile(String sourceApkFilePath, IPathService pathService)

at Ranorex.Plugin.Mobile.Utils.BackgroundWorkerSupported.ExecuteBgwCode[TArg0,TArg1](BgwDelegate`2 methodDelegate, Int32 doneProgress, String progressText, TArg0 arg0, TArg1 arg1, BackgroundWorker bgw)

at Ranorex.Plugin.Mobile.Tools.Android.Instrumentation.ApkFileInstrumenter.Instrument(String apkFilePath, Int32 port, InstrumentApkOptions deployOptions, BackgroundWorker bgw)

at Ranorex.Controls.Instrumentation.Workers.AndroidWorker.Run()

at Ranorex.Controls.AndroidInstrumentProgressPage.bgw_DoWork(Object sender, DoWorkEventArgs e)

User avatar
Ranorex Guru
Ranorex Guru
Posts: 7464
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Cannot instrument .apk - Error displays

Post by odklizec » Thu Jun 18, 2020 8:03 am


I'm afraid, Ranorex 7.1 is way too old, obsolete and no longer supported. The obvious thing you should try, is to update Ranorex with most recent 9.3.2 and try it again (even in trial mode). If 9.3.2 is able to instrument your app, you have your answer. If you cannot update to most recent Ranorex version, your only hope is to search old posts, regarding instrumentation of Android apps, and try all the suggestions you may eventually find.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration