Page 1 of 1

deployment of apk with instrumentation raises Exception

Posted: Mon Dec 15, 2014 4:05 pm
by zivshapirawork
Hi

We are trying to deploy an android apk app with instrumentation checked on in the Ranorex deploy.
The APK is not obfuscated and uses API 10. We also did not install the uninstrumented app. Ranorex 5.2.1

We are getting the error below. Unfortunately we cannot provide the apk but is there a reason for this error?
System.Exception: Failed to recompile the instrumented code. See details for more information: Exception in thread "main" org.jf.util.ExceptionWithContext: Unsigned short value out of range: 66748
at org.jf.dexlib2.writer.DexDataWriter.writeUshort(DexDataWriter.java:116)
at org.jf.dexlib2.writer.InstructionWriter.write(InstructionWriter.java:312)
at org.jf.dexlib2.writer.DexWriter.writeCodeItem(DexWriter.java:980)
at org.jf.dexlib2.writer.DexWriter.writeDebugAndCodeItems(DexWriter.java:759)
at org.jf.dexlib2.writer.DexWriter.writeTo(DexWriter.java:214)
at org.jf.dexlib2.writer.DexWriter.writeTo(DexWriter.java:192)
at brut.androlib.src.SmaliBuilder.build(SmaliBuilder.java:57)
at brut.androlib.src.SmaliBuilder.build(SmaliBuilder.java:41)
at brut.androlib.Androlib.buildSourcesSmali(Androlib.java:358)
at brut.androlib.Androlib.buildSources(Androlib.java:298)
at brut.androlib.Androlib.build(Androlib.java:284)
at brut.androlib.Androlib.build(Androlib.java:258)
at brut.apktool.Main.cmdBuild(Main.java:240)
at brut.apktool.Main.main(Main.java:89)


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)

Re: deployment of apk with instrumentation raises Exception

Posted: Tue Dec 16, 2014 9:03 am
by lucian.teodorescu
Hi,

I didn't see this error until now, but for all the errors I saw, I've found that the complete report is quite useful.
So would you mind to take a look in DexDataWriter.java, line 116 where you called writeUshort? And check if the value might exceed the range of the type (as the error states).

It is good to start with the info at hand.

Best regards,
Lucian

Re: deployment of apk with instrumentation raises Exception

Posted: Wed Dec 17, 2014 7:11 am
by zivshapirawork
Hi Lucian

thank you for the reply. the app (apk) is developed by a partner, we are trying to instrument it with Ranorex (via deployment to a device), and we get the error. It seems to be a Ranorex error and not an error in the app code (this is not a trace of the app code and this the full error text we get).

In any case, we are just deploying via Ranorex (checking on the instrumentation option) and not entering any values.

Can that help in understanding the issue?
Thanks

Re: deployment of apk with instrumentation raises Exception

Posted: Wed Dec 17, 2014 9:02 am
by lucian.teodorescu
Hello,

I wish I were a Ranorex Expert, but I am not.
Let's hope for the best from Support Team or someone more experienced.

Good luck! [fingers crossed :D ]

Lucian.

Re: deployment of apk with instrumentation raises Exception

Posted: Mon Dec 22, 2014 11:27 am
by Support Team
Hi all,

we are already in contact with zivshapirawork regarding the issue by e-mail.
We will analyze it and will give you an update as soon as we have more information.

Regards,
Bernhard

Re: deployment of apk with instrumentation raises Exception

Posted: Thu Jun 25, 2015 6:15 pm
by tvu
Hello Support,

I am getting the same error when I try to instrument our Android application. Did you find a root cause for the issue after you analyzed zivshapirawork's Apk file?

Currently, an uninstrumented Apk can install fine on all of our devices, but this error only occurs when I try to instrument the APK file. I would like to gather as much information as possible before I approach them with this issue.

Thank you,
Tung

Re: deployment of apk with instrumentation raises Exception

Posted: Fri Jun 26, 2015 3:06 pm
by Support Team
Hello Tung,

Unfortunately, this exception comes from the APK tool. We use the APK tool for the instrumentation process with the instrumentation wizard.
Since this is a third-party tool it is hard to fix that issue.

