Home » Android » android – My multidex is not resolving (it is still red)-Exceptionshub

android – My multidex is not resolving (it is still red)-Exceptionshub

Posted by: admin February 26, 2020 Leave a comment

Questions:

My android.support.multidex.MultiDexApplication is still red after all the steps. I am not able to resolve this. I’m following a course online but can’t find the answer. Can I omit multidex?

android {
    compileSdkVersion 28
    buildToolsVersion "29.0.2"
    defaultConfig {
        applicationId "com.example.ping"
        minSdkVersion 21
        targetSdkVersion 28
        multiDexEnabled true
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.core:core-ktx:1.0.2'

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

    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

    implementation 'com.android.support:multidex:1.0.3'
    implementation 'com.google.firebase:firebase-analytics:17.2.2'
    implementation 'com.google.firebase:firebase-auth:19.2.0'
    implementation 'com.google.firebase:firebase-firestore:21.4.0'
    implementation 'com.google.firebase:firebase-storage:19.1.1'

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}
apply plugin: 'com.google.gms.google-services'

Manifest:

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.ping">

    <application
        android:name="android.support.multidex.MultiDexApplication"
          (this part is showing error)
        >
How to&Answers:

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

Answer:

You need to have an application class that extends MultiDexApplication

You need to have this dependency for AndroidX

implementation 'androidx.multidex:multidex:2.0.1'

Or for the normal support library

implementation 'com.android.support:multidex:1.0.3'

Below is the code if you want it in Kotlin

class YourAppName : MultiDexApplication()

Or for Java

class YourAppName extends MultiDexApplication

And in your manifest file in the application tag

android:name:".YourAppName"

If you’re thinking why to have an application class here is some reading you can do

https://stackoverflow.com/a/33315717/10752944