deployment of apk with instrumentation raises Exception

Mobile Testing, Android App Testing.
zivshapirawork
Posts: 62
Joined: Wed Sep 24, 2014 7:47 am
Location: Israel

deployment of apk with instrumentation raises Exception

Post by zivshapirawork » Mon Dec 15, 2014 4:05 pm

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)

lucian.teodorescu
Posts: 82
Joined: Fri Oct 24, 2014 10:58 am
Location: Bucharest

Re: deployment of apk with instrumentation raises Exception

Post by lucian.teodorescu » Tue Dec 16, 2014 9:03 am

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
Lucian Teodorescu
NetSun Software

zivshapirawork
Posts: 62
Joined: Wed Sep 24, 2014 7:47 am
Location: Israel

Re: deployment of apk with instrumentation raises Exception

Post by zivshapirawork » Wed Dec 17, 2014 7:11 am

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

lucian.teodorescu
Posts: 82
Joined: Fri Oct 24, 2014 10:58 am
Location: Bucharest

Re: deployment of apk with instrumentation raises Exception

Post by lucian.teodorescu » Wed Dec 17, 2014 9:02 am

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.
Lucian Teodorescu
NetSun Software

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: deployment of apk with instrumentation raises Exception

Post by Support Team » Mon Dec 22, 2014 11:27 am

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
.
Image

tvu
Posts: 195
Joined: Tue Apr 07, 2015 10:47 pm

Re: deployment of apk with instrumentation raises Exception

Post by tvu » Thu Jun 25, 2015 6:15 pm

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

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: deployment of apk with instrumentation raises Exception

Post by Support Team » Fri Jun 26, 2015 3:06 pm

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
.
Image

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: deployment of apk with instrumentation raises Exception

Post by Support Team » Fri Jul 10, 2015 10:38 am

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
    AndroidInstrumentationSettings.png (15.83 KiB) Viewed 3620 times
  • Add "-static -multidex" to the Instrumentation Flags
    AndroidInstrumentationFlags.png
    AndroidInstrumentationFlags.png (14.41 KiB) Viewed 3620 times
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
.
Image

tvu
Posts: 195
Joined: Tue Apr 07, 2015 10:47 pm

Re: deployment of apk with instrumentation raises Exception

Post by tvu » Fri Jul 10, 2015 10:22 pm

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

zivshapirawork
Posts: 62
Joined: Wed Sep 24, 2014 7:47 am
Location: Israel

Re: deployment of apk with instrumentation raises Exception

Post by zivshapirawork » Mon Jul 13, 2015 6:36 am

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

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: deployment of apk with instrumentation raises Exception

Post by Support Team » Tue Jul 14, 2015 4:36 pm

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
.
Image

zivshapirawork
Posts: 62
Joined: Wed Sep 24, 2014 7:47 am
Location: Israel

Re: deployment of apk with instrumentation raises Exception

Post by zivshapirawork » Tue Jul 21, 2015 9:23 am

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.

thilina
Posts: 28
Joined: Wed Sep 03, 2014 12:32 pm

Re: deployment of apk with instrumentation raises Exception

Post by thilina » Fri Aug 25, 2017 1:25 pm

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

thilina
Posts: 28
Joined: Wed Sep 03, 2014 12:32 pm

Re: deployment of apk with instrumentation raises Exception

Post by thilina » Fri Aug 25, 2017 1:54 pm

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