安装 Agora Flutter RTC 包时出现 Execution failed for task ':agora_rtc_engine:compileProfileKotlin' 错误

When installing Agora Flutter RTC package it gives Execution failed for task ':agora_rtc_engine:compileProfileKotlin' error

我有一个正在运行的 flutter 项目,但是当我安装 agora RTC 包时,它显示任务执行失败 ':agora_rtc_engine:compileDebugKotlin'。错误。 我什至还没有使用这个包,我尝试设置权限和 readme 部分中的所有说明,但我认为问题出在包本身,而且我的 flutter 项目是 null-safety migrated 并且它是正在工作,所以我确定我的项目没有任何问题。

我还没有使用这个包。刚安装就报错

这里是 app/gradle.build:

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 flutter.compileSdkVersion
    ndkVersion flutter.ndkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.example.malhamti_app"
        // You can update the following values to match your application needs.
        // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
        minSdkVersion flutter.minSdkVersion
        targetSdkVersion flutter.targetSdkVersion
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

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

这是我的 android/build.gradle:

    ext.kotlin_version = '1.6.20'
    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:7.1.3'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
        maven { url 'https://jitpack.io' }
    }
}

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

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

这里是 gradle --stacktrace: 查看完整 stacktrace(字符限制)

> Task :agora_rtc_engine:compileProfileKotlin FAILED
e: /Users/doabletech/Development/Tools/flutter_sdk/.pub-cache/hosted/pub.dartlang.org/agora_rtc_engine-5.1.0/android/src/main/kotlin/io/agora/agora_rtc_engine/AgoraRtcEnginePlugin.kt: (251, 18): Type mismatch: inferred type is String? but String was expected
e: /Users/doabletech/Development/Tools/flutter_sdk/.pub-cache/hosted/pub.dartlang.org/agora_rtc_engine-5.1.0/android/src/main/kotlin/io/agora/agora_rtc_engine/AgoraSurfaceViewFactory.kt: (16, 1): Class 'AgoraSurfaceViewFactory' is not abstract and does not implement abstract base class member public abstract fun create(p0: Context?, p1: Int, p2: Any?): PlatformView defined in io.flutter.plugin.platform.PlatformViewFactory
e: /Users/doabletech/Development/Tools/flutter_sdk/.pub-cache/hosted/pub.dartlang.org/agora_rtc_engine-5.1.0/android/src/main/kotlin/io/agora/agora_rtc_engine/AgoraSurfaceViewFactory.kt: (20, 3): 'create' overrides nothing
e: /Users/doabletech/Development/Tools/flutter_sdk/.pub-cache/hosted/pub.dartlang.org/agora_rtc_engine-5.1.0/android/src/main/kotlin/io/agora/agora_rtc_engine/AgoraTextureViewFactory.kt: (12, 1): Class 'AgoraTextureViewFactory' is not abstract and does not implement abstract base class member public abstract fun create(p0: Context?, p1: Int, p2: Any?): PlatformView defined in io.flutter.plugin.platform.PlatformViewFactory
e: /Users/doabletech/Development/Tools/flutter_sdk/.pub-cache/hosted/pub.dartlang.org/agora_rtc_engine-5.1.0/android/src/main/kotlin/io/agora/agora_rtc_engine/AgoraTextureViewFactory.kt: (17, 3): 'create' overrides nothing

