Fintasys / emoji_picker_flutter

A Flutter package that provides an Emoji picker widget with 1500+ emojis in 8 categories.
MIT License
170 stars 127 forks source link

android build failed #189

Closed sinnoorc closed 8 months ago

sinnoorc commented 9 months ago

i tried to build the apk , build got failed

Execution failed for task ':emoji_picker_flutter:compileReleaseKotlin' Inconsistent JVM-target compatibility detected for tasks 'compileReleaseJavaWithJavac' (1.8) and 'compileReleaseKotlin' (17).

Screenshot 2024-02-22 at 2 48 07 PM

flutter doctor

Screenshot 2024-02-22 at 2 49 17 PM
Fintasys commented 9 months ago

Did you try flutter clean?

malbolged commented 9 months ago

Did you try flutter clean?

Same problem here, and yes i tried "flutter clean"

mtallenca commented 9 months ago

I needed to update my kotlin version to 1.9.22 to compile again...

https://plugins.gradle.org/plugin/org.jetbrains.kotlin.android/1.9.22

sinnoorc commented 9 months ago

Did you try flutter clean?

yes i did @Fintasys

jerryrox commented 9 months ago

I had the same issue after I upgraded Flutter SDK today. Could you please try if adding the below line to android/gradle.properties works for you?

kotlin.jvm.target.validation.mode=IGNORE

https://stackoverflow.com/questions/77520506/inconsistent-jvm-target-compatibility-detected-for-tasks-despite-already-definin

Fintasys commented 9 months ago

Couldn't reproduce the issue. But I assume it is due some change in Kotlin 1.8 (issuetracker) Might be possible to solve it by adding following to your build.gradle.

android { 
   ...
   compileOptions {
       sourceCompatibility JavaVersion.VERSION_17
       targetCompatibility JavaVersion.VERSION_17
   }
}

kotlinOptions {
    jvmTarget = '17'
}   

Can you try?

GuiQueirozRibeiro commented 9 months ago

I'm facing the same issue, i try to update the emoji_picker to 2.1.0 from 1.6.4 in flutter 3.19, and the build failed for me.

I try to use this options also but dindt work for me

android { ... compileOptions { sourceCompatibility JavaVersion.VERSION_17 targetCompatibility JavaVersion.VERSION_17 } }

kotlinOptions { jvmTarget = '17' }

im my opinion its better to downgrade the emoji picker, when i try to upgrade the kotlin, others packages failed, is better to following the same versions as flutter using and waiting for the emoji_picker to fix this erro

Fintasys commented 9 months ago

I downgraded Kotlin version in this branch to 1.7.10, can somebody check if that fixes the issue?

  emoji_picker_flutter:
    git:
      url: https://github.com/Fintasys/emoji_picker_flutter.git
      ref: downgrade-kotlin
heshesh2010 commented 9 months ago

I downgraded Kotlin version in this branch to 1.7.10, can somebody check if that fixes the issue?

  emoji_picker_flutter:
    git:
      url: https://github.com/Fintasys/emoji_picker_flutter.git
      ref: downgrade-kotlin
RasmusGrift96 commented 8 months ago

I have the same issue after I upgraded flutter to version 3.19.1

tried:

compileOptions {
        coreLibraryDesugaringEnabled = true
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = "1.8"
    }

as well as:

    compileOptions {
        coreLibraryDesugaringEnabled = true
        sourceCompatibility = JavaVersion.VERSION_17
        targetCompatibility = JavaVersion.VERSION_17
    }

    kotlinOptions {
        jvmTarget = "17"
    }

From some googling, seems like these people have a similar issue

Fintasys commented 8 months ago

I downgraded Kotlin version in this branch to 1.7.10, can somebody check if that fixes the issue?

  emoji_picker_flutter:
    git:
      url: https://github.com/Fintasys/emoji_picker_flutter.git
      ref: downgrade-kotlin

Without a example project to reproduce the issue it is difficult to fix. I updated the branch above to match its content like a newly generated package. Maybe someone can try again?

Based on the link @RasmusGrift96 provided there was one comment with a fix, maybe also worth a try. https://github.com/flutter/flutter/issues/125181#issuecomment-1555034383

RasmusGrift96 commented 8 months ago

Adding to my pubspec.yaml:

emoji_picker_flutter:
    git:
      url: https://github.com/Fintasys/emoji_picker_flutter.git
      ref: downgrade-kotlin

gave the same error for me.

As I'm on a different kotlin version, I also tried changed it. (together with the git) In my settings.gradle file changed: id "org.jetbrains.kotlin.android" version "1.8.20" apply false in
id "org.jetbrains.kotlin.android" version "1.7.10" apply false

this gave me errors in the form of:

 e: C:....../recaptcha.proto.mobile_webview_sdk_kt_proto_lite.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.9.0, expected version is 1.7.1.
