Android studio Android Studio-程序类型已存在:org.hamcrest.CoreMatchers
我不知道为什么会出现这种错误:Android studio Android Studio-程序类型已存在:org.hamcrest.CoreMatchers,android-studio,hamcrest,monkeylearn,Android Studio,Hamcrest,Monkeylearn,我不知道为什么会出现这种错误: 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(模块:app)的依赖项为: } 主要活动:
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(模块:app)的依赖项为:
}
主要活动:
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();
}
}
}
你有什么想法吗?在我回答的另一个问题中,简单的json也有类似的问题。 我建议你对
monkeylearn java
和junit
或任何其他非google依赖项逐个执行相同的操作,我的意思是下载它们的jar文件,并将它们逐个放入libs
文件夹,找出哪个是问题所在,然后将其留在libs
文件夹中
我认为这是Android Studio或Gradle中的一个bug 我对
简单json
也有类似的问题。为此,解决方案是排除JUnit依赖项
我不是Android编程方面的专家,但我觉得奇怪的是,你将hamcrest core
排除在JUnittestImplementation
之外。我宁愿建议从外部LIB中排除可传递依赖项
对于simple json
,这是我的解决方案:
implementation('com.googlecode.json-simple:json-simple:1.1.1') {
exclude group: 'junit', module: 'junit'
}
也许你也可以对
monkeylearn java
执行相同的操作?当你尝试运行测试或运行应用程序时,是否看到此错误?当我尝试构建项目时,此错误存在。然后,无法成功构建。请尝试注释掉androidTestImplementation和testImplementation依赖项,然后重新构建项目。
implementation('com.googlecode.json-simple:json-simple:1.1.1') {
exclude group: 'junit', module: 'junit'
}