'Flutter: Execution failed for task ':location:compileDebugKotlin'

Execution failed for task ':location:compileDebugKotlin'.

build:gradle(Module:app)

    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')
}

build:gradle(Project)

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'

Solution Tried:

  1. Invalidate Caches/Restart
  2. Build -> Clean Project
  3. Updated Kotlin Plugin and used latest Kotlin version
  4. Run ./gradlew assembleDebug
  5. Run flutter doctor and flutter clean

Previously I tried to build for release and the release build, but some features weren't working. So I looked around and found that I was supposed to add the code below in the main method in the MainActivity.kt in the android section, that's when this issue started. I even tried to comment out the method but the error is still there.

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



Solution 1:[1]

I updated all my project packages. That solved the issue for me.

Solution 2:[2]

You need to equalize kotlin version in first row which is ext.kotlin_version = '1.6.10' to according to classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" of underlined $kotlin_version

After this, problem will solve...

Solution 3:[3]

I'm also faced same issue, I done with below changes. But it's a temporary bug fix. For more reference

Search for the FlutterLocationService.kt and edit it change override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>?, grantResults: IntArray?): Boolean to

override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray): Boolean

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 kwamerex
Solution 2 theredboy
Solution 3 Saravanan S