4

I've been trying to run Java applications on android devices as standalone jars (not as apk's). Everything went fine in the beginning: I used the dex compiler from the Android SDK, packed the dex file into a jar, pushed it to the device and used a shell script (similar to the example in the link) to run it.

When I included more libraries and hit the 65K dex function limit, I used the --multi-dex flag with the dex compiler. The compilation succeeded, and I was also able to run my code on a Lollipop device. However, running the exact same jar on Kitkat gets the following run-time exception:

java.lang.VerifyError: scala/None$
    at akka.actor.ActorSystem$.<init>(ActorSystem.scala:30)
    at akka.actor.ActorSystem$.<clinit>(ActorSystem.scala)
    at akka.actor.ActorSystem.create(ActorSystem.scala)
    at com.example.MyClass.calculate(MyClass.java:185)
    at com.example.Main.main(Main.java:16)
    at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
    at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:243)
    at dalvik.system.NativeStart.main(Native Method)

I faced the exact same problem when I tried running the same code as an apk, and solved it by adding a line to the Android Manifest:

android:name="android.support.multidex.MultiDexApplication"

This obviously isn't possible in the current situation, since I don't have manifest file.

How can I still enable the multidex support for my standalone jar? Should I add libraries to the compilation? Should I run the jar differently?

Thanks.

nozik
  • 307
  • 1
  • 12
  • The big difference between 4.4 and 5.0 you are seeing here is probably the switch from the DVM, where this requires tricky glue, to ART where multiple dex files can be loaded in vm. I believe ART was available as a runtime option on 4.4 to permit developers to test against it, so perhaps you can spin up an instance of that rather than a DVM? You might also see if you can prune unused methods with more aggressive configuration of something like proguard, if you have not already done so. – Chris Stratton Apr 22 '15 at 16:26
  • Spinning up ART is looking non-trivial. To go with the multidex approach, did you build with a sufficiently low minSDKVersion so that the fully decisioning of what goes where is applied? Is there possibly a path of building your code into an apk, then ripping the various dex files back out of it? – Chris Stratton Apr 22 '15 at 16:50
  • Thanks for the suggestions @ChrisStratton. I can't switch the runtime to ART since I need to interact with some other code that currently doesn't work on ART. About your suggestion of first building as an apk, if I understand you correctly, I will need to manually check which classes were inserted to each dex file, and use the dex file that I need. Sounds too patchy to work... – nozik Apr 23 '15 at 21:23

0 Answers0