gpt4 book ai didi

android - 无法将 firebase 添加到 android (flutter)

转载 作者:行者123 更新时间:2023-11-29 00:51:44 25 4
gpt4 key购买 nike

两天以来我一直在尝试解决这个问题,我也尝试了 Stack Overflow 上已经存在的关于这个问题的解决方案,但没有成功。我遵循的所有步骤都来自将 Firebase 添加到您的 Android 应用指南(Firebase 官方的步骤)

项目级 Build.gradle:

buildscript {
ext.kotlin_version = '1.2.71'
repositories {
google()
jcenter()
}

dependencies {

classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.google.gms:google-services:4.3.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

allprojects {
repositories {
google()
jcenter()
}
}

rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}

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

应用级 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.example.loginapp"
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"
implementation 'com.google.firebase:firebase-analytics:17.2.0'
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'

Pubspec.yaml 文件:

version: 1.0.0+1

environment:
sdk: ">=2.1.0 <3.0.0"

dependencies:
flutter:
sdk: flutter

# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
firebase_auth: ^0.14.0+9

dev_dependencies:
flutter_test:
sdk: flutter

Gradle-wrapper.properties:

#Fri Jun 23 08:50:38 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip

错误:

PS D:\flutterworks\bhund> flutter run
Using hardware rendering with device Android SDK built for x86. If you get graphics artifacts, consider enabling software rendering with
"--enable-software-rendering".
Launching lib\main.dart on Android SDK built for x86 in debug mode...
Initializing gradle... 5.1s
Resolving dependencies...
* Error running Gradle:
ProcessException: Process "D:\flutterworks\bhund\android\gradlew.bat" exited abnormally:

Command: D:\flutterworks\bhund\android\gradlew.bat app:properties


Please review your Gradle project setup in the android/ folder.
PS D:\flutterworks\bhund>

最佳答案

我有同样的问题,无法手动迁移到 Androidx。请注意,如果要使用 Firebase,项目现在必须在 Androidx 中,否则以后可能会出现更多问题。

第 1 步:在您的项目级别 gradle 更改:

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

到:

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

通常在这一步之后,您的项目会运行良好,但现在迁移到 AndroidX 很重要,并且不会在使用 Firebase 时导致进一步的错误。

第 2 步:完成此操作后,只需使用 Androidx 设置创建一个新项目,您可以通过打开 flutter_console.bat 并导航到所需的文件夹然后运行来执行此操作:

    flutter create --androidx your_project_name

在你的 flutter 控制台上。

第 3 步:导航到您的新项目 > android > gradle.properties 并检查它是否有以下两行:

    android.useAndroidX=true
android.enableJetifier=true

这意味着该项目已迁移到 Androidx。

第 4 步:最后,将所有代码从旧项目连同您可能已添加到旧项目中的所有依赖项和插件一起移至新的 Flutter 项目。 (包括第一步中的依赖)

关于android - 无法将 firebase 添加到 android (flutter),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58922874/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com