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?
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);
}
}
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'
}
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()
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.