如何解决此错误VFY:无法解析虚方法

时间:2016-04-26 20:10:52

标签: java android java-8 android-appcompat

我正在使用android studio 2.0,上次我将jdk 7升级到jdk 8并且我对文件gradle进行了一些更改,但现在我收到此错误

E/InstantRun: Could not find slices in APK; aborting.
I/dalvikvm: Could not find method android.content.Context.getSystemService, referenced from method com.mstr.malik.elbalaapps.ControlPanel.access$super
W/dalvikvm: VFY: unable to resolve virtual method 435: Landroid/content/Context;.getSystemService (Ljava/lang/Class;)Ljava/lang/Object;
D/dalvikvm: VFY: replacing opcode 0x6f at 0x004b
I/dalvikvm: Could not find method android.app.Activity.stopLockTask, referenced from method com.mstr.malik.elbalaapps.ControlPanel.access$super
W/dalvikvm: VFY: unable to resolve virtual method 231: Landroid/app/Activity;.stopLockTask ()V
D/dalvikvm: VFY: replacing opcode 0x6f at 0x00b9
E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method com.mstr.malik.elbalaapps.ControlPanel.access$super
W/dalvikvm: VFY: unable to resolve check-cast 224 (Landroid/os/PersistableBundle;) in Lcom/mstr/malik/elbalaapps/ControlPanel;
D/dalvikvm: VFY: replacing opcode 0x1f at 0x00f1
I/dalvikvm: Could not find method android.content.Context.getColorStateList, referenced from method com.mstr.malik.elbalaapps.ControlPanel.access$super
W/dalvikvm: VFY: unable to resolve virtual method 417: Landroid/content/Context;.getColorStateList (I)Landroid/content/res/ColorStateList;
D/dalvikvm: VFY: replacing opcode 0x6f at 0x0101
I/dalvikvm: Could not find method android.app.Activity.onVisibleBehindCanceled, referenced from method com.mstr.malik.elbalaapps.ControlPanel.access$super
W/dalvikvm: VFY: unable to resolve virtual method 154: Landroid/app/Activity;.onVisibleBehindCanceled ()V
D/dalvikvm: VFY: replacing opcode 0x6f at 0x0111
I/dalvikvm: Could not find method android.app.Activity.onWindowStartingActionMode, referenced from method com.mstr.malik.elbalaapps.ControlPanel.access$super
W/dalvikvm: VFY: unable to resolve virtual method 158: Landroid/app/Activity;.onWindowStartingActionMode (Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode;
D/dalvikvm: VFY: replacing opcode 0x6f at 0x0137
E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method com.mstr.malik.elbalaapps.ControlPanel.access$super
W/dalvikvm: VFY: unable to resolve check-cast 224 (Landroid/os/PersistableBundle;) in Lcom/mstr/malik/elbalaapps/ControlPanel;
D/dalvikvm: VFY: replacing opcode 0x1f at 0x019a

这是gradle文件

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "24.0.0 rc3"

    defaultConfig {
        applicationId "com.mstr.malik.elbalaapps"
        minSdkVersion 18
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.3.0'
}

我如何处理错误,我试图编译版本的编译版本com.android.support:appcompat-v7:23.3.0'编译' com.android.support:appcompat-v7:23.0.0'它也崩溃了,我怎么能这样做? 提前谢谢

3 个答案:

答案 0 :(得分:10)

如果您在运行时检查Android版本,则可以安全地忽略此警告。它只是意味着您有一个方法的引用,该方法在您当前运行的代码的平台上不可用。您只需要确保在旧平台上不使用较新的API。通常lint会在发布版本中执行错误时警告您。只要记住这一点,你就不必担心它。

就像这样的运行时切换的一个例子:

if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    // You can use here an API which was added in Lollipop.
}

答案 1 :(得分:4)

根据谷歌Android工程师的说法,这是正常的。

请参阅https://code.google.com/p/android/issues/detail?id=198567

当您针对比部署的设备api级别更高的api级别进行编译时会发生这种情况。日志表明,某些方法不可用,虚拟机将用替代实现替换它们。

BR, 尼克

答案 2 :(得分:1)

我有相同的警告,然后是致命的NoClassDefFoundError。问题可以来自android-plugin的多索引模式中的dex生成的文件。所有无法找到的类都在一个包中。该软件包分为2个dex文件。一个解决方案是生成MainDexList文件,其中我只包含未解析的类,这些类连接到一个dex文件。有关详细信息,请参阅here