我发现运行时错误无法实例化应用程序android.support.multidex.MultiDexApplication

时间:2018-07-21 14:30:33

标签: android firebase runtimeexception multidex android-multidex

这是我的错误

  

E / Android运行时:致命异常:主要                     流程:in.tvac.akshayejh.photoblog,PID:5053                     java.lang.RuntimeException:无法实例化应用程序android.support.multidex.MultiDexApplication:java.lang.ClassNotFoundException:在路径:DexPathList [[zip file“ / data / app / in.tvac.akshayejh.photoblog-1 / base.apk

这是我的清单文件

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

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

<application

    android:allowBackup="true"
    android:name="android.support.multidex.MultiDexApplication"
    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=".MainActivity"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".LoginActivity"
        android:screenOrientation="portrait" />
    <activity android:name=".RegisterActivity" />
    <activity android:name=".SetupActivity" />
    <activity
        android:name="com.theartofdev.edmodo.cropper.CropImageActivity"
        android:theme="@style/Base.Theme.AppCompat" />
    <activity
        android:name=".NewPostActivity"
        android:parentActivityName=".MainActivity" />
    <activity android:name=".CommentsActivity"
        android:parentActivityName=".MainActivity"></activity>
</application>
<uses-permission android:name="android.permission.INTERNET" />

这是App gradle文件

    apply plugin: 'com.android.application'

    android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "in.tvac.akshayejh.photoblog"
        minSdkVersion 21
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

    dependencies {
    implementation fileTree(include: ['*.jar'],dir: 'libs' )
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.google.firebase:firebase-auth:11.8.0'
    implementation 'com.google.firebase:firebase-storage:11.8.0'
    implementation 'com.google.firebase:firebase-firestore:11.8.0'
    implementation 'com.android.support:support-v4:27.0.2'
    implementation 'de.hdodenhof:circleimageview:2.2.0'
    implementation 'com.theartofdev.edmodo:android-image-cropper:2.6.+'
    implementation 'com.github.bumptech.glide:glide:4.6.1'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.6.1'
    implementation 'id.zelory:compressor:2.1.0'

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.android.support:cardview-v7:27.1.1'
    implementation 'com.android.support:multidex:1.0.3'
    implementation 'com.google.firebase:firebase-core:16.0.1'
}

    apply plugin: 'com.google.gms.google-services'

这是项目gradle文件

    // Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

    repositories {
        google()
        jcenter()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.3'



        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath 'com.google.gms:google-services:4.0.2'
    }
}

    allprojects {
    repositories {
        google()
        jcenter()
    }
}

    task clean(type: Delete) {
    delete rootProject.buildDir
}

2 个答案:

答案 0 :(得分:1)

如果minSDK为21或更高版本,则不使用Multidex,因为不再使用Dalvik。

有关更多信息,请参见https://developer.android.com/studio/build/multidex

答案 1 :(得分:0)

将其添加到android {}中的build.gradle(:app)

 compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }