Error multiDex when updating Android Studio

孤街醉人 提交于 2020-01-16 00:44:20

问题


when i updating my android studio to 3.1.2 i got this error :

java.lang.RuntimeException: Unable to get provider com.google.firebase.provider.FirebaseInitProvider: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.provider.FirebaseInitProvider" on path: DexPathList

build.gradle

android {
compileSdkVersion 26
buildToolsVersion '27.0.3'
defaultConfig {
    applicationId "com.example"
    minSdkVersion 19
    targetSdkVersion 26
    versionCode 1
    versionName "1.0.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    useLibrary 'org.apache.http.legacy'
    multiDexEnabled true
    vectorDrawables.useSupportLibrary = true
}
buildTypes {
    release {
        debuggable false
        minifyEnabled true
        shrinkResources true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

    }
    debug {
        debuggable true
        minifyEnabled true
        shrinkResources true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

    }
}
dexOptions {
    javaMaxHeapSize "8g"
}
packagingOptions {
    exclude 'META-INF/DEPENDENCIES.txt'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/notice.txt'
    exclude 'META-INF/license.txt'
    exclude 'META-INF/dependencies.txt'
    exclude 'META-INF/LGPL2.1'
}
productFlavors {
}
}
dependencies {
     compile 'com.android.support:multidex:1.0.3'
}

manifest

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme"
    android:name="com.example.ApplicationManager">

    <activity android:name=".MainActivity"
        android:windowSoftInputMode="adjustResize"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

And com.example.ApplicationManager

public class ApplicationManager extends Application {

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

回答1:


try this code.

public class ApplicationManager extends MultiDexApplication{

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



回答2:


You have used application class in extend: Use below class in extends application class:

public class ApplicationManager extends MultiDexApplication {

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

and also put this line in application class in manifest:

android:allowBackup="false"
android:hardwareAccelerated="true"
android:icon="@drawable/app_icon_new"
android:label="@string/app_name"
android:largeHeap="true"
android:theme="@style/AppTheme"


来源:https://stackoverflow.com/questions/49996644/error-multidex-when-updating-android-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!