问题描述
尝试使用Firebase运行新的flutter应用程序时出现以下错误
Getting the following error while trying to run new flutter app with Firebase
Error running Gradle:
ProcessException: Process "...\gradlew.bat" exited abnormally:
我已按照 https://firebase.google.com/docs/flutter/中的说明进行操作设置为字母.
google-services.json位于android/app文件夹
google-services.json is at android/app folder
在我拥有的app/build.gradle中
in app/build.gradle i have
buildscript {
ext.kotlin_version = '1.2.71'
repositories {
google()
jcenter()
maven { url 'https://maven.google.com' }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.2'
}
}
以及在项目build.gradle中的依赖项
and in project build.gradle dependencies
implementation 'com.google.firebase:firebase-analytics:17.2.0'
并在底部
apply plugin: 'com.google.gms.google-services' // Google Play services Gradle plugin
pubspec.yaml具有
pubspec.yaml has
firebase_core: ^0.4.0+9
该应用已在Firebase控制台上以正确的名称注册为android应用.
The app is registered with correct name at Firebase console as android app.
- 我尝试了不同版本的com.android.tools.build:gradle和com.google.gms:google-services
- 颤抖的医生没有显示错误
- 我删除了user/.gradle/caches/文件夹
推荐答案
基于@ Maadhav-Sharma的答案,我得到了它的以下修复程序.即使对于应该与AndroiX兼容的带有compileSdkVersion 28的新Flutter项目,AndroidX兼容性也存在问题.更多信息: https://flutter.dev/docs/development/packages -and-plugins/androidx-compatibility
Based on @Maadhav-Sharma's answer i got it working with following fixes. Problems is with AndroidX compatibility even for new Flutter projects with compileSdkVersion 28 that should AndroiX compatible. More info: https://flutter.dev/docs/development/packages-and-plugins/androidx-compatibility
首先创建一个新项目.
在android/build.gradle中:
In android/build.gradle:
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
classpath 'com.google.gms:google-services:4.3.2'
}
在android/gradle/wrapper/gradle.properties中,添加
In android/gradle/wrapper/gradle.properties, append
android.enableJetifier=true
android.useAndroidX=true
在android/app/build.gradle中:
In android/app/build.gradle:
defaultConfig {
minSdkVersion 16
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true // This was needed to get FireStore to work
}
dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation 'com.google.firebase:firebase-analytics:17.2.0'
implementation 'androidx.multidex:multidex:2.0.1' // This was needed to get FireStore to work
}
apply plugin: 'com.google.gms.google-services'
这篇关于尝试使用Flutter设置Firebase时运行Gradle时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!