0

I am getting this error while trying to build a debug/release apk foe my project.

.gradle/caches/8.9/generated-gradle-jars/gradle-api-8.9.jar!/META-INF/bean-serialization-services.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.6.0.

build.gradle

    ext { 
        // kotlinVersion = "2.1.0"
        kotlin_version = '2.1.0'
        buildToolsVersion = "34.0.0"
        minSdkVersion = 21
        compileSdkVersion = 34
        targetSdkVersion = 34
        ndkVersion = "23.1.7779620"
    }
    repositories {
        google()
        mavenCentral()
        jcenter()
        maven {  url "https://maven.google.com"  }
    }
    dependencies {
        classpath('com.android.tools.build:gradle:8.7.3')
        classpath("com.facebook.react:react-native-gradle-plugin")
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

plugins {
    id 'org.jetbrains.kotlin.jvm'
}
repositories {
    mavenCentral()
}
dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib"
}

subprojects {project ->
    if (project.name.contains('react-native-fetch-blob')) {
        buildscript {
            repositories {
                google()
                maven { url "https://dl.bintray.com/android/android-tools/"  }
                mavenLocal()
                jcenter()                
            }    
        }
    }
}

gradle-wrapper.properties

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

app/build.gradlew

android {
    ndkVersion rootProject.ext.ndkVersion

    compileSdkVersion rootProject.ext.compileSdkVersion

    packagingOptions {
        pickFirst 'lib/x86/libc++_shared.so'
        pickFirst 'lib/x86_64/libc++_shared.so'
        pickFirst 'lib/armeabi-v7a/libc++_shared.so'
        pickFirst 'lib/arm64-v8a/libc++_shared.so'
    }
    // dexOptions {
    //     incremental true
    //     javaMaxHeapSize "4g"
    //     }


    namespace "com.tcp_socket_app_test"

    defaultConfig {
        applicationId "com.tcp_socket_app_test"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName "1.0"
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include (*reactNativeArchitectures())
        }
    }
    signingConfigs {
        debug {
            storeFile file('debug.keystore')
            storePassword 'android'
            keyAlias 'androiddebugkey'
            keyPassword 'android'
        }
    }
    buildTypes {
        debug {
            signingConfig signingConfigs.debug
        }
        release {
            // Caution! In production, you need to generate your own keystore file.
            // see https://reactnative.dev/docs/signed-apk-android.
            signingConfig signingConfigs.debug
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }

    // applicationVariants are e.g. debug, release
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            // For each separate APK per architecture, set a unique version code as described here:
            // https://developer.android.com/studio/build/configure-apk-splits.html
            // Example: versionCode 1 will generate 1001 for armeabi-v7a, 1002 for x86, etc.
            def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
            def abi = output.getFilter(OutputFile.ABI)
            if (abi != null) {  // null for the universal-debug, universal-release variants
                output.versionCodeOverride =
                        defaultConfig.versionCode * 1000 + versionCodes.get(abi)
            }

        }
    }
}

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    //noinspection GradleDynamicVersion
    implementation "com.facebook.react:react-native:+"  // From node_modules

    implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.0.0")
    
    implementation 'androidx.work:work-runtime-ktx:2.7.1'

    debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
      exclude group:'com.facebook.fbjni'
    }

    debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
        exclude group:'com.facebook.flipper'
        exclude group:'com.squareup.okhttp3', module:'okhttp'
    }

    debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
        exclude group:'com.facebook.flipper'
    }

    if (hermesEnabled.toBoolean()) {
        implementation("com.facebook.react:hermes-android")
    } else {
        implementation jscFlavor
    }
}

Tried many solutions including deleteing .gradle/caches and rebuilding. Nothing works.

*** Important Note *** It start to fail when i try to bump my gradle version from 7.5 to 8.5

4
  • Can you share your application level build.gradle file? Commented Jan 2 at 6:59
  • @tomerpacific edited the question. Commented Jan 2 at 7:21
  • Have you tried updating the gradle version using the assistant (Tools-> AGP Upgrade Assistant)? Also, is the RN version you are using supporting the updated gradle version and Kotlin compiler version? Commented Jan 2 at 7:36
  • Yes I upgraded my AGP using Upgrade assistant and also upgraded my kotlin version via Android studio only. Commented Jan 2 at 8:34

1 Answer 1

1

I solved it. If I change the kotlin version in node_modules/react-native-gradle-plugin/build.gradle to 2.1.0 then it suddenly works, so the problem seems to be the hardcoded version of 1.6.10 in there

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.