加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – Proguard配置使用改造Retrofit

发布时间:2020-12-15 05:13:03 所属栏目:Java 来源:网络整理
导读:我的应用程序在调试中运行正常,但在创建apk以发布时,我收到了以下错误. Process: neocom.dealerbook,PID: 9044 java.lang.IndexOutOfBoundsException: Invalid index 0,size is 0 at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255
我的应用程序在调试中运行正常,但在创建apk以发布时,我收到了以下错误.

Process: neocom.dealerbook,PID: 9044
    java.lang.IndexOutOfBoundsException: Invalid index 0,size is 0
            at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
            at java.util.ArrayList.get(ArrayList.java:308)
            at neocom.dealerbook.controller.k.a(MapActivity.java:103)
            at neocom.dealerbook.controller.k.success(MapActivity.java:98)
            at retrofit.CallbackRunnable$1.run(CallbackRunnable.java:45)
            at android.os.Handler.handleCallback(Handler.java:733)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5086)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
            at dalvik.system.NativeStart.main(Native Method)

这是MapActivity.java:103

Callback<ClienteConfiguracao> callback = new Callback<ClienteConfiguracao>() {
                int failCount = 0;
            @Override
            public void success(ClienteConfiguracao clienteConfiguracao,Response response) {
                currentClient = clienteConfiguracao.getDealerships().get(0); /* Line 103 */
                setupToggles(currentClient);

                List<String> mAuthorization = clienteConfiguracao.getAuthorization();
                toAllowPermissions = new HashMap<>();
                Set<String> allImplementedKeys = PermissionManager.ALL_PERMISSIONS.keySet();
                for (String key : mAuthorization) {
                    if (allImplementedKeys.contains(key)) {
                        List value = PermissionManager.ALL_PERMISSIONS.get(key);
                        toAllowPermissions.put(key,value);
                    }
                }

这是我构建的proguard文件,用于搜索我得到的错误,Retrofit网站和其他人.

-assumenosideeffects class android.util.Log {
    public static boolean isLoggable(java.lang.String,int);
    public static int v(...);
    public static int i(...);
    public static int w(...);
    public static int d(...);
    public static int e(...);
}
-dontwarn retrofit.**
-dontwarn com.squareup.okhttp.**
-dontwarn okio.**
-dontwarn retrofit.appengine.UrlFetchClient
-keep class retrofit.** { *; }
-keep class com.squareup.okhttp.** { *; }
-keep interface com.squareup.okhttp.** { *; }
-keepattributes Signature
-keepattributes Exceptions
-keepattributes *Annotation*
-keepattributes SourceFile
-keepattributes LineNumberTable


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

关于它有什么提示吗?

解决方法

使用gson进行改造时,将Progard规则添加到序列化和反序列化的类非常重要.

例如:

-keep class com.example.model.** { *; }

PS:另一个建议是使用rules snippets from this repository.许多不同的库都有规则.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读