简体   繁体   中英

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.

I saw many posts on google but cannot find my answer, please help me out!

Here is my 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'
}

And here comes my build.gradle file code

// 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
}

It is showing this, see the image here .

You need to add the firebase dependencies, and create a project in your firebase console. Then add the.json file to the project following the instructions when you add the project to firebase console, refer the documentation

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

Step by step guide: Open the project level gradle file add google service dependency

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

Then in the module level gradle file add, google plugin, firebase BOM dependency and dependency for realtime database,

    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')
}

Create a project in your firebase console and download the google-services.json file and add it to the app folder in your android project

Gradle sync the project and it will connect to the Realtime database.

Note: For the SHA-1 signing certificate required while adding project to firebase console, look for Gradle on the right side menu, App name> Tasks> Android> signingReport, and copy the SHA-1 id

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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