> Task :agora_rtc_engine:compileDebugKotlin FAILED
e: /Users/doabletech/Development/Tools/flutter_sdk/.pub-cache/hosted/pub.dartlang.org/agora_rtc_engine-5.1.0/android/src/main/kotlin/io/agora/agora_rtc_engine/AgoraRtcEnginePlugin.kt: (251, 18): Type mismatch: inferred type is String? but String was expected
e: /Users/doabletech/Development/Tools/flutter_sdk/.pub-cache/hosted/pub.dartlang.org/agora_rtc_engine-5.1.0/android/src/main/kotlin/io/agora/agora_rtc_engine/AgoraSurfaceViewFactory.kt: (16, 1): Class 'AgoraSurfaceViewFactory' is not abstract and does not implement abstract base class member public abstract fun create(p0: Context?, p1: Int, p2: Any?): PlatformView defined in io.flutter.plugin.platform.PlatformViewFactory
e: /Users/doabletech/Development/Tools/flutter_sdk/.pub-cache/hosted/pub.dartlang.org/agora_rtc_engine-5.1.0/android/src/main/kotlin/io/agora/agora_rtc_engine/AgoraSurfaceViewFactory.kt: (20, 3): 'create' overrides nothing
e: /Users/doabletech/Development/Tools/flutter_sdk/.pub-cache/hosted/pub.dartlang.org/agora_rtc_engine-5.1.0/android/src/main/kotlin/io/agora/agora_rtc_engine/AgoraTextureViewFactory.kt: (12, 1): Class 'AgoraTextureViewFactory' is not abstract and does not implement abstract base class member public abstract fun create(p0: Context?, p1: Int, p2: Any?): PlatformView defined in io.flutter.plugin.platform.PlatformViewFactory
e: /Users/doabletech/Development/Tools/flutter_sdk/.pub-cache/hosted/pub.dartlang.org/agora_rtc_engine-5.1.0/android/src/main/kotlin/io/agora/agora_rtc_engine/AgoraTextureViewFactory.kt: (17, 3): 'create' overrides nothing

> Task :agora_rtc_engine:compileReleaseKotlin FAILED
e: /Users/doabletech/Development/Tools/flutter_sdk/.pub-cache/hosted/pub.dartlang.org/agora_rtc_engine-5.1.0/android/src/main/kotlin/io/agora/agora_rtc_engine/AgoraRtcEnginePlugin.kt: (251, 18): Type mismatch: inferred type is String? but String was expected
e: /Users/doabletech/Development/Tools/flutter_sdk/.pub-cache/hosted/pub.dartlang.org/agora_rtc_engine-5.1.0/android/src/main/kotlin/io/agora/agora_rtc_engine/AgoraSurfaceViewFactory.kt: (16, 1): Class 'AgoraSurfaceViewFactory' is not abstract and does not implement abstract base class member public abstract fun create(p0: Context?, p1: Int, p2: Any?): PlatformView defined in io.flutter.plugin.platform.PlatformViewFactory
e: /Users/doabletech/Development/Tools/flutter_sdk/.pub-cache/hosted/pub.dartlang.org/agora_rtc_engine-5.1.0/android/src/main/kotlin/io/agora/agora_rtc_engine/AgoraSurfaceViewFactory.kt: (20, 3): 'create' overrides nothing
e: /Users/doabletech/Development/Tools/flutter_sdk/.pub-cache/hosted/pub.dartlang.org/agora_rtc_engine-5.1.0/android/src/main/kotlin/io/agora/agora_rtc_engine/AgoraTextureViewFactory.kt: (12, 1): Class 'AgoraTextureViewFactory' is not abstract and does not implement abstract base class member public abstract fun create(p0: Context?, p1: Int, p2: Any?): PlatformView defined in io.flutter.plugin.platform.PlatformViewFactory
e: /Users/doabletech/Development/Tools/flutter_sdk/.pub-cache/hosted/pub.dartlang.org/agora_rtc_engine-5.1.0/android/src/main/kotlin/io/agora/agora_rtc_engine/AgoraTextureViewFactory.kt: (17, 3): 'create' overrides nothing

FAILURE: Build completed with 3 failures.

1: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':agora_rtc_engine:compileProfileKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
   > Compilation error. See log for more details

* Try:
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Exception is:
see full [stacktrace][3] here (character limit)


==============================================================================

2: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':agora_rtc_engine:compileDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
   > Compilation error. See log for more details

* Try:
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Exception is:
see full [stacktrace][3] here (character limit)


==============================================================================

3: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':agora_rtc_engine:compileReleaseKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
   > Compilation error. See log for more details

* Try:
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Exception is:
see full [stacktrace][3] here (character limit)


BUILD FAILED in 4s
49 actionable tasks: 49 executed

我发现了这个问题,这是因为我使用的是 flutter dev 频道, 如果你有同样的问题,确保你使用的是最新的 flutter 稳定版本,这样做:

  • 运行 flutter channel stable

确保你的 pubspec.yaml 文件已将 flutter 版本更改为稳定版本,

  • 运行 flutter clean
  • 运行 flutter run

你可能会从 flutter lint 包中得到一个错误,我通过删除它解决了这个问题。

edit: flutter 3.0.0 似乎有问题导致 agora 出现同样的错误,将 flutter 降级到 2.12.5 解决了我的问题。