In my project, I am performing API call using RxJava.
Without proguard, it is running fine. But when I apply proguard It gives java.lang.AssertionError: java.lang.NoSuchFieldException: HTTP_1_0
in onError(e: Throwable)
of a subscriber.
I applied -keepclassmembers enum * { *; }
in my proguard to prevent obfuscation.
Api Call
fun latestPosts(): Subscription {
return service.latestPosts
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(APICallSubscriber(presenterContract, ApiIndex.POSTS))
}
Subscriber
class APICallSubscriber<T>(private val callback: BasePresenterContract,
private val apiIndex: String) : Subscriber<Response<T>>() {
override fun onCompleted() {
}
override fun onError(e: Throwable) {
Log.d("HomeTest", "${e}")
}
override fun onNext(response: Response<T>) {
val jsonObject = App.gson().toJsonTree(response).asJsonObject
val responseCode = jsonObject
.get(PayloadKeys.RAW_RESPONSE).asJsonObject
.get(PayloadKeys.CODE).asInt
Log.d("HomeTest", "$jsonObject")
val body: JsonElement? = jsonObject.get(PayloadKeys.BODY)
if (body != null) {
val responseBody = body.asJsonObject
callback.onNetworkRequestCompletedWith(responseBody, responseCode, apiIndex)
} else {
val errorBody: JsonElement? = jsonObject.get(PayloadKeys.ERROR_BODY)
callback.onNetwordRequestError(errorBody!!.asJsonObject, apiIndex)
}
}
}
I have tried different proguard rules but no result. Please help.
In case this helps anyone, I had an existing project with a library module I had made. To prevent my app from crashing after being minified by ProGuard, I needed to add
-keepclassmembers enum * { *; }
to not only the library's build.gradle, but also to the main module's build.gradle.
I was facing the same issue, I solved by adding all these in proguard-rules.pro
file:
-keepclassmembers enum * { *; }
-keep class com.google.code.gson.* { *; }
-keepattributes *Annotation*, Signature, Exception
-keepclassmembers,allowobfuscation class * {
@com.google.gson.annotations.SerializedName <fields>;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With