Skip to content

Execution failed for task ':permission_handler:compileDebugJavaWithJavac'. #786

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 of 2 tasks
majedqatousa opened this issue Feb 10, 2022 · 3 comments
Closed
1 of 2 tasks
Labels
platform: android Issue is related to the Android platform.

Comments

@majedqatousa
Copy link

majedqatousa commented Feb 10, 2022

🐛 Bug Report

after upgrad Flutter to last v (2.10.0) i can't build my app becouse this FAILED :

Execution failed for task ':permission_handler:compileDebugJavaWithJavac'.

Compilation failed; see the compiler error output for details.

my gradle file 👍

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

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.softech.carrypassenger"
        multiDexEnabled true
        minSdkVersion 21
        targetSdkVersion 30
        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 {
            signingConfig signingConfigs.release
        }
    }

}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.google.android.gms:play-services-location:18.0.0'
    implementation 'com.google.android.gms:play-services-auth:19.0.0'
    implementation "androidx.browser:browser:1.3.0"
    implementation 'com.android.support:multidex:1.0.3'
    implementation platform('com.google.firebase:firebase-bom:28.0.1')

    implementation 'com.google.firebase:firebase-auth'
    implementation 'com.google.firebase:firebase-firestore'

    implementation 'com.google.firebase:firebase-analytics:17.2.2'
    implementation 'com.google.firebase:firebase-messaging:20.1.0'

}

repositories {
    mavenCentral()
    apply plugin: 'com.google.gms.google-services'
}

Expected behavior

Reproduction steps

Configuration

Version: ^6.1.3

Platform:

  • 📱 iOS
  • 🤖 Android
@mvanbeusekom
Copy link
Member

@majedqatousa could you also please include the complete exception logs and the output of flutter doctor -v command?

@mvanbeusekom mvanbeusekom added platform: android Issue is related to the Android platform. status: needs more info We need more information before we can continue work on this issue. labels Feb 10, 2022
@majedqatousa
Copy link
Author

@mvanbeusekom
`C:\flutter.pub-cache\hosted\pub.dartlang.org\permission_handler-6.1.3\android\src\main\java\com\baseflow\permissionhandler\ServiceManager.java:152: warning: [deprecation] getDefaultAdapter() in BluetoothAdapter has been deprecated
final BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
^
error: warnings found and -Werror specified
1 error
1 warning

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':permission_handler:compileDebugJavaWithJavac'.

Compilation failed; see the compiler error output for details.
`

Flutter doctor

Doctor summary (to see all details, run flutter doctor -v): [√] Flutter (Channel stable, 2.10.0, on Microsoft Windows [Version 10.0.19042.1466], locale en-US) [√] Android toolchain - develop for Android devices (Android SDK version 31.0.0) [√] Chrome - develop for the web [X] Visual Studio - develop for Windows X Visual Studio not installed; this is necessary for Windows development. Download at https://visualstudio.microsoft.com/downloads/. Please install the "Desktop development with C++" workload, including all of its default components [√] Android Studio (version 2020.3) [√] IntelliJ IDEA Ultimate Edition (version 2021.1) [√] VS Code (version 1.63.2) [√] Connected device (4 available) [√] HTTP Host Availability

@no-response no-response bot removed the status: needs more info We need more information before we can continue work on this issue. label Feb 10, 2022
@mvanbeusekom
Copy link
Member

The problem here is the combination of using an outdated version of the permission_handler, together with the latest version of Android (according to the build.gradle file you are compiling against API 31).

As mentioned by the exception message the BluetoothAdapter.getDefaultAdapter(); method has been deprecated in API 31 (Android 12) and since you are treating warnings as errors the deprecation warning is failing your build.

There are two ways in solving this problem (last one would be the best):

  1. Change the compileSdkVersion from 31 to 30 (this means you will compile against API 30 and cannot make use of the latest features provided in Android API 31 but still works on Android API 31);
  2. Update the permission_handler plugin to the latest version (or at least higher than 8.2.0). Version 8.2.0 is updated to work with the latest Android 12 (API 31) features and ensures that the deprecated methods are no longer used.

Feel free to go for any of the above solutions, I can imagine that upgrading the permission_handler might bring other challenges. However please note that long-term the second solution is better as it supports all the latest features and API's provided by Android.

I will close this issue, however feel free to leave a comment if you have further questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform: android Issue is related to the Android platform.
Projects
None yet
Development

No branches or pull requests

2 participants