android - 无法在 Android studio 中构建 firebase gradle

标签 android firebase-realtime-database

我正在将 Firebase 数据库 gradle 添加到我的 Android 项目中,但 gradle 无法构建。我在我的应用 gradle 中添加了 Firebase gradle,并在项目 gradle 中添加了一个 google gradle我收到此消息:

enter image description here

这是我的应用程序 gradle

 apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.3"
    defaultConfig {
        applicationId "iamrajendra.github.io"
        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(include: ['*.jar'], dir: 'libs')
    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.constraint:constraint-layout:1.0.2'
    compile 'com.android.support:design:25.3.1'
    testCompile 'junit:junit:4.12'
    compile 'com.google.firebase:firebase-database:11.0.2'

}

这是我的项目 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.3'
         classpath 'com.google.gms:google-services:3.1.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
}

最佳答案

我解决了这个问题。问题是库的版本

工作库

implementation'com.google.firebase:firebase-database:10.0.0'

如果教程 android 库版本是 11.01 但该版本在 android studio 中无法运行

库不工作

com.google.firebase:firebase-database:11.0.2

教程中的 gradle 依赖项写错了。

https://firebase.google.com/docs/android/setup

关于android - 无法在 Android studio 中构建 firebase gradle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44987728/

相关文章:

android - 使用 Retrofit 获取数据并插入到 SQLite 数据库

javascript - 使用 firebase.database.ServerValue.TIMESTAMP 时有没有办法获取实际时间戳?

firebase - 实时数据库 Firebase "All or nothing"事务

android - Android 中的字幕文本

java - 在android中使用反射的缺点?

android - 使用拖放来确定身份?

安卓 parse.com setObjectId

ios - Firebase 读取/保存数据以将其用作列表 | swift/火力基地

firebase - Firestore 的 .info/serverTimeOffset?

java - 检索具有特定名称的所有字段