今天导入一个第三方播放器时,添加 "compile 'com.shuyu:GSYVideoPlayer:5.0.0-beta'"都能正常通过编译,最后运行在真机的时候出现一下错误,看的我一脸萌币。。也第一次遇到这个问题以作记录。
![](https://i-blog.csdnimg.cn/blog_migrate/69ccca0f04afb1944b470b2d6e5575b9.png)
也第一时间翻阅百度,找到好几种方法依然无果,但大概知道是什么原因,大概是因为我依赖的第三方是在java8编译的,但是我工具的只是java1.7,所以就出现了这个问题,最后修改了两个东西就完成了任务。贴出解决代码:
1.在app build.gradle中加入一下代码:
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
2.最后加入下面代码完成:
dexOptions {
preDexLibraries false
jumboMode true
javaMaxHeapSize "2g"
incremental false
}
最后贴出 build.gradle中完整代码:
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
buildToolsVersion "27.0.3"
defaultConfig {
applicationId "com.shixia.gsvideo"
minSdkVersion 16
targetSdkVersion 27
versionCode 1
versionName "1.0"
multiDexEnabled = true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
dexOptions {
preDexLibraries false
jumboMode true
javaMaxHeapSize "2g"
incremental false
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile'com.android.support:appcompat-v7:26.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
//完整版引入
compile 'com.shuyu:GSYVideoPlayer:5.0.0-beta'
}