star-micronics / react-native-star-io10

react-native-star-io10 is a library for supporting application development for Star Micronics devices.
Other
91 stars 55 forks source link

[Android] cannot access 'body': it is package-private in 'response' #37

Closed harmit001 closed 2 years ago

harmit001 commented 2 years ago

Error in Android: cannot access 'body': it is package-private in 'response'

harmit001 commented 2 years ago

https://github.com/star-micronics/react-native-star-io10/pull/38

prashant828 commented 2 years ago

any solution, I am facing the same issue ?

harmit001 commented 2 years ago

@prashant828 https://github.com/star-micronics/react-native-star-io10/pull/38

bandit-ibayashi commented 2 years ago

This may be caused by the specification changed of OkHttpClient.

If it is used okhttp ver. 3.14.9, the body is available as a method. implementation 'com.squareup.okhttp3:okhttp:3.14.9 in build.gradle.

val client = OkHttpClient()
val request = Request.Builder().url("ANY URL").build()
val response = client.newCall(request).execute()

val newString = response.body?.string() // Cannot access 'body': it is package-private in 'Response'
val oldString = response.body()?.string() // work fine

If that of ver. 4.0.0 or later, the body is available as a property. implementation 'com.squareup.okhttp3:okhttp:4.0.0 in build.gradle.

val newString = response.body?.string() // work fine'
val oldString = response.body()?.string() // Using 'body(): ResponseBody()' is an error. moved to val

If you need to use okhttp libraries below version 4 due to consistency with other libraries, you could change the above section to a method.