google / ExoPlayer

This project is deprecated and stale. The latest ExoPlayer code is available in https://github.com/androidx/media
https://developer.android.com/media/media3/exoplayer
Apache License 2.0
21.74k stars 6.03k forks source link

IMA extension does not work with Java 8 from 2.16.0 #9726

Closed cabhara closed 2 years ago

cabhara commented 2 years ago

Not sure if that is intended, but my Android Studio project (based on Java 1.8) won't compile with

implementation 'com.google.android.exoplayer:extension-ima:2.16.0'

It works for 2.15.1 and below.

(I'm implementing the IMA player code from https://developers.google.com/interactive-media-ads/docs/sdks/android/client-side into an existing Java project)

from the error listing:

> Task :app:checkDebugAarMetadata FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:checkDebugAarMetadata'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
   > The minCompileSdk (31) specified in a
     dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties)
     is greater than this module's compileSdkVersion (android-30).
     Dependency: androidx.core:core:1.7.0.
tonihei commented 2 years ago

I think you need to upgrade your app's compileSdkVersion to 31 because androidx.core:core:1.7.0 (which ExoPlayer depends on) has a minCompileSdk version of 31.

tpiDev commented 2 years ago

Forcing minCompileSdk with 31 is rather not solution here especially due to known Cast framework issues on Android 12.

As a workaround you can add in build.gradle:

android {
...
    defaultConfig {
        configurations.all {
            resolutionStrategy {
                force "androidx.core:core:1.6.0"
                force "androidx.core:core-ktx:1.6.0"
            }
        }
...
}
tonihei commented 2 years ago

Just to clarify - setting the compileSdkVersion is different from the targetSdkVersion and is only relevant for accessing the latest methods and should have no influence on the resulting app.

cabhara commented 2 years ago

I set the minCompileSdk to 31. Now I get the error:

Task :app:mergeDebugJavaResource FAILED

FAILURE: Build failed with an exception.

tonihei commented 2 years ago

This sounds like a generic gradle dependency problem where two of your app dependencies include the same file. Unfortunately we can't help you with that unless it's related to ExoPlayer and you are probably better off asking on StackOverflow or similar sites.

cabhara commented 2 years ago

I guess I will use exoplayer 2.15.1 for now, with that it compiles ok. Hope the google IMA example code will work with that. Thanks.

tonihei commented 2 years ago

Closing the issue for now as this seems to be an app specific gradle issue.

Koster35 commented 2 years ago

I set the minCompileSdk to 31. Now I get the error:

Task :app:mergeDebugJavaResource FAILED

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':app:mergeDebugJavaResource'.

A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade More than one file was found with OS independent path 'META-INF/annotation-experimental_release.kotlin_module'.

@cabhara I encountered this same build error with two separate projects of mine, even though we don't use the IMA extension (we use the IMA SDK standalone). I think the source of the issue is actually the new IMA sdk v3.25.1, which the ExoPlayer IMA extension library just internally upgraded to in ExoPlayer v2.16.0.

Because of that, I can trigger this error in three different ways:

I was able to resolve the build errors by upgrading our Android Gradle Plugin from v4.2.2 to v7.0.4 and changing our Java compilation version from Java 8 to Java 11.

Koster35 commented 2 years ago

@tonihei Although its not explicitly stated, Java 11 compilation seems to be required for IMA v3.25.1 -- see the sample build.gradle file here https://developers.google.com/interactive-media-ads/docs/sdks/android/client-side.

I think the ExoPlayer docs need to be updated to reflect that in one of these two places:

tonihei commented 2 years ago

I don't think Java 11 is needed by either IMA or ExoPlayer's IMA extension. IMA only added this configuration to their demo app (and the linked guide) because Android Studio's Gradle plugin version 7.0.0 and above requires Gradle to run with Java 11 for compilation (which is also the default in Android Studio since Arctic Fox). They don't actually have to declare this in their gradle file with targetCompatibility JavaVersion.VERSION_11, as you can verify by removing these lines from their sample app.

I just tested ad playback with ExoPlayer 2.16.1 (and IMA 3.25.1) in a clean app that builds using Java 8 and has only targetCompatibility JavaVersion.VERSION_1_8 defined, and everything is working just fine.

More than one file was found with OS independent path 'META-INF/annotation-experimental_release.kotlin_module'

I encountered the same problem, which you can fix by adding packagingOptions { exclude("META-INF/*.kotlin_module") } to your gradle project.

Koster35 commented 2 years ago

Thank you for the explanation!