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 · 4 comments
Open

Unknown Kotlin JVM target: 21 #2051

gqtn opened this issue Jan 17, 2025 · 4 comments

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.

@JaroslavHerber
Copy link
Contributor

If you clone the project and include the dependency "media-lib-common", you will also have the package "media-lib-common-ktx" included automatically, that forces you to setup kotlin. See build.gradle in media-lib-common:

rootProject.allprojects.forEach {
    if ((it.name.startsWith(modulePrefix.replace(':', '') + 'lib-')
                || it.name.startsWith(modulePrefix.replace(':', '') + 'test-'))
            && !it.name.endsWith('-common')) {
        evaluationDependsOn(':' + it.name)
    }
}

To avoid this, remove this file in your filesystem: ...\android-media3\libraries\common_ktx\build.gradle

@gqtn
Copy link
Author

gqtn commented Jan 20, 2025

Thank you for the answers. I understood the point. However, reading the official documentation, we have:

Using Android Studio
To develop AndroidX Media using Android Studio, simply open the project in the root directory of this repository.

Therefore, I would like to suggest you to adjust it on your side, or add this info in the documentation. Because I understand that this may cause more questions, since the project is large and not everyone is an expert in Gradle, Kotlin and Java in general, like me.

Please consider this as a suggestion.

@JaroslavHerber
Copy link
Contributor

That's true. Updating documentations is always advised. Especially when v1.6.0 is highly depended on Kotlin.

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

3 participants