Lint 在组装发布目标时发现致命错误 - minSdkVersion 26 到 21

Lint found fatal errors while assembling a release target - minSdkVersion 26 to 21

我正在尝试构建我的应用程序的签名版本 APK。该应用程序当前与 Play 商店中的 minSdkVersion 26 相关联,我正在尝试使其与 API 21 兼容。

当我尝试在 minSdkVersion 21 中构建签名版本 APK 时,出现致命的 lint 错误。

我已经阅读了很多关于此的现有线程,但没有任何效果,我还分析了我的整个代码,一切正常(很少有橙色警告,但没有更多的主要红色错误)。请注意,我不想使用:

android {
  lintOptions {
    checkReleaseBuilds false
    abortOnError false
  }
}

这只会绕过错误,不会解决错误...

这是我的 build.gradle:

apply plugin: 'com.android.application'
android {
    signingConfigs {
        my_signing_key {
            keyAlias ''
            keyPassword ''
            storeFile file('')
            storePassword ''
        }
    }
    compileSdkVersion 28
    defaultConfig {
        applicationId ""
        minSdkVersion 21 // used to be 26
        targetSdkVersion 28
        versionCode 9
        versionName "2.2"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            signingConfig signingConfigs.my_signing_key
        }
    }
    buildToolsVersion = '28.0.3'
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:28.0.0'    //used to be 26.1.0
    implementation 'com.android.support:design:28.0.0'  //used to be 26.1.0
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.opencsv:opencsv:4.6'    // for OpenCV
}

这是错误(从 app/build/reports/lint-results-release-fatal.html 复制粘贴):


Duplicate Platform Classes
../../build.gradle: commons-logging defines classes that conflict with classes now provided by Android. Solutions include finding newer versions or alternative libraries that don't have the same problem (for example, for httpclient use HttpUrlConnection or okhttp instead), or repackaging the library using something like jarjar.
There are a number of libraries that duplicate not just functionality of the Android platform but using the exact same class names as the ones provided in Android -- for example the apache http classes. This can lead to unexpected crashes.

To solve this, you need to either find a newer version of the library which no longer has this problem, or to repackage the library (and all of its dependencies) using something like the jarjar tool, or finally, rewriting the code to use different APIs (for example, for http code, consider using HttpUrlConnection or a library like okhttp).
Note: This issue has an associated quickfix operation in Android Studio and IntelliJ IDEA.
To suppress this error, use the issue id "DuplicatePlatformClasses" as explained in the Suppressing Warnings and Errors section.

请帮忙。另外,在你的回答中要非常非常简单和描述性,我不是计算机科学家而是地质学家,在过去的一年里我自己学会了如何将一些代码放在 Java 中来创建我的应用程序,所以我的编码理论知识极其有限。

--编辑--

我将此添加到我的 build.gradle,这样我就可以构建我的签名版本 APK:

configurations {
    all {
        exclude module: 'commons-logging'
    }
}

有人能解释一下这是做什么的吗?这是绕过错误的另一种方法还是实际上修复了错误(如我所愿)? 我还发现文件夹 java 和 res 重复/(生成),我该如何阻止这种情况发生,因为这可能是原始错误的原因?

根据消息错误和您当前的解决方案,您使用的库(com.opencsv:opencsv:4.6 上的模块 'commons-logging')和 Android图书馆。 如果您确定不使用该特定模块,则您当前的解决方案应该没问题。或者您可以通过以下方式从您使用的库(不是所有库)中删除它:

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:28.0.0'    //used to be 26.1.0
    implementation 'com.android.support:design:28.0.0'  //used to be 26.1.0
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation ('com.opencsv:opencsv:4.6')    // for OpenCV
        {
            exclude module: 'commons-logging'
        }
}