e: C:....../jetified-recaptcha-18.4.0-api.jar!/META-INF/third_party.java_src.protobuf.current.java.com.google.protobuf.kotlin_only_for_use_in_proto_generated_code_its_generator_and_tests.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.9.0, expected version is 1.7.1.
e: C::....../jetified-recaptcha-18.4.0-api.jar!/META-INF/third_party.java_src.protobuf.current.java.com.google.protobuf.kotlin_shared_runtime.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.9.0, expected version is 1.7.1.
e: C:....../jetified-play-services-measurement-api-21.5.1-api.jar!/META-INF/java.com.google.android.gmscore.integ.client.measurement_api_measurement_api.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.9.0, expected version is 1.7.1.

So I think I have to be on a newer kotlin version to get my app working.

In the new flutter version you had to change some gradle files to get it compatible with the new flutter version.

Maybe you can see what is wrong if I post them here:

settings.gradle

 pluginManagement {
    def flutterSdkPath = {
        def properties = new Properties()
        file("local.properties").withInputStream { properties.load(it) }
        def flutterSdkPath = properties.getProperty("flutter.sdk")
        assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
        return flutterSdkPath
    }
    settings.ext.flutterSdkPath = flutterSdkPath()

    includeBuild("${settings.ext.flutterSdkPath}/packages/flutter_tools/gradle")

    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
    }
}

plugins {
    id "dev.flutter.flutter-plugin-loader" version "1.0.0"
    id "com.android.application" version '8.2.2' apply false
    id 'com.android.library' version '8.2.2' apply false
    id "org.jetbrains.kotlin.android" version "1.7.10" apply false
    id "com.google.gms.google-services" version "4.4.0" apply false
    id "com.google.firebase.crashlytics" version "2.9.9" apply false
    id 'org.gradle.toolchains.foojay-resolver-convention' version '0.7.0'
}

include ":app"

in my build.gradle:;

plugins {
    id "com.android.application"
    id "kotlin-android"
    id "dev.flutter.flutter-gradle-plugin"
    id "com.google.gms.google-services"
    id "com.google.firebase.crashlytics"
}

dependencies {
    implementation 'com.google.android.material:material:1.11.0'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test:runner:1.5.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
    implementation 'com.google.firebase:firebase-analytics:21.5.1'
    implementation 'com.google.firebase:firebase-auth:22.3.1'
    coreLibraryDesugaring('com.android.tools:desugar_jdk_libs:2.0.4')
    implementation 'com.google.android.gms:play-services-auth:21.0.0'
    implementation 'com.google.firebase:firebase-messaging:23.4.1'
    implementation 'androidx.window:window:1.2.0'
    implementation 'androidx.window:window-java:1.2.0'
    implementation('com.google.firebase:firebase-auth') {
        exclude module: "play-services-safetynet"
}
    constraints { implementation('com.stripe:financial-connections') { version { strictly '20.11.0' } } }
}

I'm not very skilled in kotlin/gradle so if I make some ugly mistakes, I'm happy to learn

mtallenca commented 8 months ago

I downgraded Kotlin version in this branch to 1.7.10, can somebody check if that fixes the issue?

  emoji_picker_flutter:
    git:
      url: https://github.com/Fintasys/emoji_picker_flutter.git
      ref: downgrade-kotlin

This fix works.

Last week we moved our project to 1.9.22 to get emoji_picker_flutter to compile our production app that uses 100+ packages with 600k android installs. Moving to 1.9.22, Gradle 7 produced warnings of mixing old java with java 17 (used by 1.9.22). Fyi these warnings are defaulted to errors in Gradle 8.

Our user perceived crash rate had been in the normal range of 0.15%. Updating our user base to the 1.9.22 build the crash rate began climbing, hit 6% within 2 days. 99.9% of the crashes were in android library code when resuming the app from background.

Crash rate did not change with the our 500k iOS users. So we looked at android specific changes between releases.

We created a fork of emoji_picker_flutter setting kotlin to 1.7.10 and reverted our project back to 1.7.10. The java old/new mix warnings go away. We released this version of the app 2 days ago and crash rate has been restored to sub 0.15%.

Again reverting emoji_picker_flutter to 1.7.10 fixes the build and crash issues we were seeing.

RasmusGrift96 commented 8 months ago

https://github.com/flutter/flutter/issues/125181#issuecomment-1555034383

Doing this worked for me, even for emoji_picker_flutter: ^2.1.0

Not sure what the issue is.,

MBilalMurtaZa commented 8 months ago

I had the same issue after I upgraded Flutter SDK today. Could you please try if adding the below line to android/gradle.properties works for you?

kotlin.jvm.target.validation.mode=IGNORE

https://stackoverflow.com/questions/77520506/inconsistent-jvm-target-compatibility-detected-for-tasks-despite-already-definin

working for me

RasmusGrift96 commented 8 months ago

I had the same issue after I upgraded Flutter SDK today. Could you please try if adding the below line to android/gradle.properties works for you?

kotlin.jvm.target.validation.mode=IGNORE

https://stackoverflow.com/questions/77520506/inconsistent-jvm-target-compatibility-detected-for-tasks-despite-already-definin

working for me

Nice, This seems to work as well.

GleammerRay commented 8 months ago

Hello @Fintasys !

Yours is a lovely package, but I was having the same issue.

