Name is required.
Email address is required.
Invalid email address
Answer is required.
Exceeding max length of 5KB

exoplayer and jwplayer crash



I am using both exoplayer and jwplayer in my project.
exoplayer- to play encrypted videos
jwplayer - to play video from link

but when I am using the both libraries in build gradle I am getting the below error.

:app:transformClassesWithDexBuilderForDebug UP-TO-DATE
AGPBI: {"kind":"error","text":"Program type already present: com.google.android.exoplayer2.source.dash.BuildConfig","sources":[{}],"tool":"D8"}
:app:transformDexArchiveWithExternalLibsDexMergerForDebug FAILED
:app:buildInfoGeneratorDebug

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: C:\Users\Aadhhan\Bitbucket\Hixic New\Hixic Version Mar-2018\app\build\intermediates\transforms\dexBuilder\debug\0.jar, C:\Users\Aadhhan\Bitbucket\Hixic New\Hixic Version Mar-2018\app\build\intermediates\transforms\dexBuilder\debug\1.jar, C:\Users\Aadhhan\Bitbucket\Hixic New\Hixic Version Mar-.....

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 10s
60 actionable tasks: 9 executed, 51 up-to-date
here is my app build gradle

apply plugin: 'com.android.application'

android {
compileSdkVersion 26


defaultConfig {
applicationId "com.aadhan.videos"
minSdkVersion 16
targetSdkVersion 26
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true

javaCompileOptions {
annotationProcessorOptions {
includeCompileClasspath = true
}
}


}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}

}

dexOptions {
javaMaxHeapSize "4g"
preDexLibraries = true
}
}
android {
lintOptions {
checkReleaseBuilds false
}

}

repositories {
mavenCentral()
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:26.1.0'

implementation ('com.longtailvideo.jwplayer:jwplayer-core:+'){

}
implementation ('com.longtailvideo.jwplayer:jwplayer-common:+'){

}
// Only required if using IMA features
implementation ('com.longtailvideo.jwplayer:jwplayer-ima:+'){

}
// Only required if using Chromecast jh
implementation ('com.longtailvideo.jwplayer:jwplayer-chromecast:+'){

}

implementation ('com.google.android.exoplayer:exoplayer:2.7.2'){
force = true
}

}
apply plugin: 'com.google.gms.google-services'

sorry from my poor english, this is my first post. please help me out with the solution

5 Community Answers

Hyunjoo Kim

JW Player Support Agent  
1 rated :

Hi Roja,

This is Hyunjoo from the Android Support Team. How are you?

Our library uses Exoplayer2 v2.6.1, I see that you are trying to override the version to 2.7.2 which is probably causing the dex issues.

  1. I’ve created a sample project that worked for me while using your given build.gradle(app), the changes I made are below, but if you would also like the demo of the app, please click on this link and download the zipped file, build the app, add your license key and then run the app.
  2. I was unable to fix the JUnit test problem, but I was able to override the library version. If it’s okay with you, I would recommend using the current version, V 2.6.1.

Changes are below:

build.gradle(Project: 281-multidex)


// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
	repositories {
		jcenter()
		google()
	}
	dependencies {
		classpath 'com.android.tools.build:gradle:3.1.0'
        classpath 'com.google.gms:google-services:3.2.0'

        // NOTE: Do not place your application dependencies here; they belong
		// in the individual module build.gradle files
	}
}

allprojects {
	repositories {
		jcenter()
		google()
		maven {
            url 'https://mvn.jwplayer.com/content/repositories/releases/https://mvnrepository.com/artifact/'
        }
		maven {
			url 'https://mvn.jwplayer.com/content/repositories/releases/'
		}
	}
}

task clean(type: Delete) {
	delete rootProject.buildDir
}

build.gradle(Module:app)

apply plugin: 'com.android.application'

