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

[Bug] Building Android App Bundle fails with error Unknown Kotlin JVM target: 21 #28

Open
sunderee opened this issue Oct 11, 2024 · 1 comment

Comments

@sunderee
Copy link

Bug description

This bug occurs when I attempt to build an Android App Bundle.

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':klippa_identity_verification_sdk:compileReleaseKotlin'.
> Unknown Kotlin JVM target: 21

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

BUILD FAILED in 1s

flutter doctor output below:

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.24.3, on macOS 15.0.1 24A348 darwin-arm64, locale
    en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 16.0)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2024.2)
[✓] VS Code (version 1.94.2)
[✓] Connected device (3 available)
[✓] Network resources

• No issues found!

Possible solutions

One of the possible solutions I've found on Stack Overflow would be to declare source compatibility like so:

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

kotlinOptions {
    jvmTarget = JavaVersion.VERSION_1_8
}

It might also be useful to look into similar issues faced by official Flutter packages (example: video_player).

@sunderee
Copy link
Author

Update: was able to resolve build issues after modifying package's build.gradle file:

group 'com.klippa.identity_verification.klippa_identity_verification_sdk'
version '1.0-SNAPSHOT'

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

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

def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

rootProject.allprojects {
    repositories {
        google()
        mavenCentral()
        maven { url "https://jitpack.io" }
        maven {
            credentials {
                username System.getenv()['KLIPPA_IDENTITY_VERIFICATION_SDK_USERNAME'] ? System.getenv()['KLIPPA_IDENTITY_VERIFICATION_SDK_USERNAME'] : (keystoreProperties["klippa.identity_verification.sdk.username"] ? keystoreProperties["klippa.identity_verification.sdk.username"] : '')
                password System.getenv()['KLIPPA_IDENTITY_VERIFICATION_SDK_PASSWORD'] ? System.getenv()['KLIPPA_IDENTITY_VERIFICATION_SDK_PASSWORD'] : (keystoreProperties["klippa.identity_verification.sdk.password"] ? keystoreProperties["klippa.identity_verification.sdk.password"] : '')
            }
            url System.getenv()['KLIPPA_IDENTITY_VERIFICATION_SDK_URL'] ? System.getenv()['KLIPPA_IDENTITY_VERIFICATION_SDK_URL'] : (keystoreProperties["klippa.identity_verification.sdk.url"] ? keystoreProperties["klippa.identity_verification.sdk.url"] : 'https://custom-ocr.klippa.com/sdk/android/maven')
        }
    }
}

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

android {
    compileSdkVersion 35
    
    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    defaultConfig {
        minSdkVersion 24
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

    lintOptions {
        disable 'InvalidPackage'
    }
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    def klippaIdentityVerificationVersion = project.hasProperty('klippaIdentityVerificationVersion') ? project.klippaIdentityVerificationVersion : "0.7.5"
    implementation "com.klippa:identity_verification:$klippaIdentityVerificationVersion"
}

I don't think that upgrading compileSdkVersion from 33 to 35 is necessary.


I do not think that this is related to your package, but I additionally had to make this particular change in my android/build.gradle, and also modify the ndkVersion in android/app/build.gradle to 25.1.8937393.

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

No branches or pull requests

1 participant