I decided to look into the error and have found following direct instructions from it to be the solution for me.

Before looking into what I did, here's the outline of my project configuration:

This might not be relevant if you're on gradle 7..., however, new Gradle requires that every package defines a namespace under android. I couldn't be bothered to facilitate this in an orderly fashion so I worked around this by changing my android level build.gradle's subprojects from:

subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}

To:

subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
    afterEvaluate { project ->
        if (project.hasProperty('android')) {
            project.android {
                if (namespace == null) {
                    namespace project.group
                }
            }
        }
    }
}

Personally I've been having some issues with R8 minification (Missing classes detected while running R8). I fixed that by copying generated rules from build/app/outputs/mapping/release/missing_rules.txt into android/app/proguard-rules.pro and configuring the proguard file in my app level build.gradle via proguardFiles 'proguard-rules.pro' under android.buildTypes.release.

Important changes I've made to my project are at https://github.com/GlitterWare/Passy/commit/6bd7707b1faba45b98eeef7ef541f5b230a4b3b8 and https://github.com/GlitterWare/Passy/commit/addf7a076ce85e3559a353da9efa45083c8b9420.

You can find the exact project I was building at https://github.com/GlitterWare/Passy/commit/413961c9a7b155facb921094f65ed9a8a82fe593. Feel free to clone this commit and test it out on your end.

Now onto changes I've made to your package:

It seems that, for some reason, the default value for android.kotlinOptions.jvmTarget has been changed to 17. For this reason, it needs to be manually set back to 1.8. To avoid similar problems in the future, I've also changed the version in compileOptions, just like what you did on your fix branch (this is not the cause of current problem but it might become important in the future).

Here's what your project's build.gradle file looks like on my branch:

...
android {
    compileSdkVersion 34

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }
    ...
}
...

I have created a pull request over at https://github.com/Fintasys/emoji_picker_flutter/pull/192, merge it if it works for you.

Thank you once again for providing this package, it is a wonderful addition to my application.

GleammerRay commented 8 months ago

Hello @jerryrox @RasmusGrift96 @MBilalMurtaZa , I'm aware that the issue is "fixed" on your end but it would be greatly appreciated if you could try the fork I've created at https://github.com/GlitterWare/emoji_picker_flutter . This will both assist the maintainer in asserting correct behavior across projects and might help you avoid future problems caused by ignoring this error.

I can confirm correct behavior across 2 independent Flutter projects with different Gradle versions (8.0-all and 7.6.3-all).

To do so, remove the line that you have added earlier to ignore the error and replace the emoji_picker_flutter dependency with

  emoji_picker_flutter:
    git:
      url: https://github.com/GlitterWare/emoji_picker_flutter
      ref: ba7e1116380e37bb3fac0d53277dd6937d8849d5

Thank you!

RasmusGrift96 commented 8 months ago

Hello @jerryrox @RasmusGrift96 @MBilalMurtaZa , I'm aware that the issue is "fixed" on your end but it would be greatly appreciated if you could try the fork I've created at https://github.com/GlitterWare/emoji_picker_flutter . This will both assist the maintainer in asserting correct behavior across projects and might help you avoid future problems caused by ignoring this error.

I can confirm correct behavior across 2 independent Flutter projects with different Gradle versions (8.0-all and 7.6.3-all).

To do so, remove the line that you have added earlier to ignore the error and replace the emoji_picker_flutter dependency with

  emoji_picker_flutter:
    git:
      url: https://github.com/GlitterWare/emoji_picker_flutter
      ref: ba7e1116380e37bb3fac0d53277dd6937d8849d5

Thank you!

Deleted the line from the gradle.properties which I added before: kotlin.jvm.target.validation.mode=IGNORE

Added to my pubspec.yaml:

emoji_picker_flutter:
    git:
      url: https://github.com/GlitterWare/emoji_picker_flutter
      ref: ba7e1116380e37bb3fac0d53277dd6937d8849d5

Worked for me!!

Nice job :)

Fintasys commented 8 months ago

@GleammerRay I just merged your PR, when I realized we already have this line in package build.gralde

    if (project.android.hasProperty("namespace")) { namespace 'com.fintasys.emoji_picker_flutter' }

The explicit namespace declaration of your PR should not be required, so I removed it again.

GleammerRay commented 8 months ago

we already have this line in package build.gralde

Oh whoops, my bad, I haven't noticed that. This way of declaration might be more efficient indeed. 😅

Fintasys commented 8 months ago

Just published 2.1.1 to pub.dev, please check and let me know if we can close this issue 🙏

hagen00 commented 8 months ago

@Fintasys You should close this issue. I can confirm it's fixed.

Unrelated, I had another build error. My settings.gradle needed updating and the plugins block now looks like this:

plugins {
    id "dev.flutter.flutter-plugin-loader" version "1.0.0"
    id "com.android.application" version "7.3.0" apply false
    id "org.jetbrains.kotlin.android" version "1.9.23" apply false
}

Many thanks for your work on this plugin. Much appreciated. And thanks to @GleammerRay for the fix.