繁体   English   中英

无法连接到 firebase gradle 构建问题 Android Studio

[英]Cannot connect to firebase gradle build issues Android Studio

I am a kid developer and new to programming, i was connecting one of my android app to firebase realtime database using Firebase assistant in android studio, when i clicked on Connect to Firebase , i got and error message as Could not parse the Android Application Module's Gradle config. Resolve gradle build issues and/or resync. Could not parse the Android Application Module's Gradle config. Resolve gradle build issues and/or resync.

我在谷歌上看到很多帖子,但找不到我的答案,请帮助我!

这是我的 app/build.gradle.-

plugins {
    id 'com.android.application'
}

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.3"

    defaultConfig {
        applicationId "com.example.compassfoodlife"
        minSdkVersion 16
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {

    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.3.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}

这是我的 build.gradle 文件代码

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:4.2.0"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
        jcenter() // Warning: this repository is going to shut down soon
    }
}

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

它显示了这一点,请参见此处的图像。

您需要添加 firebase 依赖项,并在 firebase 控制台中创建一个项目。 然后按照在firebase控制台添加项目时的说明将.json文件添加到项目中,参考文档

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

分步指导:打开项目级gradle文件添加google服务依赖

classpath 'com.google.gms:google-services:4.3.5'

然后在模块级别 gradle 文件中添加,google插件,firebase BOM依赖和实时数据库依赖,

    plugins {
    id 'com.google.gms.google-services'
}
dependencies {
  implementation 'com.google.firebase:firebase-database'
    implementation 'com.google.firebase:firebase-analytics'
    implementation platform('com.google.firebase:firebase-bom:26.5.0')
}

在 firebase 控制台中创建一个项目并下载 google-services.json 文件并将其添加到 android 项目中的 app 文件夹中

Gradle 同步项目,它将连接到实时数据库。

注意:添加项目到 firebase 控制台时所需的 SHA-1 签名证书,在右侧菜单中查找 Gradle,App name> Tasks> Android> signingReport,并复制 SHA-1 id

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM