0

I've already tried multiDexEnabled true and changing the minSdkVersion 18 and compileSdkVersion 26 and it didm't work.

The library that is causing the error is:

'libs/httpmime-4.5.5.jar'

I've also tried with multiple versions of mime, the 4.0 and 4.1 doesn't give an error but it doesn't have the MultipartEntityBuilder so I can't use it, and after 4.2 it give me the error

Error:Execution failed for task 
:app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> java.lang.RuntimeException: java.lang.RuntimeException: 
com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

when building.

my gradle file is:

Edit: change Gradle

            apply plugin: 'com.android.application'

            android {
                compileSdkVersion 26
                buildToolsVersion '26.0.2'
                useLibrary  'org.apache.http.legacy'
                defaultConfig {
                    applicationId "ags.ventas"
                    minSdkVersion 18
                    multiDexEnabled true
                    targetSdkVersion 26
                    versionCode 1
                    versionName "1.0"
                    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
                    vectorDrawables.useSupportLibrary = true
                }
                buildTypes {
                    release {
                        minifyEnabled false
                        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
                    }
                }
                productFlavors {
                }
            }

            dependencies {
                implementation 'com.android.support:recyclerview-v7:26.1.0'
                compile fileTree(include: ['*.jar'], dir: 'libs')
                androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
                    exclude group: 'com.android.support', module: 'support-annotations'
                })
                debugCompile 'com.amitshekhar.android:debug-db:1.0.1'
                // HTTP requests
                compile 'com.android.support:appcompat-v7:26.1.0'
                // Google Services
                compile 'com.google.android.gms:play-services-maps:11.6.0'
                compile 'com.google.android.gms:play-services-location:11.6.0'
                compile 'com.android.support.constraint:constraint-layout:1.0.2'
                compile 'com.android.support:design:26.1.0'
                compile 'com.android.support:cardview-v7:26.1.0'
                compile 'com.android.support:support-vector-drawable:26.1.0'
                compile 'com.android.volley:volley:1.0.0'
                compile 'com.android.support:support-v4:26.1.0'
                testCompile 'junit:junit:4.12'
                compile 'org.igniterealtime.smack:smack-android-extensions:4.2.0'
                compile 'org.igniterealtime.smack:smack-android:4.2.0'
                compile 'org.igniterealtime.smack:smack-experimental:4.2.0'
                compile 'org.igniterealtime.smack:smack-tcp:4.2.0'
                compile 'org.igniterealtime.smack:smack-im:4.2.0'
                compile 'org.igniterealtime.smack:smack-sasl-provided:4.2.0'
                implementation('org.apache.httpcomponents:httpmime:4.5.5') {
                    exclude group: 'org.apache.httpcomponents', module: 'httpclient'
                }
            }

            repositories {
                maven {
                    url 'https://oss.sonatype.org/content/repositories/snapshots'
                }
                mavenCentral()
            }

Edit:

I don't know why but gradle finaly show the error

Error:Error converting bytecode to dex:
Cause: com.android.dex.DexException: Multiple dex files define 
Lorg/apache/http/entity/mime/content/StringBody;

Edit 2

I found the solution, is not the cleanest but works

Getting NoSuchFieldError INSTANCE org/apache/http/message/BasicHeaderValueParser

I'm using the this lib: https://code.google.com/p/httpclientandroidlib/ Is the same as the other but with different package name.

Thanks to all.

Fransebas
  • 321
  • 4
  • 10
  • Does dex tell you anything more if you add the `--stacktrace` flag to your build command? Also, which version of the Android Gradle Plugin are you using? – Cliabhach Feb 02 '18 at 00:48
  • Maybe --stacktrace will tell my what I need to know thanks – Fransebas Feb 02 '18 at 04:32

2 Answers2

0

May be this can help you

configurations.all {
resolutionStrategy.dependencySubstitution {
    substitute module('org.apache.commons:commons-io:1.3.2') with module('commons-io:commons-io:1.3.2')
} }

in your build.gradle and the rebuild your project

Nandha
  • 375
  • 3
  • 23
0

First, you don't need the following dependency and need to remove it:

compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'

because you're already using the http library by adding the following:

useLibrary  'org.apache.http.legacy'

Then, you need to use aar from maven instead of jar for the httpmime. You also need to exclude httpclient from httpmime:

// don't use this!!
//implementation files('libs/httpmime-4.5.5.jar')

// use this instead.
implementation('org.apache.httpcomponents:httpmime:4.5.5') {
    exclude group: 'org.apache.httpcomponents', module: 'httpclient'
}
ישו אוהב אותך
  • 28,609
  • 11
  • 78
  • 96
  • 1
    @Fransebas Your need to also remove the jar files because this line still compiled them. `compile fileTree(include: ['*.jar'], dir: 'libs')` – OneCricketeer Feb 02 '18 at 05:38