Skip to content

Gradle build error when building in android studio #1157

Closed

Description

@kkalera

Hi, I wanted to try out the android demo app but I'm getting the following error when building:


Information:Gradle tasks [:app:assembleDebug]
Error:Uncaught translation error: com.android.dx.cf.code.SimException: signature-polymorphic method called without --min-sdk-version >= 26
Error:1 error; aborting
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: java.lang.RuntimeException: java.lang.RuntimeException: Unable to pre-dex 'C:\Users\Kalera\.gradle\caches\modules-2\files-2.1\com.graphhopper\graphhopper-core\0.9.0\963667d1bcedee2656b9891aa6069a95e2e7b4cf\graphhopper-core-0.9.0.jar' to 'C:\Users\Kalera\Desktop\graphhopper-master\android\app\build\intermediates\transforms\dex\debug\folders\1000\10\graphhopper-core-0.9.0_1faaa0ecde7189cc3a7428820cb9955817078d04'
Information:BUILD FAILED
Information:Total time: 6.872 secs
Information:3 errors
Information:0 warnings
Information:See complete output in console

I have tried switching the version from 0.10-SNAPSHOT to 0.9 but without any luck.
Cleaning and rebuilding the project also do not solve the issue.

Activity

  1. karussell commented on Sep 18, 2017

    @karussell
    Member

    See this issue comment: #1144 (comment)

    If you know the underlying reason and how to fix this - would love to hear about it.

  2. ChristophKaser commented on Oct 4, 2017

    @ChristophKaser
    Contributor

    I also encountered this error and think I have found the cause of it.
    Apparently, the newest version of the android build tools do not like the call to MethodHandle.invoke in com.graphhopper.util.Helper#cleanMappedByteBuffer

    If I comment out the code depending on Constants.JRE_IS_MINIMUM_JAVA9, I can use the built jar in an android project. If I leave it in, it results in the error above.

    I think changing the code to use "old-school" reflection would fix the issue.

  3. karussell commented on Oct 4, 2017

    @karussell
    Member

    Interesting! Thanks for the update!

    I think changing the code to use "old-school" reflection would fix the issue.

    What do you mean here?

  4. ChristophKaser commented on Oct 4, 2017

    @ChristophKaser
    Contributor

    I meant instead of this:
    MethodHandle unmapper = MethodHandles.lookup().findVirtual(unsafeClass, "invokeCleaner", MethodType.methodType(void.class, ByteBuffer.class));
    Using something like this:
    Method unmapper = unsafeClass.getDeclaredMethod("invokeCleaner")

    I have to admit that I have not tried it though.

  5. karussell commented on Oct 4, 2017

    @karussell
    Member

    Strange, as e.g. MethodHandle was introduced in Android API level 26 - exactly where the problems seems to start!

  6. ChristophKaser commented on Oct 4, 2017

    @ChristophKaser
    Contributor

    I think that is the point of the build error: It checks whether MethodHandles are used in a project that does not target API level 26.

  7. karussell commented on Oct 4, 2017

    @karussell
    Member

    But why is this error not raised when using API level <26 and why does it work on older phones at all?

  8. ChristophKaser commented on Oct 4, 2017

    @ChristophKaser
    Contributor

    it is not raised when using build tools < 26 - which is not the same as the API level.

    I am speculating a bit here, but this is how I see it:
    When MethodHandle was introduced in API level 26, a check was added to the newest build tools version (also 26 - probably by design, but this does not mean that the build tools only build for API level 26) to check whether they were used in a project that does not target the necessary API level.

    why does it work on older phones at all?

    Because the code is not executed on android at all - it is only executed for Java 9 (check for Constants.JRE_IS_MINIMUM_JAVA9). However, the build tools can't detect that.

  9. karussell commented on Oct 4, 2017

    @karussell
    Member

    Thanks, this makes 100% sense!

  10. added this to the 0.10 milestone on Oct 11, 2017
  11. devemux86 commented on Nov 1, 2017

    @devemux86
    Contributor

    Android Studio 3 release (Gradle 4, Android plugin 3, SDK 27) shows immediately the issue, as cannot use GraphHopper without commenting the aforementioned code.
    (see PR #1205 for the latest Android update)

    According to documentation:

    Desugar currently doesn't support MethodHandle.invoke or MethodHandle.invokeExact. If your source code or one of your module dependencies use one of these methods you need to specify minSdkVersion 26 or higher. Otherwise, you get the following error:

    Dex: Error converting bytecode to dex:
    Cause: signature-polymorphic method called without --min-sdk-version >= 26
    

    In some cases, your module may not be using the invoke or invokeExact methods even when they're included in a library dependency. So, to keep using that library with minSdkVersion 25 or lower, enable code shrinking to remove unused methods. If that doesn't work, consider using an alternative library that doesn't use the unsupported methods.

  12. ChristophKaser commented on Nov 2, 2017

    @ChristophKaser
    Contributor

    I just added a PR (#1207) that fixes this issue for the android build and still works in Java 9.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions