我正在尝试将Firebase添加到我的flutter项目中,但我不断收到此错误找不到方法实现

问题描述

**This is the error message :** 

Launching lib\main.dart on sdk gphone x86 in debug mode...
Running Gradle task 'assembleDebug'...

FAILURE: Build failed with an exception.

* Where:
Build file 'C:\Users\HP-LinkR\Videos\event_notifier\android\build.gradle' 
 line: 35

* What went wrong:
A problem occurred evaluating root project 'android'.
> Could not find method implementation() for arguments 

[com.android.support:support-annotations:28.0.0]类型的对象

org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler。

* 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 2s
Exception: Gradle task assembly debug failed with exit code 1



***This is code for the Build.gradle file that is giving the error:***
    New Properties methods is highlighted red

这是Build.gradle文件的代码,出现错误: 新属性方法以红色突出显示 这是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"
apply plugin: 'com.google.gms.google-services'

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.event_notifier"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName

        multiDexEnabled true
    }

    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.2'
    compile 'com.android.support:multidex:1.0.1'
}

解决方法

转到event_notifier\android\build.gradle ...

这些dependencies应该可以构建:

dependencies {
    compile "org.jetbrains.kotlin:kotlin-stdlib- 
jdk7:$kotlin_version"
    compile "com.google.firebase:firebase-analytics:17.2.2"
    compile "com.android.support:multidex:1.0.1"
}

实际问题似乎是Android Gradle插件的版本已经过时。

您必须升级到最新版本才能使用implementation

classpath "com.android.tools.build:gradle:4.0.1"

也许已经从当前的androidx软件包开始了...因为否则您将被最新版本的Firebase库所困,该库使用了这些陈旧支持库。该Flutter项目通常可能已过时,并且可能需要进行一些重构(除非使用上述compile):

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib:1.3.72"
    implementation "com.google.firebase:firebase-analytics:17.4.4"

    // https://mvnrepository.com/artifact/androidx.multidex/multidex
    implementation "androidx.multidex:multidex:2.0.1"
}

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...