If your app is targeting API level 28 (Android 9.0) or above, you must include the following declaration within the<application>
element of AndroidManifest.xml.<uses-library android:name="org.apache.http.legacy" android:required="false" />
If your app is targeting a lower API level, this is handled for you.
The error message "Didn't find class "org.apache.http.ProtocolVersion"" is related to the use of the Apache HTTP library, which is no longer supported in Android P (API level 28) and higher. The class org.apache.http.ProtocolVersion
is a part of this library.
To fix this issue, you will need to remove the dependency on the Apache HTTP library and replace it with a more recent library that is supported on Android P and higher. One popular alternative is the OkHttp library.
Here are the steps you can take to replace the Apache HTTP library with OkHttp:
Remove the dependency on the Apache HTTP library from your app's build.gradle file.
Add the OkHttp library to your app's build.gradle file. You can do this by adding the following line to the dependencies section:
implementation 'com.squareup.okhttp3:okhttp:4.x.x'
Replace all instances of
org.apache.http
withokhttp3
in your app's code.Rebuild and test your app to ensure that the app no longer crashes and that all network-related functionality still works as expected.
It's also important to keep in mind that other libraries you're using may be dependent on Apache HTTP classes, so you may need to update those libraries as well.
It is also recommended to use HttpUrlConnection
provided by android framework as it is more optimized for android and it is recommended by google.
Comments
Post a Comment