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
Finally, this is how I solved it just by bumping up the iText version:
The error message
is caused by the input program using one of the methods (
MethodHandle.invoke
orMethodHandle.invokeExact
).As the use of these methods are coming from the library
the only immediate solution will be to change you min SDK (
android.defaultConfig.minSdk
inbuild.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.