无法解决:com.google.firebase:firebase-core:16.0.0

时间:2018-06-11 00:59:09

标签: android firebase android-studio

我有android项目 我想使用google firebase向该应用添加推送通知 首先我下载了​​xml文件,然后在app root上将其过去 我按照他们在这个链接上说的那样添加了这些行

buildscript {
  dependencies {
    // Add this line
    classpath 'com.google.gms:google-services:4.0.0'
  }
}
    dependencies {
  // Add this line
  compile 'com.google.firebase:firebase-core:16.0.0'
}
...
// Add to the bottom of the file
apply plugin: 'com.google.gms.google-services'

然后我立即点击同步 总是收到这个错误

failed to resolve: com.google.firebase:firebase-core:16.0.0

感谢您的帮助 这是完整的gradle文件

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "28.0.0"
    defaultConfig {
        applicationId "com.softya.demo"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        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'
    })
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support:support-v4:25.3.1'
    testCompile 'junit:junit:4.12'
    compile 'com.google.firebase:firebase-core:16.0.0'
}
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 {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.0'
        classpath 'com.google.gms:google-services:4.0.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

3 个答案:

答案 0 :(得分:2)

我注意到你需要更新很多脚本。

例如,让我们从您的顶级build.gradle开始。你不应该再使用android gradle插件2. +,而应该使用版本3.1.x

为此,您应该将google()放入您的存储库。

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

buildscript {
   repositories {
      jcenter()
      //Add this line
      google()
   }
   dependencies {
      //Please update it to 3.1.x
      classpath 'com.android.tools.build:gradle:3.1.2'
      //Update to the latest version as well
      classpath 'com.google.gms:google-services:4.0.1'
      // NOTE: Do not place your application dependencies here; they belong
      // in the individual module build.gradle files
   }
}

一些提示:

尝试将应用级build.gradlecompile更新为implementation,因为它们很快就会被弃用。

答案 1 :(得分:1)

您必须为所有项目添加google()Google的Maven存储库

allprojects {
    repositories {
        jcenter()
        google()
    }
}

答案 2 :(得分:1)

我在build.gradle [Proyect]中使用此脚本解决了这个问题

buildscript {
    ext.kotlin_version = '1.2.30'
    repositories {
        google()
        jcenter()
        maven {
            url 'https://dl.bintray.com/android/android-tools'
        }
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.2.0'
    }
}