26

I'm creating a new android project and decided to use the new AndroidX replacement for the support libraries, docs for which can be found here: https://developer.android.com/jetpack/androidx/migrate.

I followed the steps to the letter and after syncing gradle I have access to the androidx namespace and various classes contained within. However, when creating my application class I want to inherit from androidx.multidex.MultiDexApplication (which can be seen in the table in the link above). However, the entire multidex package doesn't exist.

Has anyone resolved this issue? Any pointers?

Thomas Cook
  • 4,371
  • 2
  • 25
  • 42

5 Answers5

47

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"
Martin Zeitler
  • 1
  • 19
  • 155
  • 216
12

If you are using androidx you should add MultiDexApplication(reference from androidx) to your manifest file.

<application
        android:name="androidx.multidex.MultiDexApplication"
        .....></application>
gokhan
  • 627
  • 1
  • 6
  • 16
2

In addition to Martin Zeitler's answer, I had to add in my gradle build file:

defaultConfig {
  ...
  multiDexEnabled true // Add this line
  ...
}

As well as the dependency

implementation "androidx.multidex:multidex:2.0.0"

As to why it happens, this userguide on Android Developers explains it very well.

Nicolai Lissau
  • 7,298
  • 5
  • 43
  • 57
2
build.gradle app module 

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'
}
Keshav Gera
  • 10,807
  • 1
  • 75
  • 53
1

Ok, figured it out!

Multidex library was never part of android support lib, it was additional library that had to be imported in gradle. So, I've now imported it in my dependencies block in my modules gradle file and set the following in my gradle.properties file:

# Jetifier automatically updates dependancy binaries
# To swap out support lib for androix
android.enableJetifier=true

Now, at compile time, the multidex dependency is swapped out for androidx implementation.

Thomas Cook
  • 4,371
  • 2
  • 25
  • 42