android - 生成的签名 bundle/APK - Lint 在组装发布目标时发现 fatal error

标签 android gradle dependencies apache-httpclient-4.x

我正在尝试生成签名的 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.

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

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

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

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

19年5月11日14:54

添加其他信息,以便您更好地了解情况

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'
}

2019年8月11日10:14

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

2019年11月11日10:22

我已经创建了以下错误的副本 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;

最佳答案

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

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

而是以预期的方式提供它(“旧版”自 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 - 生成的签名 bundle/APK - Lint 在组装发布目标时发现 fatal error ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58710941/

相关文章:

android - 访问 Assets 文件夹中的视频以在 Android VideoView 中播放

android - EditText 焦点丢失

android - 如何在 flutter 中拉伸(stretch)SVG?

Gradle dist/bin/script 文件模式

python - 在 python 源/脚本中查找依赖项

visual-studio - 如何将 include/lib 目录添加到 MSVC 2015 解决方案中的所有项目?

java - AndEngine 物理示例

android - 如何加速 Android Studio 2.3 或 3?

eclipse - 如何解决 Gradle 插件依赖?

maven - 查找存储依赖项的 Maven 存储库