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

Unknown Kotlin JVM target: 21 #2051

Open
gqtn opened this issue Jan 17, 2025 · 1 comment
Open

Unknown Kotlin JVM target: 21 #2051

gqtn opened this issue Jan 17, 2025 · 1 comment

Comments

@gqtn
Copy link

gqtn commented Jan 17, 2025

I tried to run the demo project following the documentation: I simply cloned the project and opened it in the root directory inside Android Studio, and I received the error "Unknown Kotlin JVM target: 21".

After trying to make some Gradle JDK changes — for example, changing from 21 to 17 and others — I found a solution:

  • I returned the Gradle JDK version to 21 (jbr-21 = 21.0.4)
  • I added the following code to build.gradle of the demo project:
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8
}

It looks like this:

android {
    namespace 'androidx.media3.demo.main'

    compileSdk project.ext.compileSdkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_1_8
    }

After this and sync project, I was able to run the demo project normally.

Was this some lack of knowledge on my side, or an incompatibility due to an Android Studio update (build on December 17, 2024)?

@oceanjules
Copy link
Contributor

oceanjules commented Jan 17, 2025

androidx.media3.demo.main does not have any Kotlin code and hence did not require kotlinOptions setup.

I am also on December's Ladybug
Image

I'm assuming you tried to change it to 17 here. It did seem to work for many people:

Image

Looking through this, I think many others were also confused by the need to include kotlinOptions.
https://stackoverflow.com/questions/79090643/android-studio-ladybug-unknown-kotlin-jvm-target-21

It seems like specifying jvmTarget=1.8 is also unnecessary, since it's the default value: https://kotlinlang.org/docs/gradle-compiler-options.html#attributes-specific-to-jvm

Overall, it does seem to be an Android Studio/Gradle/Java/Kotlin-related issue, rather than the Media3 library.

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

2 participants