添加第三方jar包后编译报错

为model添加了一个第三方的jar包,同步build的之后报错。

Error:Error converting bytecode to dex:

Cause: Dex cannot parse version 52 byte code.

This is caused by library dependencies that have been compiled using Java 8 or above.

If you are using the 'java' gradle plugin in a library submodule add

targetCompatibility = '1.7'

sourceCompatibility = '1.7'

to that submodule's build.gradle file.

大概的意思是 这个Jar包是用Java 8 打包的,但是Android Studio的默认用的JDK1.7,所以如果想使用这个jar包,

请到生成jar包的model的build.gradle中添加targetCompatibility = '1.7' sourceCompatibility = '1.7'。

一开始我理解错了,以为是在我的app的model build.gradle中添加targetCompatibility = '1.7' sourceCompatibility = '1.7'这两句,

结果加上去之后毫无效果,所以才认真理解这个error的提示内容,发现这是要求在lib生成的model中加的,然而这个第三方的jar没有源码,

所以我考虑把我的jdk设置为1.8,使用java8编译。


然而,我才发现我环境变量中配的就是java 8 ,为什么还会报这个错呢。我查了一下资料,才知道AndroidStudio要使用JAVA8必须要收到设置,

所以在build.gradle中增加了:

compileOptions{

targetCompatibility JavaVersion.VERSION_1_8

sourceCompatibility JavaVersion.VERSION_1_8

}

然后点同步,报错:

Error:Jack is required to support java 8 language features. Either enable Jack or remove sourceCompatibility JavaVersion.VERSION_1_8.

在module的defaultConfig里添加

jackOptions {

enabled true

}

再同步一下,build通过。

整个model的build.gradle:

applyplugin:'com.android.application'

android {

compileSdkVersion26

buildToolsVersion"26.0.1"

defaultConfig {

applicationId"com.soft.jgui.connmysql"

minSdkVersion21

targetSdkVersion26

versionCode1

versionName"1.0"

testInstrumentationRunner"android.support.test.runner.AndroidJUnitRunner"

jackOptions {

enabledtrue

}

}

buildTypes {

release {

minifyEnabledfalse

proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'

}

}

compileOptions{

targetCompatibility JavaVersion.VERSION_1_8

sourceCompatibility JavaVersion.VERSION_1_8

}

}

dependencies {

compile fileTree(dir:'libs',include: ['*.jar'])

androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {

excludegroup:'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'

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,142评论 25 708
  • afinalAfinal是一个android的ioc,orm框架 https://github.com/yangf...
    passiontim阅读 15,509评论 2 45
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,886评论 18 139
  • 最近在公司项目中需要利用同一套代码打包出具有不同皮肤和有一些功能差异的两个apk包,于是学习了一下Android ...
    Alexyz123阅读 15,430评论 0 14
  • 梦中与实已阔别甚久的挚友相期。在泥涩的荒野断崖游走。天气的阴湿丝毫不减昂扬兴致。一路上充满机智戏谑的问答,所...
    正午的分界阅读 341评论 0 1