Android Studio Failed to resolve: multidex Open File

浪尽此生 提交于 2019-12-13 12:52:06

问题


Failed to resolve: multidex Open File

I found this error when I sync my project.

apply plugin: 'com.android.library'

android {
    compileSdkVersion rootProject.compileSdkVersion
    buildToolsVersion rootProject.buildToolsVersion

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion rootProject.targetSdkVersion
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    def system_dependencies = rootProject.ext.system_dependencies
    compile system_dependencies.appcompat_v7
    testCompile 'junit:junit:4.12'
}

I add this, but it dose not work;

maven {
    url 'https://maven.google.com'
}

I try many ways.How to solve it?


回答1:


Try this code

 defaultConfig {
        applicationId "com.test"
        minSdkVersion 17
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        // Enabling multidex support.
        multiDexEnabled true
    }

 dependencies {
     //Multidex support for devices prior to lollipop
     implementation 'com.android.support:multidex:1.0.1'
 }

Application class

package appUtils;

import android.app.Application;
import android.content.Context;
import android.os.Build;
import android.support.multidex.MultiDex;



public class App extends Application {
    @Override
    public void onCreate() {
        super.onCreate();

    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) MultiDex.install(this);
    }
}



回答2:


Add dependency for Multidex support prior to Android 5.0. As your minSdkVersion 16 so you have to add dependency to enable multidex.

dependencies {
  implementation 'com.android.support:multidex:1.0.3'
}



回答3:


In the project build.gradle

    allprojects {
    repositories {
        /**
         * This must be at the top.
         */
        maven {
            url 'https://maven.google.com'
        }
        // Others 
        maven { url "..." }
        jcenter()
        mavenCentral()
        google()
    }
   }


来源:https://stackoverflow.com/questions/53038570/android-studio-failed-to-resolve-multidex-open-file

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