android {
	compileSdkVersion 26
    buildToolsVersion '27.0.3'

    defaultConfig {
		applicationId "com.jwplayer.opensourcedemo"
		minSdkVersion 16
		targetSdkVersion 26
		versionCode 1
		versionName "1.0"
		multiDexEnabled true
//		testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
		vectorDrawables.useSupportLibrary = true

		javaCompileOptions {
			annotationProcessorOptions {
				includeCompileClasspath = true
			}
		}


	}
	buildTypes {
		release {
			minifyEnabled false
			proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
		}

	}

	dexOptions {
		javaMaxHeapSize "4g"
        preDexLibraries  true
	}
    android {
        lintOptions {
            abortOnError false
    //		checkReleaseBuilds false
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

//repositories {
//	mavenCentral()
//}


configurations.all {
    resolutionStrategy {
        force "com.google.android.exoplayer:exoplayer:2.7.2"
    }
}
dependencies {
	implementation fileTree(include: ['*.jar'], dir: 'libs')
	implementation 'com.android.support:appcompat-v7:26.0.0'
	implementation 'com.android.support:design:26.0.0'
    androidTestImplementation 'junit:junit:4.12'

    implementation 'com.android.support:multidex:1.0.3'

    implementation 'com.google.android.gms:play-services-ads:11.8.0'

	implementation 'com.longtailvideo.jwplayer:jwplayer-core:+'
	implementation 'com.longtailvideo.jwplayer:jwplayer-common:+'
// Only required if using IMA features
	implementation 'com.longtailvideo.jwplayer:jwplayer-ima:+'
// Only required if using Chromecast jh
	implementation 'com.longtailvideo.jwplayer:jwplayer-chromecast:+'
//	implementation ('com.google.android.exoplayer:exoplayer:2.7.2'){
//		force = true
//	}

}
//apply plugin: 'com.google.gms.google-services'

MyApplication.java


package com.jwplayer.opensourcedemo;

import android.content.Context;
import android.support.multidex.MultiDex;
import android.support.multidex.MultiDexApplication;
import android.util.Log;
import com.longtailvideo.jwplayer.cast.CastManager;

import java.io.IOException;
public class MyApplication extends MultiDexApplication {

    private static final String MEASURE_TAG = "JWMeasure";

    @Override
    public void onCreate() {
        super.onCreate();
        Log.i(MEASURE_TAG, "" + Time.currentTime() + " MyApplication onCreate: start");

        // Initialize the CastManager.
        // The CastManager must be initialized in the Application's context to prevent
        // issues with garbage collection.
        CastManager.initialize(this);
    }
    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }
}

Please let me know if that helped!

Kind regards,

Hyunjoo
Support Team, Android
JW Player

Roja

User  
0 rated :

Hi Hyunjoo Kim, the above solution is working and build is successful. But when I am using SimpleExoPlayerView of exoplayer for playing encrypted video in my activity, app is crashing and throwing error/exception. Below is my code:

layout file:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/activity_jwplayerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white">

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/framelayout"
android:layout_width="match_parent"
android:layout_centerInParent="true"
android:layout_height="match_parent">

<fragment
android:id="@+id/playerFragment"
android:name="com.longtailvideo.jwplayer.JWPlayerFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout="@layout/jw_player_fragment_sample_layout" />

</FrameLayout>

<com.google.android.exoplayer2.ui.SimpleExoPlayerView
android:id="@+id/offlinevideoplayer"
android:layout_width="match_parent"
android:layout_centerInParent="true"
android:visibility="gone"
android:layout_height="match_parent" />

<ProgressBar
android:layout_width="wrap_content"
android:layout_centerInParent="true"
android:id="@+id/offlinevideoload"
android:visibility="gone"
android:layout_height="wrap_content" />
</RelativeLayout>

</android.support.design.widget.CoordinatorLayout>

activity:
public class VideoDetailActivity extends Activity{


@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail); // throwing error here

}

}

error:

java.lang.RuntimeException: Unable to start activity ComponentInfo{.......Activity}: android.view.InflateException: Binary XML file line #42: Binary XML file line #42: Error inflating class com.google.android.exoplayer2.ui.SimpleExoPlayerView

Caused by: android.view.InflateException: Binary XML file line #42: Binary XML file line #42: Error inflating class com.google.android.exoplayer2.ui.SimpleExoPlayerView

