我正在开发一个 ChatBot Android 应用程序,我想为其使用 Apache OpenNLP 库。我已经关注了这个tutorial下载并使用 OpenNLP。下载 zip 文件后,我被告知将 2 个 jar 文件作为库添加到 Android Studio 中,我已经完成了。然后我将编译选项添加到模块目录的 build.gradle 文件中。当我尝试运行该应用程序时,出现如下 Gradle Build 错误
> 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.
然后我将以下行添加到我的 gradle 文件中
compileOptions{
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
完成此操作后,当我尝试运行代码时。我收到此失败的 gradle 同步
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.
然后我将以下内容添加到 defaultConfig block 内的 gradle 文件中
jackOptions{
enabled true
}
此后,当我尝试运行我的应用程序时,出现最大数量的错误
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
谁能告诉我该怎么做吗?我希望能够在我的应用程序中使用 OpenNLP 方法。我尝试过清理和重建,但没有成功。
最佳答案
下面的 gradle 更改对我来说效果很好。 你可以尝试一下。
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'
}
关于java - 在 Android Studio 中安装并集成 Apache OpenNLP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43721672/