Using org.apache.http.legacy in Android 9

后端 未结 3 1426
面向向阳花
面向向阳花 2020-12-17 03:02

I have an old android app that uses the apache legacy Http library (org.apache.http.legacy). After the changes on Android 6, I was able to keep the app working including the

相关标签:
3条回答
  • 2020-12-17 03:08

    You have to add attribute of android:usesCleartextTraffic="true" on application tag in AndroidManifes.xml file.

    And also add this.

    <uses-library android:name="org.apache.http.legacy" android:required="false"/>
    
    0 讨论(0)
  • 2020-12-17 03:19

    Your classes seem to be conflicting.

    As an alternative to using the runtime Apache library, apps can bundle their own version of the org.apache.http library in their APK. If you do this, you must repackage the library (with a utility like Jar Jar) to avoid class compatibility issues with the classes provided in the runtime.

    See here

    0 讨论(0)
  • 2020-12-17 03:30

    So after further troubleshooting found out that issue was due to a third party library (activeandroid). Library was using reflection to check all classes available in the classpath and for some reason the legacy apache HTTP classes conflicted when calling java.lang.Class.classForName. Skipped the reflection code and app worked as expected. On versions below Android 9 this is not an issue though.

    So correct way is as per documentation using: <uses-library android:name="org.apache.http.legacy" android:required="false"/>. If you come across random exceptions check you are not using reflection to try to traverse the legacy HTTP classes.

    0 讨论(0)
提交回复
热议问题