1

I have a java maven library that I want to use in my Android app (This is the library) When I try to initiate a class like ZoldWts api = new RestfulZoldWts("key"); I get NoSuchMethodError.

java.lang.NoSuchMethodError: No direct method (Ljava/util/Collection;)V in class Lorg/apache/http/client/protocol/RequestDefaultHeaders; or its super classes (declaration of 'org.apache.http.client.protocol.RequestDefaultHeaders' appears in /system/framework/org.apache.http.legacy.boot.jar)

How did I add the library to my grade? compile 'com.amihaiemil.web:zold-java-client:0.0.1' However, I got the following error

More than one file was found with OS independent path 'META-INF/DEPENDENCIES'

I solved it by adding this to my gradle

packagingOptions {
    exclude 'META-INF/DEPENDENCIES'
}

To make sure that the library isn't broken I wrote a unit test and it runs successfully. unfortunately, the Instrumented test didn't. I tried disabling proguard by useProguard false didn't work. I also tried adding the following to my proguard rules

-keep class org/apache/http/client/protocol/.* { *; }

Still didn't work.

My gradle file:

apply plugin: 'com.android.application'

android {
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
    }
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.zold.ammar.zold_android"
        minSdkVersion 26
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0-alpha01'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'

    // Zold Java
    compile 'com.amihaiemil.web:zold-java-client:0.0.1'
}

My test code (The exact same code works in the unit test but not in the instrumented test)

@Test
public void zoldinittest() {
    ZoldWts api = new RestfulZoldWts("key");
    assertNotNull(api);
}
Ammar Hussein
  • 5,534
  • 5
  • 18
  • 37

2 Answers2

0

from here

in build.gradle android section put this code

useLibrary 'org.apache.http.legacy'

wholegroup
  • 56
  • 2
0

The problem solved by changing the version of Apache to 5.x in zold-java-client This and This issues show all the discussion, the solution is available in the version 0.0.2 of the library.

Ammar Hussein
  • 5,534
  • 5
  • 18
  • 37