问题
I am using
com.amazon.android:exoplayer-ui:r2.5.4
in my project I just upgraded IDE to Android Studio 3.3.1.
in my build.gradle
I have below code for compile
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
While trying to build, I get this error:
Task :app:mergeExtDexDebug FAILED AGPBI: {"kind":"error","text":"Default interface methods are only supported starting with Android N (--min-api 24): void com.google.android.exoplayer2.Player$EventListener.onLoadingChanged(boolean)","sources":[{}],"tool":"D8"}
FAILURE: Build failed with an exception.
- What went wrong: Could not resolve all files for configuration ':app:debugRuntimeClasspath'. Failed to transform file 'classes.jar' to match attributes {artifactType=android-dex, dexing-is-debuggable=true, dexing-min-sdk=21} using transform DexingTransform Error while dexing.
When I change the sourceCompatibility
and targetCompatibility
to JavaVersion.VERSION_1_8
, it gets build successfully but the app crashes with following error:
E/AndroidRuntime: FATAL EXCEPTION: main Process: com.mypackage, PID: 4374 java.lang.NoSuchMethodError: No direct method (Lcom/google/android/exoplayer2/upstream/DefaultAllocator;IIJJLcom/google/android/exoplayer2/util/PriorityTaskManager;)V in class Lcom/google/android/exoplayer2/DefaultLoadControl; or its super classes (declaration of 'com.google.android.exoplayer2.DefaultLoadControl' appears in /data/app/mypackagename/base.apk:classes5.dex)
Any suggestions?
project build.gradle
buildscript {
System.properties['com.android.build.gradle.overrideVersionCheck'] = 'true'
repositories {
jcenter()
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
maven { url 'https://maven.google.com' }
google()
}
dependencies {
classpath 'com.google.gms:google-services:3.0.0'
classpath 'com.android.tools.build:gradle:3.3.1'
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
allprojects {
repositories {
jcenter()
mavenCentral()
maven { url 'https://maven.google.com' }
}
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
}
}
}
app build.gradle
buildscript {
repositories {
google()
mavenLocal()
maven { url 'https://maven.fabric.io/public' }
jcenter()
}
dependencies {
classpath 'io.fabric.tools:gradle:1.27.0'
classpath 'com.google.gms:google-services:4.2.0'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
jcenter()
maven { url 'https://maven.fabric.io/public' }
}
android {
compileSdkVersion 26
buildToolsVersion '28.0.3'
defaultConfig {
applicationId ‘myAppId’
minSdkVersion 21
targetSdkVersion 26
versionCode 31
versionName "1.3.5"
multiDexEnabled true
javaCompileOptions {
annotationProcessorOptions {
arguments = ["room.schemaLocation":
"$projectDir/schemas".toString()]
}
}
sourceSets {
androidTest.assets.srcDirs += files("$projectDir/schemas".toString())
}
}
dexOptions {
javaMaxHeapSize "6g"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
checkReleaseBuilds false
abortOnError false
}
productFlavors {
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
packagingOptions {
exclude 'META-INF/android.arch.lifecycle_runtime.version'
}
}
dependencies {
implementation 'com.android.support:recyclerview-v7:26.1.0'
implementation 'com.android.support:leanback-v17:23.1.0'
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:support-v4:26.1.0'
implementation 'com.loopj.android:android-async-http:1.4.9'
implementation 'com.google.code.gson:gson:2.2.4'
implementation 'com.google.android.gms:play-services-ads:9.8.0'
implementation 'com.github.bumptech.glide:glide:3.7.0'
implementation 'com.jakewharton:butterknife:7.0.1'
implementation 'com.makeramen:roundedimageview:2.2.1'
implementation 'com.mcxiaoke.volley:library-aar:1.0.0'
implementation 'com.android.support:support-vector-drawable:26.1.0'
implementation 'com.android.support:animated-vector-drawable:26.1.0'
implementation 'com.google.ads.interactivemedia.v3:interactivemedia:3.8.5'
implementation('com.amazon.android:exoplayer-ui:r2.5.4') {
exclude module: 'exoplayer-core'
}
api 'com.amazon.android:exoplayer-core:r2.5.4'
implementation 'com.amazon.android:exoplayer-hls:r2.5.4'
implementation 'com.amazon.android:exoplayer-dash:r2.5.4'
implementation 'com.amazon.android:extension-okhttp:r2.5.4'
implementation 'commons-net:commons-net:3.3'
implementation('android.arch.persistence.room:rxjava2:1.0.0-rc1') {
exclude group: 'com.android.support', module: 'support-compat'
exclude group: 'android.arch.persistence.room', module: 'runtime'
exclude group: 'com.android.support', module: 'support-core-utils'
}
implementation('android.arch.persistence.room:runtime:1.0.0-rc1') {
exclude group: 'com.android.support', module: 'support-compat'
exclude group: 'com.android.support', module: 'support-core-utils'
}
implementation 'android.arch.lifecycle:runtime:1.0.0-rc1'
implementation('android.arch.lifecycle:extensions:1.0.0-rc1') {
exclude group: 'com.android.support', module: 'support-compat'
exclude group: 'com.android.support', module: 'support-core-ui'
exclude group: 'com.android.support', module: 'support-core-utils'
}
annotationProcessor "android.arch.persistence.room:compiler:1.0.0-rc1"
annotationProcessor "android.arch.lifecycle:compiler:1.0.0-rc1"
annotationProcessor "com.jakewharton:butterknife:7.0.1"
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
implementation 'io.reactivex.rxjava2:rxjava:2.1.0'
}
configurations.all {
resolutionStrategy.force 'com.android.support:support-v4:26.1.0'
}
回答1:
Add below code in app level build.gradle
implementation 'com.google.android.exoplayer:exoplayer:2.7.3'
upgrade your SDK and associated lib to 28...Also upgrade your Gradle to gradle-4.10.1-all.zip
...then rebuild
app...then Invalidate Cache/Restart
from File
menu.
If still not working then add below code and follow steps of rebuild
and Invalidate Cache/Restart
implementation ('react-native-track-player') {
exclude group: 'com.google.android.exoplayer'
}
implementation 'com.google.android.exoplayer:exoplayer:2.7.3'
来源:https://stackoverflow.com/questions/54812608/nosuchmethoderror-for-com-google-android-exoplayer2-upstream-defaultallocator