在Android 9中使用org.apache.http.legacy

我有一个使用apache旧版Http库(org.apache.http.legacy)的旧android应用。在Android

6上进行更改后,我能够使该应用程序(包括旧版库)保持正常运行。

‘。

现在,在Android 9设备上,我在运行时得到以下异常。

Caused by: java.lang.IncompatibleClassChangeError: Class 'org.apache.http.conn.ssl.SSLSocketFactory' does not implement interface 'org.apache.http.conn.scheme.SchemeSocketFactory' in call to 'java.net.Socket org.apache.http.conn.scheme.SchemeSocketFactory.createSocket(org.apache.http.params.HttpParams)' (declaration of 'org.apache.http.impl.conn.DefaultClientConnectionOperator' appears in /data/app/com.theprojectfactory.wmp-RdZODaT5h-l1diSw3oNCvA==/base.apk)

at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:165)

at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:304)

at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:611)

at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:446)

at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:863)

at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)

at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:106)

at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:57)

阅读Android

9更改文档,<uses-

library android:name="org.apache.http.legacy"

android:required="false"/>在AndroidManifes.xml文件中添加了提及,但是这对我似乎也不起作用,因为在启动应用程序时出现了以下异常。

java.lang.VerifyError: Superclass org.apache.http.params.BasicHttpParams of org.apache.http.params.SyncBasicHttpParams is declared final (declaration of 'org.apache.http.params.SyncBasicHttpParams' appears in /data/app/com.theprojectfactory.wmp-R2P9RNgoJ82ZupwxVa7iNA==/base.apk)

at java.lang.Class.classForName(Native Method)

at java.lang.Class.forName(Class.java:453)

at com.activeandroid.ModelInfo.scanForModelClasses(ModelInfo.java:187)

at com.activeandroid.ModelInfo.scanForModel(ModelInfo.java:152)

at com.activeandroid.ModelInfo.<init>(ModelInfo.java:63)

at com.activeandroid.Cache.initialize(Cache.java:66)

at com.activeandroid.ActiveAndroid.initialize(ActiveAndroid.java:44)

at com.activeandroid.ActiveAndroid.initialize(ActiveAndroid.java:34)

at com.activeandroid.content.ContentProvider.onCreate(ContentProvider.java:39)

at android.content.ContentProvider.attachInfo(ContentProvider.java:1917)

at android.content.ContentProvider.attachInfo(ContentProvider.java:1892)

at android.app.ActivityThread.installProvider(ActivityThread.java:6391)

at android.app.ActivityThread.installContentProviders(ActivityThread.java:5938)

at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5853)

at android.app.ActivityThread.access$1100(ActivityThread.java:199)

at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1650)

at android.os.Handler.dispatchMessage(Handler.java:106)

at android.os.Looper.loop(Looper.java:193)

at android.app.ActivityThread.main(ActivityThread.java:6669)

at java.lang.reflect.Method.invoke(Native Method)

at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)

at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

任何有关如何在Android 9 api上继续使用org.apache.http.legacy的指针将不胜感激。

回答:

因此,在进行进一步的故障排除后,发现该问题是由于第三方库(activeandroid)引起的。库正在使用反射检查类路径中所有可用的类,并且由于某种原因,旧的apache

HTTP类在调用 时发生冲突。跳过反射代码,应用程序按预期工作。在低于Android

9的版本上,这不是问题。

因此,正确的方法是根据文档使用:<uses-library android:name="org.apache.http.legacy"

android:required="false"/>。如果遇到随机异常,请检查您是否没有使用反射尝试遍历旧版HTTP类。

以上是 在Android 9中使用org.apache.http.legacy 的全部内容, 来源链接: utcz.com/qa/430886.html

回到顶部