androidx / media

Jetpack Media3 support libraries for media use cases, including ExoPlayer, an extensible media player for Android
https://developer.android.com/media/media3
Apache License 2.0
1.59k stars 377 forks source link

Type androidx.media3.extractor.AacUtil$1 is defined multiple times #1335

Closed markg85 closed 4 months ago

markg85 commented 5 months ago

Hi,

I'm trying to build NextPlayer with a custom version of media3. So i configured my settings.gradle.kts as per the media3 instructions to include:

gradle.extra.apply {
  set("androidxMediaModulePrefix", "media-")
}
apply(from = file("/home/mark/GitProjects/android_media_exoplayer/core_settings.gradle"))

Do note that i explicitly checked out the 1.3.1 version of media3 as that's the version that nextplayer uses too. Just so that i have the least possible (hopefully) errors to solve.

Next in the project's build.gradle.kts i added the media lines that should now resolve to my local clone of media3. So like so:

    implementation(project(":media-lib-common"))
    implementation(project(":media-lib-ui"))
    implementation(project(":media-lib-exoplayer"))
    implementation(project(":media-lib-exoplayer-dash"))
    implementation(project(":media-lib-exoplayer-hls"))
    implementation(project(":media-lib-exoplayer-rtsp"))
    implementation(project(":media-lib-session"))

And i disabled their include of media3 (this line).

Note that their media3 library expands to:

media3 = ["androidx-media3-common", "androidx-media3-exoplayer", "androidx-media3-exoplayer-dash", "androidx-media3-exoplayer-hls", "androidx-media3-exoplayer-rtsp", "androidx-media3-ui", "androidx-media3-session"]

In the above implementation lines i just included the exact same libraries as they were doing in the library line.

Compiling this in debug now works just fine and my clone of media3 is used. This works for me at the moment and allows me to go further.

But the release build fails. It gives this error:

Type androidx.media3.extractor.AacUtil$1 is defined multiple times: /home/mark/GitProjects/android_media_exoplayer/libraries/extractor/build/intermediates/runtime_library_classes_jar/release/classes.jar:androidx/media3/extractor/AacUtil$1.class, /home/mark/.gradle/caches/transforms-4/b341db04655207bdc0c55db531028113/transformed/media3-extractor-1.3.1-runtime.jar:androidx/media3/extractor/AacUtil$1.class

The error comes from the "minifyReleaseWithR8":

> Task :app:minifyReleaseWithR8 FAILED
AGPBI: {"kind":"error","text":"Type androidx.media3.extractor.AacUtil$1 is defined multiple times: /home/mark/GitProjects/android_media_exoplayer/libraries/extractor/build/intermediates/runtime_library_classes_jar/release/classes.jar:androidx/media3/extractor/AacUtil$1.class, /home/mark/.gradle/caches/transforms-4/b341db04655207bdc0c55db531028113/transformed/media3-extractor-1.3.1-runtime.jar:androidx/media3/extractor/AacUtil$1.class","sources":[{"file":"/home/mark/GitProjects/android_media_exoplayer/libraries/extractor/build/intermediates/runtime_library_classes_jar/release/classes.jar"}],"tool":"R8"}

I'm guessing this is an issue on my side but i have no clue where to look or how to fix it. Or is it an issue on the media3 side? Any advice on what i should be doing to get rid of this error?

icbaker commented 4 months ago

I'm guessing this is an issue on my side but i have no clue where to look or how to fix it.

I agree with this - it sounds like you end up transitively depending on two versions of the media3 library, one from your local build and one from maven. You might know that these are built from the same source, and so should be interchangeable, but the build system can't guarantee this so defensively throws an error instead of letting runtime class resolution randomly pick one or the other version of each class (which could lead to very hard to debug errors and crashes). More info here: https://developer.android.com/build/dependency-resolution-errors#duplicate_classes

And i disabled their include of media3 (this line).

I think this line link may have drifted out of date with other commits since you posted this question? It might be clearer to use a permalink: https://docs.github.com/en/repositories/working-with-files/using-files/getting-permanent-links-to-files


I'm going to leave this issue open for a couple of weeks, but since this seems to be related to your own build set-up, rather than an issue with the media3 libraries, i'm afraid we won't be able offer much more support.

markg85 commented 4 months ago

I think this line link may have drifted out of date with other commits since you posted this question? It might be clearer to use a permalink: https://docs.github.com/en/repositories/working-with-files/using-files/getting-permanent-links-to-files

I wasn't expecting it to change that quick... It was a one-liner that read: implementation(libs.bundles.media3) now it's:

    // Media3
    implementation(libs.androidx.media3.common)
    implementation(libs.androidx.media3.exoplayer)
    implementation(libs.androidx.media3.exoplayer.dash)
    implementation(libs.androidx.media3.exoplayer.hls)
    implementation(libs.androidx.media3.exoplayer.rtsp)
    implementation(libs.androidx.media3.ui)
    implementation(libs.androidx.media3.session)
    implementation(libs.github.anilbeesetti.nextlib.media3ext)
    implementation(libs.github.anilbeesetti.nextlib.mediainfo)

The (now permanent) link: https://github.com/anilbeesetti/nextplayer/blob/1d70d728df34048c84c85988ae879151e41ff190/feature/player/build.gradle.kts#L32

But.. while typing this it struck me, or at least i think. This project (NextPlayer) includes media3 components. It also includes "NextLib", a set of extensions the player needs. Which itself also seems to be including media3.

Annoying.. Perhaps i should just try to get my change merged in media3 (it's - working - AES decryption but required one to provide the key and iv, making it not so trivial to merge). :thinking:

markg85 commented 4 months ago

This turned out to what i expected it to be but couldn't really find it before. Both projects include media3. One was local, the other was still from wherever the heck android gets it's libraries. After changing both project settings to get media3 from a local folder it all started working.

Closing.