Hep*_*tus 93 java android maven android-studio
我刚刚切换到Android Studio 2.1,当尝试编译之前正在运行的应用程序时出现此错误:
Run Code Online (Sandbox Code Playgroud)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.
我已经更新了主项目的gradle.build文件以强制生成Java 1.7代码:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
apply plugin: 'java'
sourceCompatibility = 1.7
targetCompatibility = 1.7
}
}
Run Code Online (Sandbox Code Playgroud)
我还更新了gradle.build模块,如下所示设置java版本:
android {
compileSdkVersion 19
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.abc.def"
minSdkVersion 19
targetSdkVersion 19
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
Run Code Online (Sandbox Code Playgroud)
子模块是用Maven构建的.在pom.xml文件中,我也尝试强制生成1.7代码.
我知道我正在使用一个汇编工件,它包含了从属模块,但是我没有更改任何从属模块,并且上次编译时模块生成的.jar文件运行正常.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId> <!-- maven-compiler-plugin -->
<version>2.6</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
我的问题:1)这是Android Studio 2.1问题吗?有别人看过吗?2)假设这是我的错误,并且由于错误消息没有帮助找到坏模块,是否有任何关于查找V52代码的建议?我不能在不破坏大量代码的情况下省略库.可以检查一个.jar文件来查找代码修订版吗?提前致谢.-Hephaestus
小智 87
只需使用带有Android Studio 3.0+的java 1.8并为我设置以下作品:它似乎需要最新的构建工具
classpath 'com.android.tools.build:gradle:3.0.0'
Run Code Online (Sandbox Code Playgroud)
和
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
...
//jackOptions { // DEPRECATED
//enabled true
//}
}
dexOptions {
incremental true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
Run Code Online (Sandbox Code Playgroud)
nex*_*Dev 16
如果您的模块具有非特定于Android的Java库,则应该可以:apply plugin:'java'
将它放在build.gradle文件的顶部,然后重建.
apply plugin: 'java'
apply plugin: 'jacoco'
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.11'
sourceCompatibility = 1.7
targetCompatibility = 1.7
}
Run Code Online (Sandbox Code Playgroud)
如果你使用org.jetbrains:annotation:15和retrolambda插件然后删除compile org.jetbrains:annotations:15.0你的行,build.gradle错误将消失.这个对我有用.
尝试在allprojects部分中添加到main build.gradle
tasks.withType(JavaCompile) {
sourceCompatibility = "1.7"
targetCompatibility = "1.7"
}
Run Code Online (Sandbox Code Playgroud)
或者在依赖项中添加它
sourceCompatibility = 1.7
targetCompatibility = 1.7
Run Code Online (Sandbox Code Playgroud)
在所有模块中手动
小智 7
我能够通过添加以下行来解决此问题:
jackOptions {
enabled true
}
Run Code Online (Sandbox Code Playgroud)
以defaultConfig在build.gradle文件中.
您可以在链接上遵循Java 8指南 - https://developer.android.com/guide/platform/j8-jack.html
小智 5
我对greendao-generator依赖有同样的问题.我错误地将依赖添加到我的build.gradle(compile 'org.greenrobot:greendao-generator:3.1.0')和AndroidStudio中,向我显示了相同的错误消息.
可能是因为该模块已使用Java 8编译.
所以我从build.gradle中删除了这个依赖项,所有编译都愉快地:)
| 归档时间: |
|
| 查看次数: |
83163 次 |
| 最近记录: |