Link of class 'Lcom.....;' failed

Android 3xcn.com@站长2020年6月18日 pm12:22发布3年前 (2021)更新
0
导航号,我的单页导航
目录

问题描述

导入同事修改的系统应用后编译成功,但运行起来后就异常了。

Link of class 'Lcom/.....;' failed

异常完整日志

W/dalvikvm( 5955): Link of class 'Lcom/la/music/PlayFragment;' failed
W/dalvikvm( 5955): Link of class 'Lcom/la/music/PlayFragment;' failed
E/dalvikvm( 5955): Could not find class 'com.la.music.PlayFragment', referenced from method com.la.music.MainActivity.onCreate
W/dalvikvm( 5955): VFY: unable to resolve new-instance 179 (Lcom/la/music/PlayFragment;) in Lcom/la/music/MainActivity;
W/dalvikvm( 5955): Link of class 'Lcom/la/music/PlayFragment;' failed
W/dalvikvm( 5955): VFY: Ljava/lang/Object; is not instance of Landroid/app/Fragment;
W/dalvikvm( 5955): VFY: bad arg 1 (into Landroid/app/Fragment;)
W/dalvikvm( 5955): VFY:  rejecting call to Lcom/la/music/MainActivity;.LoadFragment (Landroid/app/Fragment;)V
W/dalvikvm( 5955): VFY:  rejecting opcode 0x6e at 0x001c
W/dalvikvm( 5955): VFY:  rejected Lcom/la/music/MainActivity;.showFragment (Lcom/la/music/MainActivity$FRAGMENT_TYPE;)V
W/dalvikvm( 5955): Verifier rejected class Lcom/la/music/MainActivity;
W/dalvikvm( 5955): Class init failed in newInstance call (Lcom/la/music/MainActivity;)
W/dalvikvm( 5955): threadid=1: thread exiting with uncaught exception (group=0x41c95930)
E/AndroidRuntime( 5955): FATAL EXCEPTION: main
E/AndroidRuntime( 5955): java.lang.VerifyError: com/la/music/MainActivity
E/AndroidRuntime( 5955):        at java.lang.Class.newInstanceImpl(Native Method)
E/AndroidRuntime( 5955):        at java.lang.Class.newInstance(Class.java:1319)
E/AndroidRuntime( 5955):        at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
E/AndroidRuntime( 5955):        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2104)
E/AndroidRuntime( 5955):        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2237)
E/AndroidRuntime( 5955):        at android.app.ActivityThread.access$600(ActivityThread.java:145)
E/AndroidRuntime( 5955):        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1241)
E/AndroidRuntime( 5955):        at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 5955):        at android.os.Looper.loop(Looper.java:138)
E/AndroidRuntime( 5955):        at android.app.ActivityThread.main(ActivityThread.java:5089)
E/AndroidRuntime( 5955):        at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 5955):        at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime( 5955):        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
E/AndroidRuntime( 5955):        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
E/AndroidRuntime( 5955):        at dalvik.system.NativeStart.main(Native Method)
W/ActivityManager(  377):   Force finishing activity com.la.music/.MainActivity

日志中重点

W/dalvikvm( 5955): Link of class 'Lcom/la/music/PlayFragment;' failed

而PlayFragment中有使用

import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;

解决问题

这个是我在Android 4.2 项目中遇到的问题,大概的是没有导入如下jar

android-support-v4.jar

而是导入了系统编译生成的Android 4.2的android-support-v4_classes.jar(这个是编译系统时生成的),系统应用开发一般都会导入依赖的系统jar,因此顺手导入了。

我解决的方法是:
  1. 导入android-support-v4.jar
  2. 删除系统生成的android-support-v4_classes.jar

然后就没问题了。

这个我是当时浏览stackoverflow的Anonymous Me如下回答时突然想起的。

After spending 12 hours I was able to resolve the issue on my own. I am answering it here so that it can be useful to someone in the similar situation.

I was ignoring the following warning

Found 2 versions of android-support-v4.jar in the dependency list,
but not all the versions are identical (check is based on SHA-1 only at this time).
All versions of the libraries must be the same at this time.
Versions found are:
Path: /App/libs/android-support-v4.jar
    Length: 349252
    SHA-1: 612846c9857077a039b533718f72db3bc041d389
Path: /App Library/libs/android-support-v4.jar
    Length: 337562
    SHA-1: 27c24d26e4c5d57976e6926367985548678e913c
I just deleted android-support-v4.jar from app's lib folder and kept the one in library's lib folder and the error was gone.

参考文章

  1. Link of class failed dalvik
  2. java.lang.VerifyError 异常解决方法

版权声明 1、 本站名称 91易搜
2、 本站网址 https://www.91es.com/
3、 本站部分文章来源于网络,仅供学习与参考,如有侵权请留言
4、 本站禁止发布或转载任何违法的相关信息,如有发现请向站长举报
导航号,我的单页导航

暂无评论

评论审核已启用。您的评论可能需要一段时间后才能被显示。

暂无评论...