【问题标题】:Program type already present: org.hamcrest.CoreMatchers程序类型已经存在:org.hamcrest.CoreMatchers
【发布时间】:2018-06-19 09:59:01
【问题描述】:

当我构建我的应用程序时,我收到了跟随错误。

程序类型已经存在:org.hamcrest.CoreMatchers

Message{kind=ERROR, text=Program type already present: org.hamcrest.CoreMatchers, sources=[Unknown source file], tool name=Optional.of(D8)}

我用谷歌搜索了我的问题并喜欢类似的问题here,但无法得到正确的答案。

这是我的 build.gradle 文件

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    useLibrary 'org.apache.http.legacy'
    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
        ndk {
            ndk {
                moduleName "exec"
                abiFilters 'armeabi-v7a'
            }
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    sourceSets {
        main {
            jni.srcDirs = []
            jniLibs.srcDirs = ['libs']
            res.srcDirs = ['src/main/res']
            assets.srcDirs = ['src/main/assets']
            manifest.srcFile 'src/main/AndroidManifest.xml'
        }
    }
    configurations.all{
        resolutionStrategy.force 'org.hamcrest:hamcrest-core:1.1'
    }

}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.j256.ormlite:ormlite-core:4.41'
    implementation 'com.j256.ormlite:ormlite-android:4.41'
    implementation 'com.googlecode.json-simple:json-simple:1.1.1'
    implementation 'org.mozilla:rhino:1.7.10'
}

感谢您的帮助!

【问题讨论】:

  • 你找到解决办法了吗?
  • @sanevys 是的,我的项目在我删除此依赖项后完成构建implementation 'com.googlecode.json-simple:json-simple:1.1.1'
  • 是的,如果我删除依赖关系,它也可以工作。但我需要依赖:/
  • @sanevys 该库是处理 jsonObject ,您可以将其替换为其他库或使用 android 提供的 JSONObject。
  • 我正在尝试使用不同的库github.com/Ritaja/java-exchange-rates

标签: android android-gradle-plugin


【解决方案1】:

下载json-simple 1.1.1的jar文件,放到libs文件夹中。

并从build.gradle 中删除implementation 'com.googlecode.json-simple:json-simple:1.1.1'

我不知道为什么这会解决问题,因为我根本不知道为什么会出现这个问题。

【讨论】:

    【解决方案2】:

    就我而言,我遇到了类似的错误。

    我是通过同步我的应用程序 gradle 发现的。原来我修改了app gradle代码,并没有同步而是建了项目。

    【讨论】:

      【解决方案3】:

      我发现从 json-simple 中排除依赖的 JUnit 也可以解决这个问题:

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

      simple-json 的最新版本依赖于 JUnit 4.1,它依赖于 hamcrest-core:1.1,在我的例子中它与现有的 hamcrest-core:1.3 冲突。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-09-23
        • 2019-02-22
        • 1970-01-01
        • 2018-10-21
        • 1970-01-01
        • 2018-10-03
        • 2019-04-10
        • 2018-11-15
        相关资源
        最近更新 更多