DexOpt:使用Gson TypeToken进行非法方法访问

时间:2016-08-31 14:12:11

标签: android serialization gson dalvik typetoken

我不知道从什么时候开始,但现在当我将我的应用程序部署到Android设备时,我在logcat控制台中看到了这些日志:

08-31 10:01:45.437 2157-2219/com.company.clap I/dalvikvm: DexOpt: illegal method access (call Lcom/google/gson/reflect/TypeToken;.<init> (Ljava/lang/reflect/Type;)V from Lcom/company/clapcore/service/ClapService$2;)
08-31 10:01:45.437 2157-2219/com.company.clap I/dalvikvm: Could not find method com.google.gson.reflect.TypeToken.<init>, referenced from method com.company.clapcore.service.ClapService$2.<init>
08-31 10:01:45.437 2157-2219/com.company.clap W/dalvikvm: VFY: unable to resolve direct method 15655: Lcom/google/gson/reflect/TypeToken;.<init> (Ljava/lang/reflect/Type;)V
08-31 10:01:45.437 2157-2219/com.company.clap D/dalvikvm: VFY: replacing opcode 0x70 at 0x0033
08-31 10:01:45.767 2157-2219/com.company.clap I/dalvikvm: DexOpt: illegal method access (call Lcom/google/gson/reflect/TypeToken;.<init> (Ljava/lang/reflect/Type;)V from Lcom/company/clapcore/service/ClapService$1;)
08-31 10:01:45.767 2157-2219/com.company.clap I/dalvikvm: Could not find method com.google.gson.reflect.TypeToken.<init>, referenced from method com.company.clapcore.service.ClapService$1.<init>
08-31 10:01:45.767 2157-2219/com.company.clap W/dalvikvm: VFY: unable to resolve direct method 15655: Lcom/google/gson/reflect/TypeToken;.<init> (Ljava/lang/reflect/Type;)V
08-31 10:01:45.767 2157-2219/com.company.clap D/dalvikvm: VFY: replacing opcode 0x70 at 0x0033

似乎没有任何与之相关的问题,我的应用程序仍在运行,但我讨厌在启动序列中看到错误,我担心它可能会在以后隐藏一些错误。

ClapService类只需导入TypeToken包,如下所示:

import com.google.gson.reflect.TypeToken;

并以各种方式使用它,如:

private Object getPartialConfig(String settingName, TypeToken<?> typeToken) {
...
}

或类似的东西:

private LocalizationConfig getLocalizationConfig() {
        return (LocalizationConfig)getPartialConfig("localizationSettings", new TypeToken<LocalizationConfig>() {});
    }

如果有人能解释我这个错误并告诉我如何摆脱它,我会非常感激。谢谢!

1 个答案:

答案 0 :(得分:0)

尝试将空构造函数添加到tmp

ClapService