Reputation: 471
I am developing a ChatBot android application for which I wanted to use Apache OpenNLP library. I have followed this tutorial to download and use OpenNLP. After downloading the zip files, I was told to add 2 jar files to Android Studio as libraries which I have done. Then I have added the compile options to the build.gradle file of the modules directory. When I tried running the app, I got a Gradle Build error as following
> Error:Error converting bytecode to dex:
Cause: Dex cannot parse version 52 byte code.
This is caused by library dependencies that have been compiled using Java 8 or above.
If you are using the 'java' gradle plugin in a library submodule add
targetCompatibility = '1.7'
sourceCompatibility = '1.7'
to that submodule's build.gradle file.
Then I have added the following lines to my gradle file
compileOptions{
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
After doing this, when I try to run the code. I get this failed gradle sync
Error:Jack is required to support java 8 language features. Either enable Jack or remove sourceCompatibility JavaVersion.VERSION_1_8.
Error:Jack is required to support java 8 language features. Either enable Jack or remove sourceCompatibility JavaVersion.VERSION_1_8.
Then I add the following to my gradle file inside the defaultConfig block
jackOptions{
enabled true
}
After this when I try to run my app, I get the maximum number of errors
Error:Lambda coming from jar file need their interfaces on the classpath to be compiled, unknown interfaces are java.io.FileFilter
Error:Lambda coming from jar file need their interfaces on the classpath to be compiled, unknown interfaces are java.io.FileFilter
Error:Lambda coming from jar file need their interfaces on the classpath to be compiled, unknown interfaces are java.io.FileFilter
Error:Default method void updateAdaptiveData(java.lang.String[] tokens, java.lang.String[] outcomes) not supported in Android API level less than 24
Error:Default method void clearAdaptiveData() not supported in Android API level less than 24
Error:Default method void reset() not supported in Android API level less than 24
Error:Default method void close() not supported in Android API level less than 24
Error:Execution failed for task ':app:transformClassesWithPreJackPackagedLibrariesForDebug'.
> com.android.build.api.transform.TransformException: com.android.builder.core.JackToolchain$ToolchainException: Jack compilation exception
Could anyone please tell me what to do? I would like to be able to use OpenNLP methods in my application. I have tried cleaning and rebuilding but in vain.
Upvotes: 2
Views: 2399
Reputation: 21
I have created an example repository on how to use OpenNLP in Android, you can refer here: https://github.com/duckyngo/OpenNLP-Android-Example
Upvotes: 0
Reputation: 31
Below gradle changes worked fine for me. You can try out.
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
}
android {
compileSdkVersion 23
buildToolsVersion '23.0.2'
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
dependencies {
compile 'org.apache.opennlp:opennlp:1.6.0'
}
Upvotes: 3