【问题标题】:i found runtime error Unable to instantiate application android.support.multidex.MultiDexApplication我发现运行时错误无法实例化应用程序 android.support.multidex.MultiDexApplication
【发布时间】:2018-07-21 14:30:32
【问题描述】:

这是我的错误

E/AndroidRuntime: 致命异常: main 进程:in.tvac.akshayejh.photoblog,PID:5053 java.lang.RuntimeException:无法实例化应用程序 android.support.multidex.MultiDexApplication:java.lang.ClassNotFoundException:在路径上找不到类“android.support.multidex.MultiDexApplication”:DexPathList [[zip 文件“/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
}

【问题讨论】:

    标签: android firebase runtimeexception android-multidex


    【解决方案1】:

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

    请参阅https://developer.android.com/studio/build/multidex 了解更多信息。

    【讨论】:

    • 那么我该如何实现multidex
    • 不要使用它,像普通的 apk 一样使用。 Android 将自行管理对 64k+ 内存的需求。查看链接...
    【解决方案2】:

    将此添加到 android { }

    中的 build.gradle(:app)
     compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_8
            targetCompatibility JavaVersion.VERSION_1_8
        }
    

    【讨论】:

      猜你喜欢
      • 2018-05-26
      • 2017-10-07
      • 2022-09-29
      • 1970-01-01
      • 1970-01-01
      • 2021-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多