Flutter:任务“:location:compileDebugKotlin”执行失败

ham*_*ace 6 android kotlin android-studio build.gradle flutter

Execution failed for task ':location:compileDebugKotlin'.

构建:gradle(模块:应用程序)

    ext.kotlin_version = '1.6.10'
    repositories {
        maven {
            //url 'https://dl.google.com/dl/android/maven2',
            url 'http://download.flutter.io'
        }
        google()
        mavenCentral()
    }

    dependencies {
        classpath 'com.google.gms:google-services:4.3.10'
        classpath 'com.android.tools.build:gradle:4.+'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.4.1'
        //classpath("com.google.android.libraries.mapsplatform.secrets-gradle-plugin:secrets-gradle-plugin:2.0.0")
    }
}

allprojects {
    repositories {
        maven {
            apply plugin: 'maven'
            //url 'https://dl.google.com/dl/android/maven2',
            url 'http://download.flutter.io'
        }
        google()
        mavenCentral()
    }
}

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

Run Code Online (Sandbox Code Playgroud)

构建:gradle(项目)

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 FileNotFoundException ("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '4'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

android {
    compileSdkVersion 31

    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.develpment.sported_app"
        minSdkVersion 23
        targetSdkVersion 29
        multiDexEnabled true
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

    signingConfigs {
       release {
           keyAlias keystoreProperties['keyAlias']
           keyPassword keystoreProperties['keyPassword']
           storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
           storePassword keystoreProperties['storePassword']
       }
   }

    buildTypes {
        //release {
            release {
                profile {
                    matchingFallbacks = ['debug', 'release']
                }
                minifyEnabled true
                useProguard true
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
                signingConfig signingConfigs.release
            }
        //}
    }
    lintOptions {
       disable 'InvalidPackage'
       checkReleaseBuilds false
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "com.android.support:multidex:1.0.3"
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
    implementation 'com.android.support:support-annotations:28.0.0'
}

apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'
Run Code Online (Sandbox Code Playgroud)

尝试过的解决方案:

  1. 使缓存无效/重新启动
  2. 构建 -> 清理项目
  3. 更新了 Kotlin 插件并使用了最新的 Kotlin 版本
  4. 跑步./gradlew assembleDebug
  5. 运行flutter doctorflutter clean

以前我尝试过构建发布版本和发布版本,但某些功能无法正常工作。所以我环顾四周,发现我应该在 android 部分的 MainActivity.kt 的 main 方法中添加下面的代码,这就是这个问题开始的时候。我什至尝试注释掉该方法,但错误仍然存​​在。

override fun configureFlutterEngine(@NonNull flutterEngine:FlutterEngine){GeneratedPluginRegistrant.registerWith(flutterEngine);}

小智 6

我更新了所有项目包。这为我解决了这个问题。

  • 是的,运行“flutter pub Upgrade”,然后“flutter clean”,然后“flutter pub get”为我解决了这个问题。 (3认同)

小智 2

您需要根据ext.kotlin_version = '1.6.10'classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"下划线的 $kotlin_version均衡第一行中的 kotlin 版本

在此之后,问题就解决了...