Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Multidex support #344

Closed
rosen-vladimirov opened this issue Jan 27, 2016 · 6 comments
Closed

Enable Multidex support #344

rosen-vladimirov opened this issue Jan 27, 2016 · 6 comments
Labels

Comments

@rosen-vladimirov
Copy link
Contributor

The problem

In case the application is using a lot of plugins and compile dependencies, the dexing may fail with

Output: UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536 at ...

It turns out this is Android limitation:

Android application (APK) files contain executable bytecode files in 
the form of Dalvik Executable (DEX) files, 
which contain the compiled code used to run your app. 
The Dalvik Executable specification limits the total number 
of methods that can be referenced within a single DEX file to 65,536, 
including Android framework methods, 
library methods, and methods in your own code.

Android way to fix this

In order to overcome this limitation, here's the official guide how to support multidexing:
https://developer.android.com/tools/building/multidex.html
The idea is to add the following to build.gradle:

android {
    defaultConfig {
        // Enabling multidex support.
        multiDexEnabled true
    }
}

dependencies {
  compile 'com.android.support:multidex:1.0.0'
}

Also some changes must be applied in AndoridManifest.xml OR our own NativeScriptApplication class:

  • modifying default AndroidManifest.xml requires changing the application name:
 <application
        ...
        android:name="android.support.multidex.MultiDexApplication">
        ...
    </application>
  • modifying NativeScriptApplication - in attachBaseContext() method call
MultiDex.install(this);

Possible way to handle this

Maybe NativeScript CLI can pass some flag to build.gradle and based on it we can enable multidexing and call MultiDex.install(this);

@rosen-vladimirov
Copy link
Contributor Author

The issue has really high priority as the following steps lead to dex errors:

  • $ tns create myApp
  • $ cd myApp
  • $ tns plugin add nativescript-push-notifications
  • $ tns plugin add nativescript-telerik-ui
  • $ tns build android

As we are expecting the customers to use these two plugins a lot, can we raise the priority of this issue. Is there a workaround?

@rosen-vladimirov
Copy link
Contributor Author

Ok, the problem is caused by the google play services compile dependency. The workaround is to compile only part of it (this should be done in the plugins that add this dependency).
More information can be found in this article
https://developers.google.com/android/guides/setup#split

@dapriett
Copy link

dapriett commented Feb 3, 2016

There is an issue with my nativescript-google-maps-sdk - not sure if it's related dapriett/nativescript-google-maps-sdk#7

The map shows up blank on Android 4.2.2, only thing odd I seem to find in the Android logs are messages like this:

02-02 10:13:32.381: E/dalvikvm(3390): Could not find class 'android.app.AppOpsManager', referenced from method com.google.android.gms.common.zze.zzb
02-02 10:13:32.393: E/dalvikvm(3390): Could not find class 'android.app.AppOpsManager', referenced from method com.google.android.gms.common.nb.a
02-02 10:13:32.429: E/dalvikvm(3390): Could not find class 'android.app.AppOpsManager', referenced from method com.google.android.gms.common.mw.a

The plugin already limits the dependencies to only com.google.android.gms:play-services-maps within google play services. Wondering if multidex will resolve this.

@Plamen5kov
Copy link
Contributor

This feature will be enabled for use in android-runtime 2.0, because you will be able not only the AndroidManifest.xml, and the build.gradle but the onCreate logic.
If you want to use multidex you need to follow the steps described in the issue description.

@dapriett
Copy link

How could I test this out with dapriett/nativescript-google-maps-sdk#7 ? Any examples with multidex support?

@Plamen5kov
Copy link
Contributor

Plamen5kov commented Apr 27, 2016

@dapriett not yet, but i'll write an article or documentation, that explains all possibilities that come thanks to the static binding generator and how to utilize them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants