![](/img/trans.png)
[英]Adding Cloud Firestore & Firebase to Flutter project (Android)
[英]Adding Firebase to flutter project, breaks the project
我按照几个教程将 firebase 添加到我的 flutter 项目中。 但无论我做什么,我的项目都以同样的失败告终。
我尝试创建新项目,但同样失败。
现在,我按照本教程进行操作。
在更改应用程序级别 build.gradle 文件后,我开始构建我的应用程序。 我使用flutter run
在我的物理设备上运行应用程序。
每次,我都会遇到同样的错误,并且在互联网上搜索,并没有解决问题,因此问题。
我的错误:
* Error running Gradle:
ProcessException: Process "D:\Projects\flutter_creds\android\gradlew.bat" exited abnormally:
Starting a Gradle Daemon, 1 incompatible and 1 stopped Daemons could not be reused, use --status for details
FAILURE: Build failed with an exception.
* Where:
Build file 'D:\Projects\flutter_creds\android\app\build.gradle' line: 24
* What went wrong:
A problem occurred evaluating project ':app'.
> ASCII
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 1m 58s
Command: D:\Projects\flutter_creds\android\gradlew.bat app:properties
Please review your Gradle project setup in the android/ folder.
Exited (sigterm)
错误位于我的应用程序级别 build.gradle 文件的第 24 行。 但是,那是行,我没有改变。 这是我的 build.gradle(应用级别)
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 28
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.sowingfiber.flutter_creds"
minSdkVersion 16
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
apply plugin: 'com.google.gms.google-services'
这是由于 AndroidX 兼容性,创建一个新项目并按照以下步骤操作:
为了让您的项目与 AndroidX 兼容,您需要在gradle.properties文件中添加以下两行:
android.useAndroidX = true android.enableJetifier = true
确保在您的应用程序 build.gradle 文件中compileSdkVersion和targetSdkVersion都设置为28
从您的主应用程序 build.gradle 文件中删除所有带有注释“删除”的行:
android { compileSdkVersion 28 lintOptions { disable 'InvalidPackage' } defaultConfig { applicationId "YOUR_APPLICATION_ID" minSdkVersion 16 targetSdkVersion 28 versionCode flutterVersionCode.toInteger() versionName flutterVersionName testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" //Remove } buildTypes { release { signingConfig signingConfigs.debug } } } dependencies { testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.2' // Remove androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' // Remove }
如果您尝试构建项目,您将收到与 AndroidX 核心库有关的错误,要修复它,请在项目级别 build.gradle文件的子项目类别中添加代码:
buildscript { repositories { google() jcenter() } dependencies { classpath 'com.android.tools.build:gradle:3.2.1' } subprojects { project.configurations.all { resolutionStrategy.eachDependency { details -> if (details.requested.group == 'androidx.core' &&.details.requested.name.contains('androidx') ) { details.useVersion "1.0.1" } } } } }
注意 1:在第 4 步中,请记住子项目类别应位于依赖项类别之下,如果不存在,则复制并粘贴给定的代码。
我更愿意在 Android Studio 中尝试上述步骤,保存所有文件并重新启动项目,添加 Firebase 依赖项以及文档中告知的任何更改:文档。 它会起作用的。
祝你好运!!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.