Home > Back-end >  Flutter 2: Run app: Execution failed for task ':location:compileDebugKotlin'
Flutter 2: Run app: Execution failed for task ':location:compileDebugKotlin'

Time:04-18

I am trying to build my app but I have encountered a problem that I do not success to resolve. I've tried many stackoverflow solution without any success (like this one Execution failed for task ':location:compileDebugKotlin').

Here the building error:

Launching lib\main.dart on sdk gphone64 x86 64 in debug mode...
Running Gradle task 'assembleDebug'...
e: C:\Users\Da2ny\AppData\Local\Pub\Cache\hosted\pub.dartlang.org\location-4.3.0\android\src\main\java\com\lyokone\location\FlutterLocationService.kt: (124, 1): Class 'FlutterLocationService' is not abstract and does not implement abstract member public abstract fun onRequestPermissionsResult(p0: Int, p1: Array<(out) String!>, p2: IntArray): Boolean defined in io.flutter.plugin.common.PluginRegistry.RequestPermissionsResultListener
e: C:\Users\Da2ny\AppData\Local\Pub\Cache\hosted\pub.dartlang.org\location-4.3.0\android\src\main\java\com\lyokone\location\FlutterLocationService.kt: (258, 5): 'onRequestPermissionsResult' overrides nothing

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':location:compileDebugKotlin'.
> Compilation error. See log for more details

* 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 6s

Here my flutter doctor:

C:\lib\flutter\bin\flutter.bat doctor --verbose
[√] Flutter (Channel beta, 2.13.0-0.1.pre, on Microsoft Windows [Version 10.0.22000.613], locale fr-FR)
    • Flutter version 2.13.0-0.1.pre at C:\lib\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 13a2fb10b8 (5 days ago), 2022-04-12 15:34:25 -0500
    • Engine revision 499984f99c
    • Dart version 2.17.0 (build 2.17.0-266.1.beta)
    • DevTools version 2.12.1

[√] Android toolchain - develop for Android devices (Android SDK version 32.0.0)
    • Android SDK at C:\lib\flutter-android
    • Platform android-32, build-tools 32.0.0
    • Java binary at: C:\Program Files\Android\Android Studio1\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.11 9-b60-7590822)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop for Windows (Visual Studio Community 2022 17.1.4)
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
    • Visual Studio Community 2022 version 17.1.32407.343
    • Windows 10 SDK version 10.0.19041.0

[√] Android Studio (version 2020.3)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.11 9-b60-7590822)

[√] Android Studio (version 2021.1)
    • Android Studio at C:\Program Files\Android\Android Studio1
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.11 9-b60-7590822)

[√] VS Code (version 1.66.2)
    • VS Code at C:\Users\Da2ny\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension can be installed from:
       https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[√] Connected device (4 available)
    • sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64    • Android 12 (API 32) (emulator)
    • Windows (desktop)            • windows       • windows-x64    • Microsoft Windows [Version 10.0.22000.613]
    • Chrome (web)                 • chrome        • web-javascript • Google Chrome 100.0.4896.88
    • Edge (web)                   • edge          • web-javascript • Microsoft Edge 100.0.1185.29

[√] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!
Process finished with exit code 0

My kotlin version: ext.kotlin_version = '1.6.10'

The added perms:

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

Could you please help me ?

CodePudding user response:

if you recently upgrade your flutter you need to upgrade gradle and kotllin version in your app download latest version of gradle and include it in your project like this: in the following folder : andoid->geadle->wrapper-> in file grdle-wrapper.properites edit last line distributionUrl=https://services.gradle.org/distributions/gradle-7.4.1-all.zip

then upgrade kotlin version in build.gradle

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

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

}

CodePudding user response:

I fixed it:

  1. Updating compileSdkVersion to 32 in Android->App->build.gradle

  2. Adding android:exported="true" to <activity in android->app->src->main->AndroidManifest.xml

  3. Doing the modification of @AHMAD_AR

    andoid->geadle->wrapper-> in file grdle-wrapper.properites edit last line distributionUrl=https://services.gradle.org/distributions/gradle-7.4.1-all.zip

    then upgrade kotlin version in build.gradle

    buildscript {
      ext.kotlin_version = '1.6.10'
      repositories {
        google()
        mavenCentral()
      }
    
      dependencies {
        classpath 'com.android.tools.build:gradle:7.0.4'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
      }
    }
    
  4. Reinstalling the last version of Flutter - Stable Channel

  • Related