我不知道为什么会出现此错误:
Program type already present: org.hamcrest.CoreMatchers
Message{kind=ERROR, text=Program type already present: org.hamcrest.CoreMatchers, sources=[Unknown source file], tool name=Optional.of(D8)}
如果 build.gradle(模块:应用程序(的依赖关系,我在范围内的代码是:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation ('junit:junit:4.12'){
exclude group: 'org.hamcrest', module: 'hamcrest-core'
}
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation 'com.monkeylearn:monkeylearn-java:0.1.4'
}
主要活动:
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import com.monkeylearn.MonkeyLearn;
import com.monkeylearn.MonkeyLearnException;
import com.monkeylearn.MonkeyLearnResponse;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
MonkeyLearn ml = new MonkeyLearn("*******************************");
String moduleId = "*********";
String[] textList = {"This is a text to test your classifier", "This is some more text"};
MonkeyLearnResponse res = ml.classifiers.classify(moduleId, textList, true);
System.out.println( res.arrayResult );
} catch (MonkeyLearnException e) {
e.printStackTrace();
}
}
}
你有什么想法吗?
在我在这里回答的另一个问题中,simple-json
也有类似的问题。我建议您对monkeylearn-java
和junit
或任何其他非Google依赖项一一执行相同的操作,我的意思是下载它们的jar文件并将它们一一放入libs
文件夹中,找出哪个是问题所在,并将其保留在libs
文件夹中。
我认为这是Android Studio或Gradle中的一个错误。
我在simple-json
上遇到了类似的问题。为此,解决方案是排除 JUnit 依赖项。
我不是Android编程专家,但我觉得很奇怪,您将hamcrest-core
排除在JUnit testImplementation
之外。我宁愿建议从外部库中排除传递依赖项。
对于simple-json
来说,这是我的解决方案:
implementation('com.googlecode.json-simple:json-simple:1.1.1') {
exclude group: 'junit', module: 'junit'
}
也许你可以为monkeylearn-java
做同样的事情?