android-studio - Lint 在组装发布目标时发现 fatal error - minSdkVersion 26 到 21

标签 android-studio gradle android-studio-3.5

我正在尝试构建我的应用程序的签名发布 APK。该应用程序当前与 Play Store 上的 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'
        }
}

关于android-studio - Lint 在组装发布目标时发现 fatal error - minSdkVersion 26 到 21,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57761638/

相关文章:

java - '/media/disk/sdk/build-tools/19.1.0/aapt'' 以非零退出值 1 完成

由于 shrinkReleaseMultiDexComponents,Android 版本构建失败

android - 如何为不同的产品风格定义不同的依赖关系

android - 如何用 View 绑定(bind)替换 findViewById(v.getId()) ?

android - 评估根项目 'android'时发生问题。适用于org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler类型的对象

plugins - 如何在 gradle findbugs 插件中将报告的错误打印到控制台?

Android Studio 3.5无法打开以前版本的项目

android - 部署目标选项不可见并且在 Android Studio 3.5 中出现 "No Device Found"错误

android - Android Studio 中的快速文档未突出显示语法