Lint在组装释放目标时发现了致命错误-minSdkVersion 26至21

时间:2019-09-02 18:59:09

标签: android-studio gradle android-studio-3.5

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

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

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

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是重复的(生成的),如何阻止这种情况的发生,因为这很可能是原始错误的原因?

1 个答案:

答案 0 :(得分:0)

从消息错误和您当前的解决方案来看,您使用的库(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'
        }
}