Monits / static-code-analysis-plugin

A plugin to simplify Static Code Analysis on Gradle. Not restricted to, but specially useful, in Android projects, by making sure all analysis can access the SDK classes.
Apache License 2.0
39 stars 12 forks source link

v2.1.5 compiled for Java8 only? #7

Closed barriosnahuel closed 8 years ago

barriosnahuel commented 8 years ago

I'm using the plugin ok but when I tried to start using Data Binding, the project synced well but gives me an error running task: :installDebug.

It seems that the plugin either has any conflicting dependency with DataBinding or it is compiled for Java8 only (but I see it's compiling for compatibility with 7

What I tested

java -version Java7

./gradlew app:installDebug

Build file '/.../app/build.gradle' line: 1

* What went wrong:
A problem occurred evaluating project ':app'.
> java.lang.UnsupportedClassVersionError: com/android/build/gradle/AppPlugin : Unsupported major.minor version 52.0

Note that DataBinding works ok in Java7.

java -version Java8

Without DataBinding

./gradlew app:installDebug

works ok! =)

With DataBinding

./gradlew app:installDebug

:app:mergeDebugAssets UP-TO-DATE
:app:transformClassesWithDexForDebug
Dex: 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.
    UNEXPECTED TOP-LEVEL EXCEPTION:
    java.lang.RuntimeException: Exception parsing classes
        at com.android.dx.command.dexer.Main.processClass(Main.java:775)
        at com.android.dx.command.dexer.Main.processFileBytes(Main.java:741)
        at com.android.dx.command.dexer.Main.access$1200(Main.java:88)
        at com.android.dx.command.dexer.Main$FileBytesConsumer.processFileBytes(Main.java:1683)
        at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
        at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
        at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
        at com.android.dx.command.dexer.Main.processOne(Main.java:695)
        at com.android.dx.command.dexer.Main.processAllFiles(Main.java:592)
        at com.android.dx.command.dexer.Main.runMonoDex(Main.java:321)
        at com.android.dx.command.dexer.Main.run(Main.java:292)
        at com.android.builder.internal.compiler.DexWrapper.run(DexWrapper.java:54)
        at com.android.builder.core.DexByteCodeConverter.lambda$dexInProcess$2(DexByteCodeConverter.java:173)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
    Caused by: com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)
        at com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:476)
        at com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406)
        at com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388)
        at com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251)
        at com.android.dx.command.dexer.Main.parseClass(Main.java:787)
        at com.android.dx.command.dexer.Main.access$1600(Main.java:88)
        at com.android.dx.command.dexer.Main$ClassParserTask.call(Main.java:1722)
        at com.android.dx.command.dexer.Main.processClass(Main.java:773)
        ... 16 more

1 error; aborting
:app:transformClassesWithDexForDebug FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: java.lang.RuntimeException: java.lang.RuntimeException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: Return code 1 for dex process

Sandbox

You can un/comment this line where I'm applying this plugin to reproduce the error. That branch is using DataBinding and works ok without applying static-code-analysis =(

jsotuyod commented 8 years ago

Ok, just tried your project and reproduced the error.

Running with -debug I see this:

00:42:23.798 [DEBUG] [com.android.build.gradle.internal.ApplicationTaskManager] processing archive /home/jmsotuyo/.gradle/caches/modules-2/files-2.1/com.android.databinding/compiler/2.2.0-alpha5/173b5ba5ec9d2a71350da24c7c239ed5a54179bb/compiler-2.2.0-alpha5.jar... 00:42:23.798 [DEBUG] [com.android.build.gradle.internal.ApplicationTaskManager] processing META-INF/... 00:42:23.798 [DEBUG] [com.android.build.gradle.internal.ApplicationTaskManager] processing META-INF/MANIFEST.MF... 00:42:23.798 [DEBUG] [com.android.build.gradle.internal.ApplicationTaskManager] processing META-INF/compiler-compileKotlin.kotlin_module... 00:42:23.798 [DEBUG] [com.android.build.gradle.internal.ApplicationTaskManager] processing META-INF/kotlin-runtime.kotlin_module... 00:42:23.798 [DEBUG] [com.android.build.gradle.internal.ApplicationTaskManager] processing META-INF/kotlin-stdlib.kotlin_module... 00:42:23.798 [DEBUG] [com.android.build.gradle.internal.ApplicationTaskManager] processing META-INF/services/... 00:42:23.808 [DEBUG] [com.android.build.gradle.internal.ApplicationTaskManager] processing META-INF/services/javax.annotation.processing.Processor... 00:42:23.811 [DEBUG] [com.android.build.gradle.internal.ApplicationTaskManager] processing NOTICE... 00:42:23.811 [DEBUG] [com.android.build.gradle.internal.ApplicationTaskManager] processing NOTICE.txt... 00:42:23.811 [DEBUG] [com.android.build.gradle.internal.ApplicationTaskManager] processing android/... 00:42:23.811 [DEBUG] [com.android.build.gradle.internal.ApplicationTaskManager] processing android/databinding/... 00:42:23.811 [DEBUG] [com.android.build.gradle.internal.ApplicationTaskManager] processing android/databinding/annotationprocessor/... 00:42:23.811 [DEBUG] [com.android.build.gradle.internal.ApplicationTaskManager] processing android/databinding/annotationprocessor/AnnotationUtil.class... 00:42:23.812 [ERROR] [org.gradle.api.Project] Dex: 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.

I opened the compiler-2.2.0-alpha5.jar, extracted android/databinding/annotationprocessor/AnnotationUtil.class and by using javap -v on it found that, unsurprisingly, it's compiled for JRE 8.

This jar is used for annotation processing, so it's not to be included on the dex. This is clearly a bug on Android's plugin 2.2.0-alpha5, and is not present in version 2.1.2.

For the time being, I recomend you switch back to Android plugin 2.1.2, and report the issue on http://b.android.com/

Remember, android-24 requires Java 8:

  • What went wrong: Execution failed for task ':app:compileDebugJavaWithJavac'.

    compileSdkVersion 'android-24' requires JDK 1.8 or later to compile.

I still can't reproduce your first error (Unsupported major.minor version 52.0 on Java 7). I'm leaving this issue open until we can reproduce it or finally dismiss it. Could you provide a sample on which Java 7 produces such output?

jsotuyod commented 8 years ago

I got to reproduce your error, it's the Android Gradle plugin itself that is built for JRE 8. Even without SCA I get that error on java 7.

So, both issues here are with Android or your setup.

Bottomline:

Solution:

jsotuyod commented 8 years ago

Android Gradle plugin 2.2.0-alpha6 has just been released, and it seems to fix this dexing issue. You could use it safely.