解析失败:multidex-instrumentation

Failed to resolve: multidex-instrumentation

在实施 multidex 时,每当我同步我的项目时都会遇到以下错误。

Failed to resolve: multidex-instrumentation

I used these instructions to set it up.

这是相关的应用级别build.gradle:

android {
    compileSdkVersion 28

    defaultConfig {
        applicationId "xxx.xyz.zzz"
        minSdkVersion 16
        targetSdkVersion 22
        multiDexEnabled true
        versionCode 1
        versionName "1.0"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
    }
}
dependencies {
    compile 'com.android.support:multidex:1.0.3'
    ....and the rest
}

以及相关的项目级别build.gradle:

buildscript {
    repositories {
        google()
        jcenter()
        maven { url 'https://maven.fabric.io/public' }
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'
        classpath 'com.google.gms:google-services:3.1.2'
        classpath 'io.fabric.tools:gradle:1.+'
    }
}

allprojects {
    repositories {
        mavenLocal()
        mavenCentral()
        jcenter()
        maven {
            url "$rootDir/../node_modules/react-native/android"
        }
        google()
    }
}

我在这里错过了什么?

在 gradle 文件中添加以下依赖项并检查。我遇到了同样的问题,通过添加它解决了这个问题。

androidTestImplementation 'com.android.support:multidex-instrumentation:1.0.3'

React-native + rnn v2 遇到了同样的问题解决方案:如果你的 minSdkVersion 设置为 21 或更高,你需要做的就是在你的模块级 build.gradle 文件中将 multiDexEnabled 设置为 true,如下所示:

android { 
    defaultConfig {
        // ... 
        minSdkVersion 21 
        targetSdkVersion 28 
        multiDexEnabled true } 
        // ... 
    }
    // ...
}

但是,如果您的 minSdkVersion 设置为 20 或更低,那么您必须使用 multidex 支持库,如下所示:然后按照此处的官方说明进行操作 https://developer.android.com/studio/build/multidex

通过在项目 build.gradle 文件

的所有项目存储库中的 google 的 Maven 存储库之后移动 google() 为我解决了
allprojects {
repositories {
    jcenter()
    maven { url "https://jitpack.io" }
    maven{url "https://maven.google.com"}
    google()
 }
}