我的VSApiEndpointInterface
中的代码@POST(REGISTER_USER)
Call registerUser(@Body User user);
用户类别如下所示。
public class User {
String email;
String password;
public User(String email, String password) {
this.email = email;
this.password = password;
}
}
在主 Activity 中,我创建了用户对象,
User user = new User("[email protected]", "123456");
Call call = apiService.registerUser(user);
call.enqueue(new Callback<User>() {
@Override
public void onResponse(Response<User> response, Retrofit retrofit) {
int statusCode = response.code();
System.out.print("Veer " +response.body());
}
@Override
public void onFailure(Throwable t) {
// Log error here since request failed
}
});
我也尝试过,
Call<User> registerUser(@Body User user);
但是同样的错误。
完整曲目
11-29 10:12:59.299 28854-28854/com.myapp.app W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x41017258)
11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime: FATAL EXCEPTION: main
11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime: java.lang.IllegalArgumentException: Unable to create call adapter for interface retrofit.Call
11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime: for method VSApiEndpointInterface.registerUser
11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime: at retrofit.Utils.methodError(Utils.java:177)
11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime: at retrofit.MethodHandler.createCallAdapter(MethodHandler.java:47)
11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime: at retrofit.MethodHandler.create(MethodHandler.java:26)
11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime: at retrofit.Retrofit.loadMethodHandler(Retrofit.java:151)
11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime: at retrofit.Retrofit$1.invoke(Retrofit.java:132)
11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime: at $Proxy0.registerUser(Native Method)
11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime: at com.myapp.app.activity.LoginActivity$1.onClick(LoginActivity.java:48)
11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime: at android.view.View.performClick(View.java:3517)
11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime: at android.view.View$PerformClick.run(View.java:14155)
11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:605)
11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:92)
11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime: at android.os.Looper.loop(Looper.java:137)
11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:4508)
11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method)
11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:511)
11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809)
11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576)
11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime: at dalvik.system.NativeStart.main(Native Method)
11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime: Caused by: java.lang.IllegalArgumentException: Call return type must be parameterized as Call<Foo> or Call<? extends Foo>
11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime: at retrofit.Utils.getCallResponseType(Utils.java:185)
11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime: at retrofit.ExecutorCallAdapterFactory.get(ExecutorCallAdapterFactory.java:35)
11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime: at retrofit.Retrofit.nextCallAdapter(Retrofit.java:189)
11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime: at retrofit.Retrofit.callAdapter(Retrofit.java:175)
11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime: at retrofit.MethodHandler.createCallAdapter(MethodHandler.java:45)
11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime: at retrofit.MethodHandler.create(MethodHandler.java:26)
11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime: at retrofit.Retrofit.loadMethodHandler(Retrofit.java:151)
11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime: at retrofit.Retrofit$1.invoke(Retrofit.java:132)
11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime: at $Proxy0.registerUser(Native Method)
11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime: at com.myapp.app.activity.LoginActivity$1.onClick(LoginActivity.java:48)
11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime: at android.view.View.performClick(View.java:3517)
11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime: at android.view.View$PerformClick.run(View.java:14155)
11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:605)
11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:92)
11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime: at android.os.Looper.loop(Looper.java:137)
11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:4508)
11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method)
11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:511)
11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809)
11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576)
11-29 10:12:59.326 28854-28854/com.myapp.app E/AndroidRuntime: at dalvik.system.NativeStart.main(Native Method)
我想知道我的代码错误。其次是错误原因。
谢谢。
我也有同样的问题。它在调试模式下工作,在发布模式下失败。
问题是因为亲卫规则。
这对我有帮助 https://github.com/krschultz/android-proguard-snippets/tree/master/libraries
这里的改造和 Okio 规则对我有用。
将这些添加到亲卫规则中
-keepattributes Signature
-keep class com.google.gson.reflect.TypeToken { *; }
-keep class * extends com.google.gson.reflect.TypeToken
-keepattributes AnnotationDefault,RuntimeVisibleAnnotations
-keep,allowobfuscation,allowshrinking interface retrofit2.Call
-keep,allowobfuscation,allowshrinking class retrofit2.Response
-keep,allowobfuscation,allowshrinking class kotlin.coroutines.Continuation
-dontwarn okhttp3.internal.platform.**
-dontwarn org.conscrypt.**
-dontwarn org.bouncycastle.**
-dontwarn org.openjsse.**
-keep class retrofit2.** { *; }
-keep class okhttp3.** { *; }
-keep class com.google.gson.** { *; }
-keepattributes *Annotation*
-dontwarn sun.misc.**
-keep class com.google.gson.examples.android.model.** { *; }
-keep class * implements com.google.gson.TypeAdapterFactory
-keep class * implements com.google.gson.JsonSerializer
-keep class * implements com.google.gson.JsonDeserializer
# JSR 305 annotations are for embedding nullability information.
-dontwarn javax.annotation.**
# A resource is loaded with a relative path so the package of this class must be preserved.
-adaptresourcefilenames okhttp3/internal/publicsuffix/PublicSuffixDatabase.gz
# Animal Sniffer compileOnly dependency to ensure APIs are compatible with older versions of Java.
-dontwarn org.codehaus.mojo.animal_sniffer.*
# OkHttp platform used only on JVM and when Conscrypt and other security providers are available.
-keepattributes Annotation
-keep interface okhttp3.** { *; }
-dontwarn okhttp3.**
-dontwarn okio.**
-dontwarn org.conscrypt.*