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

Version 5.0.0 + Android fails with: Cannot inline bytecode built with JVM target 11 #488

Open
bvschaik opened this issue Jul 18, 2023 · 7 comments

Comments

@bvschaik
Copy link

Android projects still use JVM target 1.8 due to device constraints; the gradle file therefore contains:

android {
    ...
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
}

Upgrading mockito-kotlin from 4.1.0 to 5.0.0 causes the following compile error on any mock/whenever/etc call:

Cannot inline bytecode built with JVM target 11 into bytecode that is being built with JVM target 1.8. Please specify proper '-jvm-target' option

JVM target 11 is nowhere to be found in the Gradle files.

Steps to reproduce:

  1. Clone minimal example project: https://github.com/bvschaik/mockito-kotlin-error
  2. Try to run unit tests: ./gradlew testDebugUnitTest
  3. Note compile errors

If you downgrade mockito-kotlin to 4.1.0, the project compiles and runs successfully.

If mockito-kotlin no longer supports JVM 1.8, that should've been noted in the changelog.

@argenkiwi
Copy link

Does this mean we are stuck with v4.x for Android development for the foreseeable future?

@TimvdLippe
Copy link
Contributor

The drop of compatibility is listed on mockito-core in its release notes combined with the rationale: https://github.com/mockito/mockito/releases/tag/v5.0.0

If you still need to support Java 8, you can keep on using Mockito 4. Nothing should break there.

@naitaku
Copy link

naitaku commented Sep 20, 2023

I was unaware that Mockito 5 no longer offers support for Java 8. Does this imply that for Android projects, the jvmTarget should now be set to VERSION_11? It seems to be supported with Android Gradle Plugin 7.0.
https://developer.android.com/build/releases/past-releases/agp-7-0-0-release-notes#java-11

If that's the case, would it be advisable to include a note in the Readme.md specifically for Android developers regarding this change?

@TimvdLippe
Copy link
Contributor

Yes that is indeed now required. Feel free to send me a PR with a README update on the version similar to what we have in the README of mockito-core.

@wiryadev
Copy link

i have set jvmtarget and compatibility in compileoptions to Java 11 but the problem still exists

@naitaku
Copy link

naitaku commented Sep 21, 2023

@wiryadev, would it be possible for you to share an example project that demonstrates the issue you're encountering?

The project linked at the beginning of this issue, https://github.com/bvschaik/mockito-kotlin-error, was resolved by adjusting the compile options to use JVM 11.

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_11
        targetCompatibility JavaVersion.VERSION_11
    }
    kotlinOptions {
        jvmTarget = '11'
    }

@wiryadev
Copy link

@wiryadev, would it be possible for you to share an example project that demonstrates the issue you're encountering?

The project linked at the beginning of this issue, https://github.com/bvschaik/mockito-kotlin-error, was resolved by adjusting the compile options to use JVM 11.

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_11
        targetCompatibility JavaVersion.VERSION_11
    }
    kotlinOptions {
        jvmTarget = '11'
    }

unfortunately it is not possible currently to create sample project for that nor that it is possible to share my office work project. I choose to just downgrade to 4.1.0. My current assumption is this happens because of some dependency that i use is compiled against Java 8.

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

No branches or pull requests

5 participants