skip to Main Content

I am getting below error after installing itext7:

com.android.tools.r8.a: MethodHandle.invoke and MethodHandle.invokeExact are only supported starting with Android O (--min-api 26)
implementation "com.itextpdf:itext7-core:7.1.3"

I tried following solutions but it didn’t work either:

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

In addition, I tried downgrading the version of itext to implementation "com.itextpdf:itext7-core:5.0.6" and it didn’t work either.

Can anyone help how do I resolve this issue? Thanks

2

Answers


  1. Chosen as BEST ANSWER

    Finally, this is how I solved it just by bumping up the iText version:

    implementation "com.itextpdf:itext7-core:7.1.10"
    

  2. The error message

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

    is caused by the input program using one of the methods (MethodHandle.invoke or MethodHandle.invokeExact).

    As the use of these methods are coming from the library

    implementation "com.itextpdf:itext7-core:7.1.3"
    

    the only immediate solution will be to change you min SDK (android.defaultConfig.minSdk in build.gradle) to 26. This will cause you app to only run on Android 8.0 and above.

    Alternatively, if the code paths using these APIs are not actually used by you app, then turning on R8 shrinking could also work, as then the offending code will be removed from the program during shaking.

    Finally, you can also reach out the the library developers to see if they have an Android specific version or are interesting in supporting Android by avoiding the offending APIs.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search