lightcouch / LightCouch

CouchDB Java API
www.lightcouch.org
Apache License 2.0
67 stars 70 forks source link

IllegalArgumentException in org.apache code on Android 9 #74

Closed retrodaredevil closed 5 years ago

retrodaredevil commented 5 years ago

Recently, I upgraded to Android 9 and my app stopped working. I have tested the exact same code on a different phone with a clean install of the app on each of them and the app running on Android 9 gives this stack trace:

W/System.err: java.lang.IllegalArgumentException: Credentials may not be null W/System.err: at org.apache.http.util.Args.notNull(Args.java:54) at org.apache.http.impl.auth.BasicScheme.authenticate(BasicScheme.java:159) at org.apache.http.client.protocol.RequestAuthenticationBase.authenticate(RequestAuthenticationBase.java:120) at org.apache.http.client.protocol.RequestAuthenticationBase.process(RequestAuthenticationBase.java:99) at org.apache.http.client.protocol.RequestTargetAuthentication.process(RequestTargetAuthentication.java:82) at org.apache.http.protocol.ImmutableHttpProcessor.process(ImmutableHttpProcessor.java:133) at org.apache.http.protocol.HttpRequestExecutor.preProcess(HttpRequestExecutor.java:167) at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:484) at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:835) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56) at org.lightcouch.CouchDbClientBase.executeRequest(CouchDbClientBase.java:480) at org.lightcouch.CouchDbClientBase.get(CouchDbClientBase.java:531) at org.lightcouch.CouchDbClientBase.get(CouchDbClientBase.java:542) at org.lightcouch.CouchDbContext.serverVersion(CouchDbContext.java:122) at org.lightcouch.CouchDbContext.<init>(CouchDbContext.java:57) at org.lightcouch.CouchDbClientBase.<init>(CouchDbClientBase.java:102) at org.lightcouch.CouchDbClientAndroid.<init>(CouchDbClientAndroid.java:111) at me.retrodaredevil.solarthing.android.request.CouchDbDataRequester.requestData(CouchDbDataRequester.kt:43) The stack trace goes on below with a few more unrelated calls. I'm thinking that this isn't something I'm doing wrong because it goes through 9 org.apache calls and 7 org.lightcouch calls. If I am doing something wrong, the code should really be changed so whatever it is that's happening throws an exception sooner.

Any help would be appreciated.

lightcouch commented 5 years ago

Hi there,

which version of apache httpclient used by your app?

retrodaredevil commented 5 years ago

I am not sure. I don't think I ever explicitly imported it. Here are my dependencies. I think the only relevant thing in here is the version of LightCouch, but maybe this will help.

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.github.eidolon1138:solarthing:v1.1.1'
    // https://mvnrepository.com/artifact/org.lightcouch/lightcouch
    implementation 'org.lightcouch:lightcouch:0.2.0'
}

Should I try explicitly importing another version of apache httpclient? Will that conflict with whatever Android uses?

Now that you mention the Apache HttpClient version, my guess is that Android 9 uses a more up to date version that isn't compatible with this, but that's just a guess.

Edit: It looks like I'm running 4.4.1 or 4.5.3. While decompiling some of the source, many of the things that CouchDbClientAndroid uses in its createHttpClient is deprecated which may explain why this is failing somewhere.

lightcouch commented 5 years ago

It may be try to use the 'legacy' version of httpclient that shipped with android.

retrodaredevil commented 5 years ago

You're correct! I came across this post on stackoverflow and it fixed it with one simple line. https://stackoverflow.com/questions/50446148/how-to-use-apache-http-on-android-p

Line added inside in AndroidManifest.xml: <uses-library android:name="org.apache.http.legacy" android:required="false"/>