Caused by: android.view.InflateException: Binary XML file line #42: Error inflating class com.google.android.exoplayer2.ui.SimpleExoPlayerView
at .......Activity.onCreate(VideoDetailActivity.java:191) 
Caused by: java.lang.reflect.InvocationTargetException
at .......Activity.onCreate(VideoDetailActivity.java:191) 
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/exoplayer2/ui/R$layout;
at com.google.android.exoplayer2.ui.SimpleExoPlayerView.<init>(SourceFile:260)
at com.google.android.exoplayer2.ui.SimpleExoPlayerView.<init>(SourceFile:233)
at .......Activity.onCreate(VideoDetailActivity.java:191) 
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.exoplayer2.ui.R$layout"
on path: DexPathList[[zip file "/data/app/com.aadhan.videos-1/base.apk"....

Hyunjoo Kim

JW Player Support Agent  
0 rated :

Hi Roja,

Did you call your activity in your AndroidManifest.xml?

Caused by: java.lang.ClassNotFoundException: Didn’t find class “com.google.android.exoplayer2.ui.R$layout”
on path: DexPathList[[zip file “/data/app/com.aadhan.videos-1/base.apk”…

This error, I see here, SimpleExoPlayerView is a deprecated class, please see here: https://google.github.io/ExoPlayer/doc/reference/com/google/android/exoplayer2/ui/SimpleExoPlayerView.html

Kind regards,

Hyunjoo
Support Team, Android
JW Player

Roja

User  
0 rated :

OK, but for using PlayerView, I need to import 'com.google.android.exoplayer:exoplayer:2.7.2'
But when im importing it again throwing below error:
FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformClassesWithMultidexlistForDebug'.
> com.android.build.api.transform.TransformException: Error while generating the main dex list.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

here is my app build gradle:

apply plugin: 'com.android.application'

android {
compileSdkVersion 26
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
}
defaultConfig {
applicationId "com.aadhan.videos"
minSdkVersion 16
targetSdkVersion 26
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true

javaCompileOptions {
annotationProcessorOptions {
includeCompileClasspath = true
}
}


}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}

}

dexOptions {
// Prevent OutOfMemory with MultiDex during the build phase
javaMaxHeapSize "4g"
preDexLibraries = true
}
android {
lintOptions {
abortOnError false
}

}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildToolsVersion '26.0.1'
}
configurations.all {
resolutionStrategy {
force "com.google.android.exoplayer:exoplayer:2.7.2"
}
}
repositories {
mavenCentral()
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:26.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation 'com.android.support:design:26.1.0'
implementation 'com.android.support:support-core-utils:26.1.0'
implementation 'com.android.support:cardview-v7:26.1.0'
implementation 'com.android.support:recyclerview-v7:26.1.0'
//constraint
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation project(':supportapp')
implementation 'com.google.code.gson:gson:2.8.2'
implementation files('libs/ksoap2-android-assembly-2.6.5-jar-with-dependencies.jar')
implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'com.longtailvideo.jwplayer:jwplayer-core:+'
implementation 'com.longtailvideo.jwplayer:jwplayer-common:+'
// Only required if using IMA features
implementation 'com.longtailvideo.jwplayer:jwplayer-ima:+'
// Only required if using Chromecast jh
implementation 'com.longtailvideo.jwplayer:jwplayer-chromecast:+'
implementation 'com.android.support:multidex:1.0.1'
implementation files('libs/httpclient-4.2.3.jar')
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.10'
// Facebook Login only
implementation 'com.facebook.android:facebook-login:4.28.0'
implementation 'com.facebook.android:facebook-common:4.28.0'
implementation 'com.google.android.gms:play-services-auth:11.8.0'
implementation 'com.google.firebase:firebase-messaging:11.8.0'
// glide
implementation 'com.github.bumptech.glide:glide:3.7.0'
implementation 'com.github.paolorotolo:appintro:3.3.0'
implementation 'com.google.android.exoplayer:exoplayer:2.7.2'
}

here is my usage of playerview in layout:

<com.google.android.exoplayer2.ui.PlayerView
android:id="@+id/offlinevideoplayer"
android:layout_width="match_parent"
android:layout_centerInParent="true"
android:layout_height="match_parent" />

Thanks,

Roja

Hyunjoo Kim

JW Player Support Agent  
0 rated :

Hi Roja,

I’ve noticed you’ve put

implementation 'com.google.android.exoplayer:exoplayer:2.7.2'

in your build.grade(Module:app), that is unnecessary because you’ve already forced it here:


                configurations.all {
                   resolutionStrategy {
                      force "com.google.android.exoplayer:exoplayer:2.7.2"
                  }
                }

This is also unnecessary:


                repositories {
                        mavenCentral()
                }

You are getting the maven repo from build.gradle(Project:281-multidex)


                allprojects {
                    repositories {
                          jcenter()
		          google()
		          maven {
			          url 'https://mvn.jwplayer.com/content/repositories/releases/'
		           }
		           maven {
			           url 'https://mvnrepository.com/artifact/'
                            }
		           maven {
			           url 'https://mvn.jwplayer.com/content/repositories/releases/'
		            }
                     }
                }

Can you try going to gradle.properties and uncomment (remove the “#”):


#org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
to
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

Kind regards,

Hyunjoo
Support Team, Android
JW Player

Post Your Public Answer