无法更新到com.google.gms:google-services:4.2.0

时间:2019-01-30 13:12:44

标签: android firebase android-studio gradle google-play-services

开始时,google-services ver。是field.getValue().getPdfObject().get(PdfName.TU) ,但是当我将其更改为classpath 'com.google.gms:google-services:4.1.0'时,会在4.2.0

期间发生错误

我的最高级别:

Sync Project with Gradle files

我的app / build.gradle文件:

 // Top-level build file

apply plugin: 'kotlin'

buildscript {
    ext.kotlin_version = '1.3.20'
    repositories {
        google()
        jcenter()
        maven { url 'https://maven.fabric.io/public' }

        maven { url 'http://oss.jfrog.org/artifactory/oss-snapshot-local' }

    }
    dependencies {

        classpath 'com.android.tools.build:gradle:3.2.1'

        classpath 'com.google.gms:google-services:4.2.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.orhanobut.tracklytics:tracklytics-plugin:2.0.0'

        classpath 'io.fabric.tools:gradle:1.+'

        classpath "io.realm:realm-gradle-plugin:5.8.0"

    }
}

allprojects {
    repositories {
        mavenLocal()
        google()
        jcenter()
        mavenCentral()
        maven { url 'https://maven.fabric.io/public' }
        maven { url "https://jitpack.io" }
    }

    configurations.all {
        exclude group: 'org.jetbrains.kotlin', module: 'kotlin-stdlib-jre7'
    }
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}

compileKotlin {
    kotlinOptions {
        jvmTarget = "1.8"
    }
}
compileTestKotlin {
    kotlinOptions {
        jvmTarget = "1.8"
    }
}

enter image description here 这是apply plugin: 'com.android.application' apply plugin: 'io.fabric' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlin-kapt' android { ... defaultConfig { ... versionCode 1 versionName "1.0" multiDexEnabled true } dexOptions { javaMaxHeapSize "8g" preDexLibraries = false } compileOptions { sourceCompatibility 1.8 targetCompatibility 1.8 } } dependencies { ... } apply plugin: 'com.google.gms.google-services'

的全部错误
c:\Users\User\.AndroidStudio3.3\system\log\

4 个答案:

答案 0 :(得分:8)

@NickUnuchek将依赖项块从根项目的gradle文件中移出,然后它将起作用

在结果顶级gradle中:

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

apply plugin: 'kotlin'

buildscript {
    ext.kotlin_version = '1.3.20'
    repositories {
        google()
        jcenter()
        maven { url 'https://maven.fabric.io/public' }
        //region realm
        maven { url 'http://oss.jfrog.org/artifactory/oss-snapshot-local' }
        //endregion
    }
    dependencies {
        //region google()
        classpath 'com.android.tools.build:gradle:3.3.0'
        //endregion
        //region jcenter()
        classpath 'com.google.gms:google-services:4.2.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.orhanobut.tracklytics:tracklytics-plugin:2.0.0'
        //endregion
        //region maven { url 'https://maven.fabric.io/public' }
        //to check fabric gradle ver
        //https://s3.amazonaws.com/fabric-artifacts/public/io/fabric/tools/gradle/maven-metadata.xml
        classpath 'io.fabric.tools:gradle:1.+'
        //endregion
        //region realm
        classpath "io.realm:realm-gradle-plugin:5.8.0"
        //endregion
    }
}

allprojects {
    repositories {
        mavenLocal()
        google()
        jcenter()
        mavenCentral()
        maven { url 'https://maven.fabric.io/public' }
        maven { url "https://dl.bintray.com/nickunuchek/maven" }
        maven { url "https://jitpack.io" }
    }

    configurations.all {
        exclude group: 'org.jetbrains.kotlin', module: 'kotlin-stdlib-jre7'
    }
}

dependencies {
    //REMOVED FROM TOP-LEVEL implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}

compileKotlin {
    kotlinOptions {
        jvmTarget = "1.8"
    }
}
compileTestKotlin {
    kotlinOptions {
        jvmTarget = "1.8"
    }
}

app / build.gradle:

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'

android {
   ...

    defaultConfig {
     ...
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }


    dexOptions {
        javaMaxHeapSize "8g"
        preDexLibraries = false
    }

    compileOptions {
        sourceCompatibility 1.8
        targetCompatibility 1.8
    }

}

dependencies {
  ...
  implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"//MOVED HERE FROM TOP-LEVEL GRADLE
}

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

答案 1 :(得分:8)

在构建脚本末尾应用google-services插件后,通过添加以下内容,我解决了ArrayIndexOutOfBoundsException的问题:

apply plugin: 'com.google.gms.google-services'
com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true

这会禁用在Google-services 4.2.0中存在错误的版本检查

答案 2 :(得分:1)

当我尝试更新到com.google.gms:google-services:4.2.0时,我遇到了同样的问题。删除gradle缓存也无济于事。

这使得AIOOBE dissapear唯一完全注释出该应用的行家回购的依赖关系。

  android {
    ...
    dependencies {

      // commented out
      // implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

      // this works
      implementation fileTree(dir: 'libs/dropbox', includes: ['dropbox*.jar', 'json*.jar'])**

    }
  }

你可以在我的例子中看到,本地文件相关的工作。但是,这不是解决方案,可能只是朝着找到错误原因的方向迈出了一步。

更挖掘后:

它看起来像是Google服务插件的错误,更确切地说是StrictVersionMatcherPlugin的错误,该错误会随Google Play服务插件自动添加。

他们正在检查firebase和play-services库的版本,并且以某种方式检查会发生异常。这是一个string.indexOf,其中有很多错误。

if (depFromString.startsWith("project ")) { // TODO(paulrashidi): Figure out if a third level dependency shows depFromString. // In a project with other project dependencies the dep // string will be "project :module1" String depName = depFromString.split(":")[1];

depName project :,因此split[1]将失败

答案 3 :(得分:0)

Google Services Gradle插件的堆栈跟踪提示:

Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
    at com.google.android.gms.dependencies.DependencyInspector

,然后添加插件:classpath "com.google.gms:google-services:4.2.0",但不要将其与apply plugin: "com.google.gms.google-services"一起使用(这属于文件的底部)。

没有关联的Java依赖关系也可能导致这种情况;例如:

implementation "com.google.android.gms:play-services-base:16.1.0"