Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility JavaVersion.VERSION_1_8 breaks tests #18

Closed
Takhion opened this issue Feb 23, 2014 · 10 comments
Closed

Compatibility JavaVersion.VERSION_1_8 breaks tests #18

Takhion opened this issue Feb 23, 2014 · 10 comments
Labels

Comments

@Takhion
Copy link

Takhion commented Feb 23, 2014

Adding the following to build.gradle (as suggested in the readme and being the only way to force the syntax on Android Studio):

android {
  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }
}

...Results in the following exception when trying to run unit tests in Android Studio 0.4.6:

Information:Gradle tasks [:TestApp:assembleDebug, :TestApp:assembleDebugTest]
Information:objc[31058]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/bin/java and /Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jre/lib/libinstrument.dylib. One of the two will be used. Which one is undefined.
Information:UNEXPECTED TOP-LEVEL EXCEPTION:
Information:...while parsing me/eugeniomarletti/testingtests/test/BuildConfig.class
Information:1 error; aborting
Information:1 error
Information:0 warnings
Information:Information:See complete output in console
Error:Execution failed for task ':TestApp:dexDebugTest'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
    /Applications/Android Studio.app/sdk/build-tools/android-4.4.2/dx --dex --output /Users/eugeniomarletti/Dropbox/Projects/TestingTests/TestApp/build/dex/test/debug /Users/eugeniomarletti/Dropbox/Projects/TestingTests/TestApp/build/classes/test/debug /Users/eugeniomarletti/Dropbox/Projects/TestingTests/TestApp/build/dependency-cache/test/debug
  Error Code:
    1
  Output:
    UNEXPECTED TOP-LEVEL EXCEPTION:
    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:472)
      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.processClass(Main.java:665)
      at com.android.dx.command.dexer.Main.processFileBytes(Main.java:634)
      at com.android.dx.command.dexer.Main.access$600(Main.java:78)
      at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:572)
      at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:170)
      at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)
      at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)
      at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)
      at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)
      at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)
      at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)
      at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)
      at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)
      at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)
      at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)
      at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
      at com.android.dx.command.dexer.Main.processOne(Main.java:596)
      at com.android.dx.command.dexer.Main.processAllFiles(Main.java:498)
      at com.android.dx.command.dexer.Main.runMonoDex(Main.java:264)
      at com.android.dx.command.dexer.Main.run(Main.java:230)
      at com.android.dx.command.dexer.Main.main(Main.java:199)
      at com.android.dx.command.Main.main(Main.java:103)
    ...while parsing me/eugeniomarletti/testingtests/test/BuildConfig.class
    1 error; aborting
@Takhion
Copy link
Author

Takhion commented Feb 23, 2014

I forgot to include my build.gradle, might be useful:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.8.+'
        classpath 'me.tatarka:gradle-retrolambda:1.2.+'
    }
}

allprojects {
    repositories {
        mavenCentral()
    }
}

apply plugin: 'android'
apply plugin: 'retrolambda'

android {
    compileSdkVersion 19
    buildToolsVersion '19.0.1'

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 19
        versionCode 1
        versionName '1.0'
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

retrolambda {
    jdk System.getenv('JAVA8_HOME')
    oldJdk System.getenv('JAVA7_HOME')
    javaVersion JavaVersion.VERSION_1_7
}

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

@evant
Copy link
Owner

evant commented Feb 23, 2014

Looks like I wasn't including test variants. Try with the latest SNAPSHOT version (instructions in the develop branch README).

@evant evant added the bug label Feb 23, 2014
@Takhion
Copy link
Author

Takhion commented Feb 28, 2014

Now the error has become:

Execution failed for task ':SuperTestApp:patchAndroidJar'.
> Retrolambda: "/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home"/jre/lib/rt.jar does not exist, make sure that JAVE_HOME or retrolambda.jdk points to a valid version of java8
   You can download java8 from https://jdk8.java.net/download.html

Quotes in the middle of the path?

@evant
Copy link
Owner

evant commented Mar 1, 2014

Interesting, are there quotes when you echo $JAVA8_HOME?

@Takhion
Copy link
Author

Takhion commented Mar 1, 2014

Apparently I really had quotes in there:

$ echo $JAVA8_HOME
"/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home"

I removed them and now it's perfect :)
What's really interesting is that it was working before switching to the SNAPSHOT version (except for tests)!

@evant
Copy link
Owner

evant commented Mar 3, 2014

Glad you got it working. I released 1.3.0 so you can switch to that when it syncs on maven central.

@evant evant closed this as completed Mar 3, 2014
@elvizlai
Copy link

android is not support Java8 now

@evant
Copy link
Owner

evant commented Jul 14, 2014

@elvizlai I'm not exactly sure what you mean. If you are having trouble building, can you provide any error messages you are getting? Also, please open a new issue instead of piggy-backing off of an old closed one.

@kaushikgopal
Copy link

Are the instructions mentioned here (in the SNAPSHOT) , the same as the most current version "2.1.0". I'm facing a similar issue (#32 ).

@Takhion
Copy link
Author

Takhion commented Jul 26, 2014

This is the (extremely) simple project that I used at the time to check retrolambda's compatibility with tests: https://github.com/Takhion/supertest. It's outdated and probably broken, plus it has some libraries that don't relate to retrolambda in any way, but it's worth giving a shot as at the time it was working perfectly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants