[英]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.