生成的签名包/APK - Lint 在组装发布目标时发现致命错误

Generated Signed Bundle / APK - Lint found fatal errors while assembling a release target

我正在尝试生成签名的 apk,但出现以下错误:

Lint found fatal errors while assembling a release target.

To proceed, either fix the issues identified by lint or modify your build script as follows:
...
android {
    lintOptions {
        checkReleaseBuilds false
        // Or, if you prefer, you can continue to check for errors in release builds,
        // but continue the build even when errors are found:
        abortOnError false
    }
}
...

所以我开始研究如何解决这个问题并解决这个问题question,我发现了一些有用的信息。

实际上,..\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.
../../build.gradle: `httpclient` 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.

对不起,如果阅读可能很无聊,但我正在尝试逐步解释......

所以我一直在寻找,直到我被困在这个 之后。基本上建议是添加这两行代码以排除重复的 类:

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

不幸的是,有一个问题,当我再次编译应用程序时,我得到了这个我无法解决的错误:

error: cannot access ContentType
class file for org.apache.http.entity.ContentType not found

我真的认为排除httpclient模块和上面报错有联系,但我可能错了...

这些是一些有用的信息:

Android Studio 3.5.1
Build #AI-191.8026.42.35.5900203, built on September 25, 2019
JRE: 1.8.0_202-release-1483-b03 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 10 10.0

再次感谢您阅读到这里,如果您有解决方案或建议,欢迎提出!

14:54 05/11/19

添加可以让您更好地了解情况的其他信息

compileSdkVersion 28
defaultConfig {
    applicationId "com.example.app"
    minSdkVersion 22
    targetSdkVersion 28
    versionCode 2
    versionName "21.19.08.27"
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    multiDexEnabled true
}

2019 年 5 月 11 日 16:35

这里有依赖项

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.0.0'
    implementation 'androidx.recyclerview:recyclerview-selection:1.0.0'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

    implementation 'com.google.android.material:material:1.1.0-alpha07'
    implementation 'com.google.code.gson:gson:2.8.5'

    implementation 'com.williamww:silky-signature:0.1.0'
    implementation 'com.afollestad.material-dialogs:core:0.9.1.0'
    implementation 'com.weiwangcn.betterspinner:library-material:1.1.0'
    implementation 'com.weiwangcn.betterspinner:library:1.1.0'

    implementation 'org.apache.httpcomponents:httpmime:4.3.6'

    implementation 'com.ajts.androidmads.sqliteimpex:library:1.0.0'

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

10:14 08/11/2019

之前我没有提到useLibrary 'org.apache.http.legacy'

的使用

10:22 11/11/2019

我已经创建了我遇到以下错误的副本 github project

所以我的目标是能够编译和使用下面的类:

import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.InputStreamBody;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;

在应用级别添加这个 gradle

 buildTypes {
        lintOptions {
            checkReleaseBuilds false
        }
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

选项 1:

App Level gradle

buildTypes {
        release {
            lintOptions {
                disable 'MissingTranslation'
                checkReleaseBuilds false
                abortOnError false
            }
            minifyEnabled false
            signingConfig signingConfigs.release
        }
    }

选项 2:

我不建议关闭 lint 检查,它们存在是有原因的。相反,检查错误是什么并修复它。

错误报告保存到 [app module]/build/reports/lint-results-yourBuildName-fatal.html. 您可以在浏览器中打开此文件以阅读有关错误的信息。

如果Gradle能更清楚地说明错误报告的生成位置就好了。

禁用 Lint 不是解决方案;最好完全删除重复的依赖项:

implementation "org.apache.httpcomponents:httpmime:4.3.6"

而是以预期的方式提供它("legacy" 适用于 Android API 级别 >= 23):

useLibrary "org.apache.http.legacy"

请参阅 behavior changes... 或者,只需使用 HttpURLConnectionOkHttpRetrofit

org.apache.httpcomponents 也可以使用 - 但不能同时使用两个包。


为了保持导入完全相同,一个快速但肮脏的解决方法是:

implementation "org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2"

检查你的依赖,有时问题是库版本。更新库版本能够减少您在 Android

中构建 apk 的问题
android {
    lintOptions {
        checkReleaseBuilds fals
        abortOnError false
    }
}

Adding this in your App level gradle will fix the error, but later you need to find it and fix the error because lint is there for a reason.

这将修复

if your want to find out the exact error then go to following path in your project

      /app/build/reports/lint-results-release-fatal.html or 
      /app/build/reports/lint-results-release-fatal.xml

otherwise you can use 
   lintOptions {
        checkReleaseBuilds false
        abortOnError false
    }

衷心感谢所有回答问题的人。

删除 Lint 控件从来都不是一个好的解决方案,非常感谢 Martin Zeitler 我能够解决这个问题。

实践中,修改依赖我设法解决了:

useLibrary 'org.apache.http.legacy'

dependencies {

    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.0.0'
    implementation 'androidx.recyclerview:recyclerview-selection:1.0.0'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

    implementation 'com.google.android.material:material:1.1.0-alpha07'
    implementation 'com.google.code.gson:gson:2.8.5'

    implementation 'com.williamww:silky-signature:0.1.0'
    implementation 'com.afollestad.material-dialogs:core:0.9.1.0'
    implementation 'com.weiwangcn.betterspinner:library-material:1.1.0'
    implementation 'com.weiwangcn.betterspinner:library:1.1.0'

    implementation 'org.apache.httpcomponents:httpclient-android:4.3.5'

    implementation('org.apache.httpcomponents:httpmime:4.3.6') {
        exclude module: 'httpclient'
    }

    implementation 'com.ajts.androidmads.sqliteimpex:library:1.0.0'

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

题目和答案的区别如下:

implementation 'org.apache.httpcomponents:httpclient-android:4.3.5'

implementation('org.apache.httpcomponents:httpmime:4.3.6') {
    exclude module: 'httpclient'
}