Using Art instead of Dalvik to compile

1.5k views Asked by At

I'm using Eclipse and I have a new project using android version 21 (5.0). I want to compile it using Art instead of Dalvik. What I have to do to achieve that?

Edit : The reason of the question is that I have this problem:

[2014-11-12 10:30:49 - Dex Loader] Unable to execute dex: method ID not in [0, 0xffff]: 65536
[2014-11-12 10:30:49 - MAMUT] Conversion to Dalvik format failed: Unable to execute dex: method ID not in [0, 0xffff]: 65536

I expected than doing that I solve the problem:

Of particular note is the suggestion of making a minSdkVersion 21 dev build - this allows you to generate multi-dex output incrementally in the new ART format, making for a much faster development iteration cycle (at least on Android 5.0 devices).

Thanks

3

There are 3 answers

2
zapl On BEST ANSWER

Of particular note is the suggestion of making a minSdkVersion 21 dev build - this allows you to generate multi-dex output incrementally in the new ART format, making for a much faster development iteration cycle (at least on Android 5.0 devices).

That's wrong and should read roughly

Of particular note is the suggestion of using Android Build Tools 21.1 and higher together with the Multidex Support Library - this allows you to use multiple dex files in the dex format which hasn't changed at all, making for unchanged development.

The problem of the dex format is that it can't contain more than 65536 methods. The solution is to simpliy split the output into multiple dex files. There are 2 problems we had in the past

  • the dx tool was not capable to produce multiple dex files
  • it's very complicated to use multiple dex files on a device since devices load only 1 dex file and the code in the other ones has to be loaded somehow manually.

Build tools 21 solve the first problem, you can simply generate multiple dex files by just adding the -multi-dex flag to the compile options.

The multidex support library solves the second problem. It tells those devices how to load additional dex files. And the ART runtime on Lollipop and above (4.4 had ART too but can't do the same) is capable of using multiple files without being told how to do so.

Also relevant is the official Building Apps with Over 65K Methods document.

3
Blackbelt On
I want to compile it using Art instead of Dalvik. 

Art and Dalvik are not compiler, they are virtual machine. They executed the bytecode generated by the compiler (your application)

0
Sayem On

Just you need an emulator or real device which is running ART.

Check this: https://developer.android.com/guide/practices/verifying-apps-art.html