I cloned ExoPlayer locally and added the modules to my existing project using my settings.gradle.
gradle.ext.exoplayerRoot = 'path/to/exoplayer'
gradle.ext.exoplayerModulePrefix = 'exoplayer-'
apply from: new File(gradle.ext.exoplayerRoot, 'core_settings.gradle')
Whenever I try to build the project, I receive the following build error:
error: package android.support.annotation does not exist
These happen for all @NonNull and @Nullable annotations in the ExoPlayer modules.
build.gradle
android {
compileSdkVersion 28
def versionMajor = 1
def versionMinor = 0
def versionPatch = 0
defaultConfig {
applicationId "packagename"
minSdkVersion 23
targetSdkVersion 28
versionCode versionMajor * 10000 + versionMinor * 100 + versionPatch
versionName "${versionMajor}.${versionMinor}.${versionPatch}"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
dataBinding {
enabled = true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'com.android.support:support-annotations:28.0.0'
implementation project(':exoplayer-library-core')
}
gradle.properties
android.databinding.enableV2=true
android.useAndroidX=true
android.enableJetifier=true
Top-level build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I updated the original post with my top-level build.gradle file. The google repository is defined in both cases. I also tried it with a new, fresh project, it seems to have troubles with the Android Jetifier and AndroidX support. When I comment these out if a fresh, new project, I don't seem to have the issue.
Looking again, I don't really understand the first build.gradle. Shouldn't the dependencies at the bottom be in a
dependencies {
...
}
block?
@ojw28 They are in the dependencies block, something went wrong with c/p
@ojw28 I just created a fresh, new project and have the same issue.
Android Studio 3.2.1
build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.rootsoft.exoplayer.demo"
minSdkVersion 26
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
dataBinding {
enabled = true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:design:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation project(':exoplayer-library-core')
}
settings.gradle
gradle.ext.exoplayerRoot = '/Users/RootSoft/Projects/ExoPlayer/ExoPlayer'
gradle.ext.exoplayerModulePrefix = 'exoplayer-'
apply from: new File(gradle.ext.exoplayerRoot, 'core_settings.gradle')
include ':app'
gradle.properties
org.gradle.jvmargs=-Xmx1536m
android.databinding.enableV2=true
android.useAndroidX=true
android.enableJetifier=true
Whenever I remove the following from my gradle.properties file, it works fine:
android.useAndroidX=true
android.enableJetifier=true
@ojw28 Do you have any idea what might be wrong? I've been breaking my heads on this for the past few days. Thanks in advance!
I tried doing what you did and it works fine for me.
For some reason it seems that Jetifier does not convert the dependencies to the new AndroidX (atleast for me) for the library modules.
I managed to solve the issue by specifying a gradle.properties file for every local exoplayer module in my project that is used in the application. I still don't know what causes the issue, but preventing Jetifier from migrating to AndroidX seems to solve this issue.
# Local module Gradle settings.
android.useAndroidX=false
# Jetifier will convert support libraries of all your dependencies to AndroidX automatically,
# if you don't set it true then your project will have both support
android.enableJetifier=false
I managed to solve the issue by specifying a
gradle.propertiesfile for every local exoplayer module in my project that is used in the application. I still don't know what causes the issue, but preventing Jetifier from migrating to AndroidX seems to solve this issue.# Local module Gradle settings. android.useAndroidX=false # Jetifier will convert support libraries of all your dependencies to AndroidX automatically, # if you don't set it true then your project will have both support android.enableJetifier=false
U can use these dependencies too:
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.annotation:annotation:1.0.2'
@ray-pixar Could you explain exactly where you put those dependencies? Is it in the android-exoplayer folder under node-modules? Or somewhere else?
Most helpful comment
I managed to solve the issue by specifying a
gradle.propertiesfile for every local exoplayer module in my project that is used in the application. I still don't know what causes the issue, but preventing Jetifier from migrating to AndroidX seems to solve this issue.