Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting `java.lang.AssertionError: java.lang.NoSuchFieldException: HTTP_1_0`

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.

like image 471
Ankit Kumar Avatar asked Dec 14 '22 10:12

Ankit Kumar


2 Answers

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.

like image 113
Sam Avatar answered May 21 '23 13:05

Sam


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>;
}
like image 25
user14279758 Avatar answered May 21 '23 12:05

user14279758