Question

I am working on a project that is quickly approaching the 64K method limit for dex files. This Android Developer blog post (from July 2011) explains how to get dynamic class loading working with a command-line build driven by Ant, but does not explore how to get it working from within IDEs (besides saying it won't work within Eclipse).

I looked around and couldn't find anything on getting this system to work from within IntelliJ. Does IntelliJ supports building apps with multiple dex files? If so, how does one set it up?

Was it helpful?

Solution 5

Multidex seems like the best (and fastest) option for addressing the 65K method limit. Google has great documentation on setting up Multidex here.

OTHER TIPS

Try using ProGuard to strip out unused classes and methods from your project and you should (hopefully) find you don't need multiple dex files.

That said if you do: IntelliJ and Eclipse are just IDEs -- they don't directly build your code -- so you will need to identify how your project is being built -- most likely Ant or Gradle.

If your project is a Gradle project then there will be a build.gradle file in the project root -- if this is the case then you will need to look how to accomplish the same with the Android Gradle plugin, a good place to start would be http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Manipulating-tasks.

There are two options:

  1. Break down the existing class. Or
  2. Move out your class to another project and build it as a library (.jar). And as the blog post (mentioned in query) suggest, use their class to load this library (.jar) in your project separately.

Can you provide details about your project?

I recently had same problem after connecting the PlayN library to my project. First I read all posts that you mentioned and related stuff, but eventually I solved the problem by excluding part of the classes from dependant Pythagoras jar (I deleted the pythagoras.d package, which is for "double", since pythagoras.f, "float", was used instead of it in PlayN), which was one of the biggest dependencies in PlayN.

Maybe you can find similar weak place in your project dependencies.

Eclipse can launch external ant scripts but that wont help with tools. Best recommendation is Android Studio and Gradle since all of the commands are run external to the IDE, then port this Ant script http://code.google.com/p/android-custom-class-loading-sample/source/browse/trunk/android-custom-class-loading-sample/build.xml to gradle.

Keep an eye out for some official support along the lines of: https://groups.google.com/forum/#!topic/gradle-android-plugin-users/zG_xUeVaV7s

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top