gpt4 book ai didi

java - 在 Android Studio 中安装并集成 Apache OpenNLP

转载 作者:行者123 更新时间:2023-11-29 04:31:20 26 4
gpt4 key购买 nike

我正在开发一个 ChatBot android 应用程序,我想为其使用 Apache OpenNLP 库。我已经关注了这个tutorial下载和使用 OpenNLP。下载 zip 文件后,我被告知将 2 个 jar 文件添加到 Android Studio 作为我已经完成的库。然后我将编译选项添加到模块目录的 build.gradle 文件中。当我尝试运行该应用程序时,出现如下 Gradle 构建错误

> 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 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.

然后我将以下内容添加到 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com