Android Support Multidex Library Implementation

Android support multidex library implementation

The Blog was the old solution.

With Android Studio 0.9.2 & Gradle Plugin 0.14.1, you only need to:

  1. Add to AndroidManifest.xml:

.

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

or

Add

MultiDex.install(this);

in your custom Application's attachBaseContext method

or your custom Application extend MultiDexApplication


  1. add multiDexEnabled = true in your build.gradle

.

android {
defaultConfig {
...
multiDexEnabled = true
}
}

Done.

Sorry for my poor English

Related Resources:

http://developer.android.com/tools/building/multidex.html

https://plus.google.com/+XavierDucrohet/posts/1FnzwdcBnyC

How to enable multidexing with the new Android Multidex support library

Edit:

Android 5.0 (API level 21) and higher uses ART which supports multidexing. Therefore, if your minSdkVersion is 21 or higher, the multidex support library is not needed.


Modify your build.gradle:

android {
compileSdkVersion 22
buildToolsVersion "23.0.0"

defaultConfig {
minSdkVersion 14 //lower than 14 doesn't support multidex
targetSdkVersion 22

// Enabling multidex support.
multiDexEnabled true
}
}

dependencies {
implementation 'com.android.support:multidex:1.0.3'
}

If you are running unit tests, you will want to include this in your Application class:

public class YouApplication extends Application {

@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}

}

Or just make your application class extend MultiDexApplication

public class Application extends MultiDexApplication {

}

For more info, this is a good guide.

AndroidX MultiDex not found

android.enableJetifier=true does not make the least sense, while being able to replace it.

you can simply add it as a dependency, without non-transparent mangling of name-spaces:

implementation "androidx.multidex:multidex:2.0.1"

My multidex is not resolving (it is still red)

You're mixing androidX with Support libraries.

You should replace:

implementation 'com.android.support:support-v4:28.0.0'

with

implementation 'androidx.multidex:multidex:2.0.1'

and replace

android.support.multidex.MultiDexApplication

with

androidx.multidex.MultiDexApplication

Android support Multidex still generates the 'over than 64K methods in main-dex file' error

According to documentation you must have in your multidex-config the classes you want to keep.

Analyze your APK and check for the classes and methods there are included on the main dex file and check the packages that are contributing the reach the 64K limit.

Make sure you are not keeping your entire project on the multidex-config file.

The example given in the documentation can be misleading if you use a broad package filter:

-keep class com.example.** { *; }

Try to keep only necessary packages:

-keep class com.example.YOUR-PACKAGE** { *; }

androidx and support dependency causing multidex error

Use the Following Command to check which dependency has duplicate class

./gradlew app:dependencies

Then Exclude the module like this

{
exclude group: 'com.android.support'
}

Hope this will solve your problem!
Let me know if you have any issues!

Adding MultiDex to a project in android studio but keeping getting java.lang.NoClassDefFoundError

You want to create a Base class that extends the MultiDex if you don't have one.

public class BaseApp extends MultiDexApplication {

@Override
public void onCreate() {
super.onCreate();
}

}

Your Manifest can look like below:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.finalyearprojectapp">

<uses-permission android:name="android.permission.INTERNET" />

<application
android:name=".BaseApp"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">

<activity android:name=".MainScreen" />
<activity android:name=".RegisterActivity" />
<activity android:name=".LoginActivity" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>

Edit:
You should upgrade your firebase to the latest, or at least version from 17.0.0 and above.
I was told that According to firebase release notes May 07, 2019, it says; "If you use Firebase Authentication, update to firebase-auth v17.0.0 or later to ensure functionality alignment with other updated Firebase libraries."

Android Studio Failed to resolve: multidex Open File

In the project build.gradle

    allprojects {
repositories {
/**
* This must be at the top.
*/
maven {
url 'https://maven.google.com'
}
// Others
maven { url "..." }
jcenter()
mavenCentral()
google()
}
}


Related Topics



Leave a reply



Submit