fluttercommunity / plus_plugins

Flutter Community Plus Plugins
BSD 3-Clause "New" or "Revised" License
1.52k stars 888 forks source link

[Question]: Getting this error with The binary version of its metadata is 1.9.0, expected version is 1.7.1. #2942

Open simhead opened 1 month ago

simhead commented 1 month ago

What is your question?

I have added android_alarm_manager_plus: ^4.0.3 to pubspec.yaml and when I run flutter build apk, I am getting this error: ''' /.pub-cache/hosted/pub.dev/android_alarm_manager_plus-4.0.3/android/src/main/kotlin/dev/fluttercommunity/plus/androidalarmmanager/AlarmBroadcastReceiver.kt: (27, 18): Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.9.0, expected version is 1.7.1. The class is loaded from /Users/peterkim/.gradle/caches/transforms-4/44f32ef92a48a9a2ea0a5cd6f6ead497/transformed/jetified-kotlin-stdlib-1.9.23.jar!/kotlin/Unit.class '''

here is my build.gradle: ''' buildscript { ext.kotlin_version = '1.9.24' repositories { google() jcenter() }

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

} '''

can someone suggest how to fix this?

Checklist before submitting a question

vbuberen commented 1 month ago

Please check plugin's requirements first and update your project accordingly: https://github.com/fluttercommunity/plus_plugins/tree/main/packages/android_alarm_manager_plus#requirements

You need to update Android Gradle Plugin version in your project.

simhead commented 1 month ago

I did followed the requirement and still getting the message. here are some details for my env: flutter --version

Flutter 3.22.0 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 5dcb86f68f (7 days ago) • 2024-05-09 07:39:20 -0500
Engine • revision f6344b75dc
Tools • Dart 3.4.0 • DevTools 2.34.3

java --version

java 17.0.7 2023-04-18 LTS
Java(TM) SE Runtime Environment (build 17.0.7+8-LTS-224)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.7+8-LTS-224, mixed mode, sharing)

android/gradle/wrapper/gradle-wrapper.properties

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
# distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-all.zip

android/build.gradle

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

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

tasks.register("clean", Delete) {
    delete rootProject.buildDir
}

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

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

android/app/build.gradle

plugins {
    id "com.android.application"
    id "kotlin-android"
    // The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
    id "dev.flutter.flutter-gradle-plugin"
}

def localProperties = new Properties()
def localPropertiesFile = rootProject.file("local.properties")
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader("UTF-8") { reader ->
        localProperties.load(reader)
    }
}

def flutterVersionCode = localProperties.getProperty("flutter.versionCode")
if (flutterVersionCode == null) {
    flutterVersionCode = "1"
}

def flutterVersionName = localProperties.getProperty("flutter.versionName")
if (flutterVersionName == null) {
    flutterVersionName = "1.0"
}

android {
    namespace = "com.example.oci_alarm_manager"
    compileSdk = flutter.compileSdkVersion
    ndkVersion = flutter.ndkVersion

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

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId = "com.example.oci_alarm_manager"
        // You can update the following values to match your application needs.
        // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
        minSdkVersion flutter.minSdkVersion
        targetSdkVersion flutter.targetSdkVersion
        // minSdkVersion 21
        // targetSdkVersion 32
        versionCode = flutterVersionCode.toInteger()
        versionName = flutterVersionName
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig = signingConfigs.debug
        }
    }
}

flutter {
    source = "../.."
}

can you tell me what's missing?

vbuberen commented 1 month ago
//     classpath 'com.android.tools.build:gradle:7.2.0'

Which version of the Android Gradle Plugin you use instead of this commented line? It needs to be at least 8.3.0.

simhead commented 1 month ago

I have tried as suggested and still getting the same error:

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

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

tasks.register("clean", Delete) {
    delete rootProject.buildDir
}

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

    dependencies {
        classpath 'com.android.tools.build:gradle:8.3.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.24"
    }
}
simhead commented 1 month ago

btw I am using macos 14.4.1

bethel-m commented 3 weeks ago

hello am getting the same error, any solutions yet

bethel-m commented 3 weeks ago

hello again, i tried this and it worked for me: i specified the kotlin version in the settings.gradle file, and i did not bother adding it again in the build.gradle file from 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.7.10" apply false } to 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.10" apply false }