Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/201.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
当使用proguard进行模糊处理时,通过改装进行自定义错误处理会产生java.lang.reflect.UndeclaredThrowableException_Java_Android_Proguard_Obfuscation_Retrofit - Fatal编程技术网

当使用proguard进行模糊处理时,通过改装进行自定义错误处理会产生java.lang.reflect.UndeclaredThrowableException

当使用proguard进行模糊处理时,通过改装进行自定义错误处理会产生java.lang.reflect.UndeclaredThrowableException,java,android,proguard,obfuscation,retrofit,Java,Android,Proguard,Obfuscation,Retrofit,已编写用于改装的自定义错误处理。当minifyEnabled false时,代码工作正常。当我启用proguard时,我得到以下异常 12-17 10:14:07.688 18568-19041/com.mobility.cariq.carscore W/System.err﹕ java.lang.reflect.UndeclaredThrowableException 12-17 10:14:07.688 18568-19041/com.mobility.cariq.carscore W/

已编写用于改装的自定义错误处理。当
minifyEnabled false
时,代码工作正常。当我启用proguard时,我得到以下异常

12-17 10:14:07.688  18568-19041/com.mobility.cariq.carscore W/System.err﹕ java.lang.reflect.UndeclaredThrowableException
12-17 10:14:07.688  18568-19041/com.mobility.cariq.carscore W/System.err﹕ at $Proxy9.updatesForModel(Native Method)
12-17 10:14:07.688  18568-19041/com.mobility.cariq.carscore W/System.err﹕ at com.mobility.cariq.carscore.rest.service.UpdateDatabaseService.jiijijliillliliilllil(UpdateDatabaseService.java:119)
12-17 10:14:07.688  18568-19041/com.mobility.cariq.carscore W/System.err﹕ at com.mobility.cariq.carscore.rest.service.UpdateDatabaseService.onHandleIntent(UpdateDatabaseService.java:75)
12-17 10:14:07.689  18568-19041/com.mobility.cariq.carscore W/System.err﹕ at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
12-17 10:14:07.689  18568-19041/com.mobility.cariq.carscore W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:102)
12-17 10:14:07.689  18568-19041/com.mobility.cariq.carscore W/System.err﹕ at android.os.Looper.loop(Looper.java:136)
12-17 10:14:07.689  18568-19041/com.mobility.cariq.carscore W/System.err﹕ at android.os.HandlerThread.run(HandlerThread.java:61)
12-17 10:14:07.689  18568-19041/com.mobility.cariq.carscore W/System.err﹕ Caused by: com.mobility.cariq.carscore.rest.error.UnauthorizedException
12-17 10:14:07.690  18568-19041/com.mobility.cariq.carscore W/System.err﹕ at com.mobility.cariq.carscore.rest.error.RestErrorHandler.handleError(RestErrorHandler.java:40)
12-17 10:14:07.690  18568-19041/com.mobility.cariq.carscore W/System.err﹕ at retrofit.RestAdapter$RestHandler.invoke(RestAdapter.java:242)
错误处理程序

public class RestErrorHandler implements ErrorHandler {

@Override
public Throwable handleError(RetrofitError cause) {
    Response r = cause.getResponse();

    if (r != null && r.getStatus() == 400) {

        try {
            RestError mRestError = (RestError) cause.getBodyAs(RestError.class);
            final String exception = mRestError.getMessages().get(0);
            return new UnauthorizedException(exception);
        } catch (Exception e) {
            e.printStackTrace();
            LogUtility.NoteLog(e);
        }
    }
    return cause;
}
Proguard

-obfuscationdictionary keywords.txt
-classobfuscationdictionary keywords.txt
-packageobfuscationdictionary keywords.txt

-dontwarn android.telephony.**
-keepattributes SourceFile,LineNumberTable

-dontwarn butterknife.internal.**
-keep class **$$ViewInjector { *; }
-keepnames class * { @butterknife.InjectView *;}

-keepattributes Signature
-keepattributes *Annotation*
-keep class com.squareup.okhttp.** { *; }
-keep interface com.squareup.okhttp.** { *; }
-dontwarn com.squareup.okhttp.**

-dontwarn rx.**
-dontwarn retrofit.**
-keep class retrofit.** { *; }
-keepclasseswithmembers class * {
    @retrofit.http.* <methods>;
}

-keep class sun.misc.Unsafe { *; }
-keep class com.mobility.cariq.carscore.rest.model.** { *; }
-keep class com.mobility.cariq.carscore.rest.error.** { *; }
-dontwarn java.nio.file.**
-dontwarn org.codehaus.mojo.**

-dontwarn org.joda.convert.**
-obfuscationdictionary keywords.txt
-classobfuscationdictionary关键字.txt
-packageobfousationdictionary关键字.txt
-dontwarn.android.telephony**
-keepattributes源文件,LineNumberTable
-dontwarn butterknife,内部**
-保持类**$$ViewInjector{*;}
-keepnames类*{@butterknife.InjectView*;}
-保留署名
-keepattributes*注释*
-保持类com.squareup.okhttp.*{*;}
-保持接口com.squareup.okhttp.*{*;}
-dontwarn com.squareup.okhttp**
-dontwarn rx**
-dontwarn改装**
-保持类更新。**{*;}
-keepclassswithmembers类*{
@http.*;
}
-保持类sun.misc.Unsafe{*;}
-保持类com.mobility.cariq.carscore.rest.model.*{*;}
-保留类com.mobility.cariq.carscore.rest.error.*{*;}
-dontwarn java.nio.file**
-dontwarn org.codehaus.mojo**
-dontwarn org.joda.convert**

我对使用proguard和改装相当陌生。我无法理解如何处理异常。

看起来像
未经授权的异常
是已检查的异常(扩展自
异常
,而不是
运行时异常
),这意味着您需要在所有服务接口上声明
抛出
子句

interface MyService {
  @GET("/")
  Something doSomething() throws UnauthorizedException;
}

Proguard默认情况下删除异常属性


-keepattributes Exceptions
将确保您的
可丢弃文件在混淆后仍保留在代码中。

我已经这样做了,杰克。当我混淆代码时,它停止工作。在没有proguard的情况下,它可以完美地工作。