3

I'm trying to generate a signed apk but I've got the following error:

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

So I started looking at how to fix the problem and hit the head against this question and I've found some useful information.

In practice, there is a file located in ..\app\build\reports\ named \lint-results-release-fatal.html containing the reason for the error:

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.

Sorry if the reading can be boring but I'm trying to explain step by step...

So I kept looking until I got stuck following this question. Basically the advice is to add these two lines of code to exclude duplicate classes:

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

Unfortunately, there is a problem, when I go to compile the app again I get this error that I can't solve:

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

I really think that the exclusion of the httpclient module and the error reported above are linked, but I could be wrong...

These are some useful information:

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

Thanks again for reading up to here and if you have a solution or a suggestion are welcome!

14:54 05/11/19

Add other information that may give you a better overview of the situation

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
}

16:35 05/11/2019

Here there are the dependencies

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

Previusly i didn't mention the utilize of useLibrary 'org.apache.http.legacy'

10:22 11/11/2019

I've created a replica of the error i'm getting on the following github project.

So my goal is to be able to compile and use the following classes:

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;
Martin Zeitler
  • 1
  • 19
  • 155
  • 216
G. Ciardini
  • 1,210
  • 1
  • 17
  • 32
  • Can you execute ./gradlew app:dependencies > dependencies.txt and check if some other components are using the httpclient plugin – Swayangjit Nov 05 '19 at 12:07
  • The Apache HTTP in the past was already bundled inside the Android Platform. Probably you are redefining the same dependency twice. Check here too: https://developer.android.com/about/versions/pie/android-9.0-changes-28#apache-p – MatPag Nov 05 '19 at 12:10
  • @Swayangjit Okay, saying that I don't know if I checked properly, since I don't know the procedure, I can tell you that the dependency `org.apache.httpcomponents: httpmime: {strictly 4.3.6}` is in the dependencies.txt file – G. Ciardini Nov 05 '19 at 13:48
  • @MatPag What do you mean by that? I tried to exclude the `exclude module: 'httpclient'` and add `` but nothing has changed! However I changed the question by adding more information! – G. Ciardini Nov 05 '19 at 13:54
  • Add your gradle dependencies. Maybe you have a problem with a dependency or an imported jar – MatPag Nov 05 '19 at 14:16
  • @MatPag As you wish :) – G. Ciardini Nov 05 '19 at 15:42
  • Try replacing the httpmime line with: `implementation ("org.apache.httpcomponents:httpmime:4.3.6") { exclude group: 'org.apache.httpcomponents', module: 'httpclient' }` – MatPag Nov 05 '19 at 15:54
  • @MatPag it does not work, the same error is returned as in the question. One thing that could affect is that the app uses `useLibrary 'org.apache.http.legacy'` – G. Ciardini Nov 05 '19 at 16:13
  • Yes probably, I would suggest you to remove all those deprecated libraries or upload a small sample with the reproducible problem on github so that we can try directly with your setup and post the link here – MatPag Nov 05 '19 at 16:19
  • @MatPag I've added the small and reproducible problem on github, check the question for the link! – G. Ciardini Nov 11 '19 at 09:28

6 Answers6

1

Disabling Lint is not a solution; better remove the duplicate dependency altogether:

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

and instead provide it in the expected way (the "legacy" applies since Android API level >= 23):

useLibrary "org.apache.http.legacy"

See behavior changes... alternatively, just use HttpURLConnection, OkHttp or Retrofit.

org.apache.httpcomponents could also be used - but not both packages at the same time.


One quick & dirty workaround, in order to keep the imports exactly the same, would be:

implementation "org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2"
Martin Zeitler
  • 1
  • 19
  • 155
  • 216
  • I'm gonna test as soon as possibile! – G. Ciardini Nov 13 '19 at 15:57
  • Hi, I'm sorry but I'm just trying it now! Currently I would like to try your little trick to solve it. It doesn't seem to work but I could be wrong, can you explain me what you did? Did you simply add the import or have you removed / replaced one? – G. Ciardini Nov 14 '19 at 15:02
  • @G.Ciardini you can only add the dependency once - while it doesn't matter if using the legacy one from the framework or whatever 3rd party version. Duplicate classes will fail and missing classes will also fail. – Martin Zeitler Nov 14 '19 at 18:43
0

Add this in app level gradle

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

  • unfortunately this does not solve the problem, it simply bypasses it! I need to upload the generated bundle to the play console, i must resolve it! – G. Ciardini Nov 05 '19 at 13:42
0

check your dependencies, sometimes the problem is the library version. the update library version is able to reduce your problem build apk in Android

Subhanshuja
  • 390
  • 1
  • 3
  • 20
0
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.

This will fix the

0
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
    }
Avinash
  • 867
  • 4
  • 11
0

A heartfelt thanks to everyone who answered to the question.

Removing the Lint controls is never a good solution and a big thanks to Martin Zeitler I was able to solve the problem.

In practice, modifying the dependencies I managed to solve it:

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

The differences between the question and the solutions are the following:

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

implementation('org.apache.httpcomponents:httpmime:4.3.6') {
    exclude module: 'httpclient'
}
G. Ciardini
  • 1,210
  • 1
  • 17
  • 32