Skip to content

MethodHandle.invoke and MethodHandle.invokeExact are only supported starting with Android O (--min-api 26) #7769

Closed

Description

@JordanLongstaff

Guava Version

33.4.7-jre

Description

The latest version of Guava uses MethodHandle which is only available in Android API 26 or later. My app supports API 21 at the minimum, and it uses the latest release of Guava to patch a security vulnerability, only now it won't build because Guava uses methods that are not supported in the minimum SDK version. And I have no desire to increase it in my app.

Example

Any Android app with minimum SDK version lower than 26, using the latest version of Guava, would suffice. Here's a PR build from my repo that failed:
https://github.com/JordanLongstaff/ArtemisAgent/actions/runs/14347309233/job/40219434611?pr=189

Expected Behavior

App should still build as normal.

Actual Behavior

App cannot build because of MethodHandle. See the link in the example for more info.

Packages

No response

Platforms

Android

Checklist

  • I agree to follow the code of conduct.

  • I can reproduce the bug with the latest version of Guava available.

Activity

  1. cpovirk commented on Apr 9, 2025

    @cpovirk
    Member

    Sorry, our internal toolchain must handle things differently, as we're able to build for minSdkVersion 21 there. (We should ideally set up an external test for this.) Thanks for the fast report of this. I'll look when I start work in an hour or two.

  2. self-assigned this
    on Apr 9, 2025
  3. cpovirk commented on Apr 9, 2025

    @cpovirk
    Member

    I haven't gotten the build running locally yet, though I made a little progress:

    /tmp/tmp.wPQ8gN60RZ/ArtemisAgent/keystore.properties (No such file or directory)
    

    So:

    printf '%s=X\n' keyAlias keyPassword storePassword storeFile > keystore.properties
    

    But now:

    * What went wrong:
    A problem occurred configuring project ':IAN:annotations:konsist'.
    > Failed to apply plugin 'org.gradle.software-reporting-tasks'.
       > Could not create task ':IAN:annotations:konsist:outgoingVariants'.
          > Could not create task of type 'OutgoingVariantsReportTask'.
             > Could not create an instance of type org.gradle.api.tasks.diagnostics.internal.configurations.ConfigurationReportsImpl.
                > Could not create an instance of type org.gradle.api.reporting.internal.DefaultReportContainer.
                   > Type T not present
    

    [edit: This might have been a problem running with JDK 24, specifically in combination with Kotlin (rather than Groovy)?]

    But a search got me to a PR for another Android app, which also has the problem, as you'd pointed out. I can reproduce the problem there with JAVA_HOME=$HOME/.m2/jdks/jdk-17.0.13+11 ANDROID_HOME=$HOME/android-sdk-linux ./gradlew build, so I'll iterate with that.

    As for what I'll do about this: I might just forget about using VarHandle from guava-android, instead making the code try AtomicReferenceFieldUpdater before Unsafe on the JVM. But I'll see what else I can figure out....

  4. cpovirk commented on Apr 9, 2025

    @cpovirk
    Member

    Hmm, maybe this is only an issue before AGP 7.4: http://issuetracker.google.com/issues/174733673#comment12?

    But no, the app I'm testing with is using 8.3.1: https://github.com/mathisdt/trackworktime/blob/7f38ecc8c0b1f0eb396fec94b47e1ca0cae6b085/build.gradle#L9.

    http://issuetracker.google.com/issues/174733673#comment13 suggests that the issue is fixed at the compiler level but needs a change in the plugin itself: http://issuetracker.google.com/issues/320207221.

  5. cpovirk commented on Apr 9, 2025

    @cpovirk
    Member

    I have to run my change through some further testing (both in our monorepo and against one of the AGP projects), but I expect to be able to submit it later today and hopefully even get a new release out soon after.

  6. added this to the 33.4.8 milestone on Apr 9, 2025
  7. cpovirk commented on Apr 9, 2025

    @cpovirk
    Member

    My testing against the AGP project suggests that the fix works, and I've gotten the internal code review that I need for submission. I am still waiting for the internal testing, which won't be done for at least a few hours more. Still, barring surprises, I should be able to publish a release with the fix early in my work day tomorrow.

  8. cpovirk commented on Apr 10, 2025

    @cpovirk
    Member

    There's been some trouble with the internal testing system, which has affected my multiple attempts to test my change yesterday. The owners of the system have been looking into it. I assume that it will get resolved enough that I can submit my change on Monday.

  9. JordanLongstaff commented on Apr 12, 2025

    @JordanLongstaff
    Author

    @cpovirk Just wanted to say, I greatly appreciate your efforts and your transparency in trying to fix this. 👍

  10. cpovirk commented on Apr 14, 2025

    @cpovirk
    Member

    I published Guava 33.4.8 (release notes, Maven Central) with the fix. May this be the conclusion to the last problem with this series of releases :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P1type=defectBug, not working as expected

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    ⌂ 换网址