Some other people using this tool had the same issue. The only workaround I can suggest at the moment is instrumenting the APK with source code.
A detailed description how to do so can be found in the section "Instrumentation with Source Code"
on our website.

I hope that helps solving the issue.

Regards,
Bernhard

Re: deployment of apk with instrumentation raises Exception

Posted: Fri Jul 10, 2015 10:38 am
by Support Team
Hello everybody,

I am happy to tell you that we found a possible solution for the issue above.
It is currently just a hidden feature and we are not exactly sure if it works for every APK, but you can try the steps below.
  • For the workaround a Ranorex version > 5.4.0 is required
  • Open the settings dialog in the Ranorex Android APK Instrumentation Wizard
    AndroidInstrumentationSettings.png
  • Add "-static -multidex" to the Instrumentation Flags
    AndroidInstrumentationFlags.png
In most cases the instrumentation should work after doing so.
Please note, at the moment we cannot give you a guarantee, but could already instrument a few APK files successfully.

Regards,
Bernhard

Re: deployment of apk with instrumentation raises Exception

Posted: Fri Jul 10, 2015 10:22 pm
by tvu
If we instrument via command line, can we simply add "-static -multidex" to the command line arguments? Do we have to add a flag like we do in the case to disable web testing like so:"/EnableWebTesting=False"?

Thanks,
Tung

Re: deployment of apk with instrumentation raises Exception

Posted: Mon Jul 13, 2015 6:36 am
by zivshapirawork
I will check the Studio option, but we deploy via code. How can this feature (adding flags) be used via the deploy method?

Host.Local.InstrumentAndDeployAndroidApp

thanks
ziv

Re: deployment of apk with instrumentation raises Exception

Posted: Tue Jul 14, 2015 4:36 pm
by Support Team
Hello all,

both should be possible.

Instrumentation using command line:
C:\Program Files (x86)\Ranorex 5.4\Bin>Ranorex.Instrumentation.exe /p:android /d:"YourDevice" /a:"T:\usr\TEST.apk" /dm:WiFi /InstrumentationFlags:"-static -multidex"

Instrumentation in user code:
InstrumentApkOptions o = new InstrumentApkOptions();
o.InstrumentationFlags = "-static -multidex";
 
Host.Local.InstrumentAndDeployAndroidApp(DeviceName, APKPath, true, Host.DeploymentModes.Usb, 1800000, o);
I hope that works for you.

Regards,
Bernhard

Re: deployment of apk with instrumentation raises Exception

Posted: Tue Jul 21, 2015 9:23 am
by zivshapirawork
Kudos to the team for fixing this :D

I instrumented my multidex apk via the Ranorex studio 5.4.0 and it is working now.
Via user code it fails on timeout and I reported this issue separately.

I hope this helps others.

Re: deployment of apk with instrumentation raises Exception

Posted: Fri Aug 25, 2017 1:25 pm
by thilina
Support Team wrote:Hello all,

both should be possible.

Instrumentation using command line:
C:\Program Files (x86)\Ranorex 5.4\Bin>Ranorex.Instrumentation.exe /p:android /d:"YourDevice" /a:"T:\usr\TEST.apk" /dm:WiFi /InstrumentationFlags:"-static -multidex"

Instrumentation in user code:
InstrumentApkOptions o = new InstrumentApkOptions();
o.InstrumentationFlags = "-static -multidex";
 
Host.Local.InstrumentAndDeployAndroidApp(DeviceName, APKPath, true, Host.DeploymentModes.Usb, 1800000, o);
I hope that works for you.

Regards,
Bernhard
but this command fails in powershell. can you please help ?
i'm using PS script to install apk to device

Re: deployment of apk with instrumentation raises Exception

Posted: Fri Aug 25, 2017 1:54 pm
by thilina
Found the issue
.\Ranorex.Instrumentation.exe /p:"android" /a:"app-dev.apk" /d:"MyDevice" /skip:False /deploymode:Usb /InstrumentationFlags:'"'-static -multidex'"' /EnableWebTesting:True /TreeSimplification:True /FullImageComparison:True /deploytimeout:0 /instrumenttimeout:0
' " ' need to enclose single-quote