如何将Flutter应用连接到Firebase

时间:2019-12-18 02:49:58

标签: flutter

我已经尝试过增强我的应用程序的Firebase的强度,所以我必须转到firebase.google.com,然后创建一个新项目,所以问题出在我将他们所说的放在构建时。 Gradle文件出现错误

  

失败:构建失败,并出现异常。

     
      
  • 其中:   构建文件'C:\ Users \ name \ AndroidStudioProjects \ test \ android \ app \ build.gradle'行:24

  •   
  • 出了什么问题:   评估项目':app'时发生问题。   无法应用插件[id'kotlin-android']   名称为“ android”的扩展名不存在。当前注册的扩展名:[ext,kotlin]

  •   
  • 尝试:   使用--stacktrace选项运行以获取堆栈跟踪。使用--info或--debug选项运行,以获取更多日志>输出。使用--scan运行以获取完整的见解。

  •   
  • https://help.gradle.org

  • 获得更多帮助   
     

1秒内失败   错误完成:Gradle任务assembleDebug失败,退出代码为1

这是我的android / build.gradle

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

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

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
}

这是android / app / 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: '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.test"
        minSdkVersion 21
        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'

2 个答案:

答案 0 :(得分:0)

我想您在android文件中缺少android/app/build.gradle插件

apply plugin: 'com.android.application'

尝试一下:

enter image description here

答案 1 :(得分:0)

只需将构建gradle和kotlin依赖项更改为以下稳定版本即可。

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

    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.0'
        classpath 'com.google.gms:google-services:4.3.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

还要在android / app / build.gradle文件中添加android插件

apply plugin: 'com.android.application'