java 引入jar包没编译_添加第三方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'

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值