-2

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)
        >
halfer
  • 19,824
  • 17
  • 99
  • 186

2 Answers2

0

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

Kartik
  • 709
  • 1
  • 9
  • 21
0

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
Harsh Jatinder
  • 833
  • 9
  • 15
  • hi is it not possible to do it with implementation 'com.android.support:support-v4:28.0.0'? as the course im using , my instructor uses the same version. and i havent migrated to androidx. – Gayatri Anushka Feb 18 '20 at 07:27
  • this `androidx.appcompat:appcompat:1.0.2` entry in your gradle indicates that your project is already in androidX. So older support versions will cause conflicts. Don't worry there won't be any issue if you use androidX version, it is more stable and conflict free. – Harsh Jatinder Feb 18 '20 at 07:39
  • Also, if this solves your problem, please approve the answer. – Harsh Jatinder Feb 18 '20 at 07:41
  • sir so even if i follow a course that uses 'com.android.support:support-v4:28.0.0, instead of adding this, i can add the androidx library and it will be fine? – Gayatri Anushka Feb 18 '20 at 07:49
  • thankyou sir now no errors as I changed multidex androidx version. i even updated androidx.appcompat:appcompat:1.0.2 to 1.2.0 hope thats okay? and is there any way you could help with my project sir. – Gayatri Anushka Feb 18 '20 at 08:14