Running apps containing large amount of code

1.1k views Asked by At

Background

It seems some old Android OSs (and maybe even the newest ones) have a limitation on the amount of code each app can hold.

As I've found, the limitation is on a buffer called "LinearAlloc" .

On 2.2 or 2.3 it's about 5-8 MB , and I think it's 16 or more on others.

The problem

If you have a too large code (and apps can reach this state), you won't be able to install the app at all on older devices, getting the next error (also reported here) :

Installation error: INSTALL_FAILED_DEXOPT
Please check logcat output for more details.
Launch canceled!

What I've found

One solution is to just remove as much code and libraries as possible, but on some huge projects such a thing is very hard to do.

I've found the next links talking about how Facebook solved this, by somehow increasing the limit:

Also, Google has posted how to solve it by loading code dynamically :

http://android-developers.blogspot.co.il/2011/07/custom-class-loading-in-dalvik.html

The question

How did Facebook do it?

Is it possible to overcome this in other ways too?

Is there any free library that increases/removes the limitation of this buffer?

What is the limitation on newer Android versions, if there is any?

How do other huge apps (and games) handle this issue? Do they put their code into C/C++?

Would loading the dex files dynamically solve this?

2

There are 2 answers

4
android developer On

There is a new solution, made by Google:

It seems all you have to do is any of the next things: - extend from "MultiDexApplication" instead of from "Application" - call MultiDex.install(context) in your application's attachBaseContext

But now I wonder:

  1. Is that really it?
  2. Does it have any issues ? Does it affect performance?
  3. How does it work?
  4. What should be done with ContentProvider, as it's getting called before Application gets initialized?
  5. The post says "gives you MultiDex support on all API 4+ devices (well, until v21, where you get this natively)" . Does it mean that from v21 it will be the default behavior, or just that the class will be built in and you won't need to use the support library's class ?
  6. Will this solution work on Eclipse too?
1
rtsai2000 On

The limit is the total number of method references:

A middle ground between doing nothing and the multi-dex approach described in the FB/Google articles is to use a tool like ProGuard to remove references to unused code at the Java level. See: