Android Studio - 程序类型已经存在:org.hamcrest.CoreMatchers [英] Android Studio - Program type already present: org.hamcrest.CoreMatchers

查看:27
本文介绍了Android Studio - 程序类型已经存在:org.hamcrest.CoreMatchers的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道为什么会出现这个错误:

I have no idea why this error exists:

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 (Module: app) 的依赖范围内的代码是:

My code in in the scope if dependency of build.gradle (Module: app) is:

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 时遇到了类似的问题.为此,解决方案是排除 JUnit 依赖项.

I had a similar problem with simple-json. For that the solution was to exclude the JUnit dependency.

我不是 Android 编程方面的专家,但我觉得奇怪的是您从 JUnit testImplementation 中排除了 hamcrest-core.我宁愿建议从外部库中排除传递依赖项.

I am not an expert on Android programming but I find it strange that you exclude hamcrest-core from the JUnit testImplementation. I would rather suggest to exclude transitive dependencies from external libs.

对于 simple-json 这是我的解决方案:

For simple-json this was my solution:

implementation('com.googlecode.json-simple:json-simple:1.1.1') {
    exclude group: 'junit', module: 'junit'
}

也许你可以为 monkeylearn-java 做同样的事情?

Maybe you can do the same for monkeylearn-java?

这篇关于Android Studio - 程序类型已经存在:org.hamcrest.CoreMatchers的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