gpt4 book ai didi

java - Retrofit2 proguard 发生 : java. lang.AbstractMethodError:抽象方法 "void retrofit2.Callback.onResponse(retrofit2.Call, retrofit2.Response)"

转载 作者:行者123 更新时间:2023-12-03 05:41:04 32 4
gpt4 key购买 nike

我正在开发一个自定义模块项目,里面有一个管理器类(下面调用“ManagerClass ”)作为这个模块的主要入口。在这个类中,我使用retrofit2 将http API 与入队模式连接起来。

Now, what makes me crazy is that, in Debug buildType, the whole module is running faultlessly!But if I want to make JAR, it means in release mode, I want the module to be mixed and the exception occured!



这是我的 API 方法:
public void apiGetPublicIpInfo2(Callback<TestIp> callback) {
Call<TestIp> call = apiService.getPublicIpInfo("http://ipinfo.io/json");
call.enqueue(callback);
}

这是我在 ManagerClass 中的用法:
mApiManager.apiGetPublicIpInfo2(new Callback<TestIp>() {
@Override
public void onResponse(Call<TestIp> call, Response<TestIp> response) {
...
}

@Override
public void onFailure(Call<TestIp> call, Throwable t) {
...
}
});

但是如果我创建 JAR,它看起来像这样:

enter image description here

The abstract method onResponse and onFailure of retrofit2.Callback are mixed!



结果是:
java.lang.AbstractMethodError: abstract method "void retrofit2.Callback.onResponse(retrofit2.Call, retrofit2.Response)"
at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:70)
at android.os.Handler.handleCallback(Handler.java:809)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:166)
at android.app.ActivityThread.main(ActivityThread.java:7377)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:469)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:963)

proguard-rules.pro 文件是普通类型,就像:
-keep class com.----.ManagerClass {
public <fields>;
public <methods>;
}

即使我将其更改为
-keep class com.----.ManagerClass {
*;
}

覆盖方法 响应 失败 匿名内部类“ new Callback<>(){} ”仍然混合...

我的模块 build.gradle 是:
apply plugin: 'com.android.library'
android {
compileSdkVersion 26

defaultConfig {
minSdkVersion 10
targetSdkVersion 26
versionCode 1
versionName "0.0.1"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

buildTypes {
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
jniDebuggable true
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
jniDebuggable false
}
}
lintOptions {
abortOnError false
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:26.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
}

在我尝试了某种方法(例如编辑 proguard 文件)后,我不知道如何修复它。

最佳答案

尝试设置此选项:

-dontwarn retrofit2.**
-keep class retrofit2.** { *; }
-keepattributes Signature
-keepattributes Exceptions

-keepclasseswithmembers class * {
@retrofit2.http.* <methods>;
}

更多详细设置见: https://github.com/square/retrofit/blob/master/retrofit/src/main/resources/META-INF/proguard/retrofit2.pro

关于java - Retrofit2 proguard 发生 : java. lang.AbstractMethodError:抽象方法 "void retrofit2.Callback.onResponse(retrofit2.Call, retrofit2.Response)",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52986712/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com