将Firebase添加到flutter项目中,会中断项目 [英] Adding Firebase to flutter project, breaks the project

查看:104
本文介绍了将Firebase添加到flutter项目中,会中断项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遵循了一些教程,将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的兼容性, 创建一个新项目,然后执行以下步骤:

  1. 为了使您的项目与AndroidX兼容,您需要在 gradle.properties 文件中添加以下两行:

    android.useAndroidX = true
    android.enableJetifier = true
    

  2. 确保在您的 app build.gradle文件中,将 compileSdkVersion targetSdkVersion 都设置为 28

  3. 从主 app 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
    }
    

  4. 如果您尝试构建项目,则会收到与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步中,请记住子项目类别应在dependecies类别以下,如果不存在,则复制并粘贴给出的代码.

我希望在Android Studio中尝试上述步骤,保存所有文件并重新启动项目,添加Firebase依赖项以及文档中要求执行的所有更改:this tutorial.

Right after changing the app level build.gradle file, I start to build my app. I use flutter run to run the app on my physical device.

Every single time, I get hit by the same exact error, and scouring on the internet, didn't solve the issue, hence the question.

My Error:

* 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)

The error is at line 24 of my app level build.gradle file. However, that is the line, I haven't changed. Here is my build.gradle (app level)

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'

解决方案

It's due to AndroidX compatibility, Create a new project and follow the steps below:

  1. In order for your project to be AndroidX compatible, you need to add the following two lines to your gradle.properties file:

    android.useAndroidX = true
    android.enableJetifier = true
    

  2. Make sure in your app build.gradle file that the compileSdkVersion and targetSdkVersion are both set to 28

  3. Remove all the lines with the comment "Remove" from your main app build.gradle file:

    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
    }
    

  4. If you try to build the project you will get an error that has something to do with the core library for AndroidX, To fix it, add the code in the subprojects category in your project level build.gradle file:

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

NOTE 1: In the 4th step rememeber that the subprojects category should be bellow the dependecies category, if not present then copy and paste the code given.

I would prefer to try the above steps in Android Studio, Save all the files and restart the project, Add the Firebase dependencies and whatever the changes are told to do in the documentation: Documentation. It would work.

BEST OF LUCK!!

这篇关于将Firebase添加到flutter项目中,会中断项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