Skip to content
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

Support JDK 17 #71

Closed
SherpaMiguel opened this issue Feb 7, 2024 · 21 comments
Closed

Support JDK 17 #71

SherpaMiguel opened this issue Feb 7, 2024 · 21 comments

Comments

@SherpaMiguel
Copy link

When using Gradle 8 (requires JDK 17):

Execution failed for task ':flutter_google_places_sdk_android:compileDebugKotlin'.
'compileDebugJavaWithJavac' task (current target is 1.8) and 'compileDebugKotlin' task (current target is 17) jvm target compatibility should be set to the same Java version.
Consider using JVM toolchain: https://kotl.in/gradle/jvm/toolchain

@jonasborggren
Copy link

Any workaround for now?

@SherpaMiguel
Copy link
Author

SherpaMiguel commented Feb 8, 2024

@jonasborggren yep, add this into your android/build.gradle

subprojects {
    afterEvaluate {
        if (project.plugins.hasPlugin("com.android.application")
                || project.plugins.hasPlugin("com.android.library")) {
            // TODO FIX
            // https://github.com/matanshukry/flutter_google_places_sdk/issues/71
            if (project.name == "flutter_google_places_sdk_android") {
                project.android.compileOptions {
                    sourceCompatibility = JavaVersion.VERSION_17
                    targetCompatibility = JavaVersion.VERSION_17
                }
            }
        }
    }
    project.buildDir = "${rootProject.buildDir}/${project.name}"
    project.evaluationDependsOn(':app')
}

@matanshukry
Copy link
Owner

@SherpaMiguel @jonasborggren can you explain the steps you're taking to get this error, or even create a reproducible example?

I'm using java 19.0.2, gradle 8.1.1, and running flutter build appbundle on the example project works fine.

@SherpaMiguel
Copy link
Author

@matanshukry in settings.gradle, update "com.android.application" (Gradle) to 8.2.2 and "org.jetbrains.kotlin.android" to 1.9.22

This is my plugin configuration in settings.gradle:

plugins {
    id "dev.flutter.flutter-plugin-loader" version "1.0.0"
    id "com.android.application" version "8.2.2" apply false // VERSIÓN GRADLE
    id "org.jetbrains.kotlin.android" version "1.9.22" apply false // VERSIÓN KOTLIN
    // START: FlutterFire Configuration
    id "com.google.gms.google-services" version "4.4.0" apply false
    id "com.google.firebase.crashlytics" version "2.9.9" apply false
    id "com.google.firebase.firebase-perf" version "1.4.2" apply false
    // END: FlutterFire Configuration
}

Also followed this migration guide: https://docs.flutter.dev/release/breaking-changes/flutter-gradle-plugin-apply

Note that this problem is ocurring in some other Flutter plugins: fluttercandies/flutter_image_compress#270

@larssn
Copy link

larssn commented Mar 26, 2024

@SherpaMiguel When inserting your afterEvaluate script into the bottom of android/build.gradle, I get an error on build: Cannot run Project.afterEvaluate(Closure) when the project is already evaluated.

EDIT: Figured it out

The bottom of the build.gradle file in a default Flutter setup will end up looking like this:

rootProject.buildDir = '../build'
subprojects {
    afterEvaluate {
        if (project.plugins.hasPlugin("com.android.application")
                || project.plugins.hasPlugin("com.android.library")) {
            if (project.name == "flutter_google_places_sdk_android") {
                project.android.compileOptions {
                    sourceCompatibility = JavaVersion.VERSION_17
                    targetCompatibility = JavaVersion.VERSION_17
                }
            }
        }
    }
}

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

@SherpaMiguel
Copy link
Author

@SherpaMiguel When inserting your afterEvaluate script into the bottom of android/build.gradle, I get an error on build: Cannot run Project.afterEvaluate(Closure) when the project is already evaluated.

The afterEvaluate script should be inside "subprojects", in the root of android/build.gradle.

@TatsuUkraine
Copy link

Does anybody know when this fix may be released?

@matanshukry
Copy link
Owner

matanshukry commented Aug 17, 2024

@TatsuUkraine I've updated the build.gradle and settings.gradle due to an upgrade as part of flutter, but as I wrote before it is working for me successfully.

I'm using Gradle 8.1.1 , Java 19.0.2, and flutter 3.24.0.

If it still fails for you - what are you running exactly? what version each component you have, and what is the error?

@TatsuUkraine
Copy link

TatsuUkraine commented Aug 17, 2024

So I was recently updating project to AGP 8.3.1, due to an r8 issue. Which forced me to switch to java17. I'm on flutter 3.22 still though. But I already migrated to a new Gradle config, which was announced in prev stable release

Workaround described here #71 (comment) worked for me as a tmp solution.

I also noticed referenced PR in this thread, which got merged, but it seems new version with this fix wasn't released yet

@TatsuUkraine
Copy link

The error I'm getting prior tmp fix was exactly the one described in the description of this ticket

@matanshukry
Copy link
Owner

@TatsuUkraine As far as I can tell the temporary solution described here is part of users/your project not part of this plugin, so it shouldn't be related.

Try to provide more details or even a reproducible repo/example so I can reproduce the error on my end, and hence fix any issues if there are any

@TatsuUkraine
Copy link

@matanshukry #82

@matanshukry
Copy link
Owner

@matanshukry #82

That PR is not a reproducible example; it doesn't even talk about the problem.

Also it was already merged, so I don't even understand what's your point...

@TatsuUkraine
Copy link

@matanshukry sorry, didn't write full message ( I meant that this PR got merged, but these changes was never released. As part of this changes I can see that it switches plugin to use java 17

@matanshukry
Copy link
Owner

@TatsuUkraine oh ok that make sense.
Let me look into that then

@TatsuUkraine
Copy link

I can be wrong here, but as far as I understand in order to switch to AGP 8 all your third party deps, as well as the project, should target the same jvm version, and the tmp fix in this thread does it by forcing current package have the same java version configs

@TatsuUkraine
Copy link

I have so many third party deps, so I can assume some of them does switch back and forward between jvm versions during the build, which ends up with the fail due to race condition in the Gradle build 😅 so I did just easiest thing so far - override compile options to match my project compile options for Google maps package and it worked))

@matanshukry
Copy link
Owner

@TatsuUkraine Published to 0.1.9 .
Should take few minutes, but then please try it and let me know if it solves the issue

@TatsuUkraine
Copy link

@matanshukry thank you, I will let you know if anything comes up

@matanshukry
Copy link
Owner

Closing for now then, will re-open if needed

@TatsuUkraine
Copy link

@matanshukry looks good on my end, builds are passing without the tmp fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants