将Android Studio更新到2.3版之后.每次我刷我的ViewPager我都会收到此错误并且应用程序崩溃:
03-23 17:19:19.437 28523-28523/? E/AndroidRuntime: FATAL EXCEPTION: main Process: com.irokotv.plus, PID: 28523 java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/animation/AnimatorCompatHelper; at android.support.v7.widget.DefaultItemAnimator.resetAnimation(DefaultItemAnimator.java:515) at android.support.v7.widget.DefaultItemAnimator.animateAdd(DefaultItemAnimator.java:218) at android.support.v7.widget.SimpleItemAnimator.animateAppearance(SimpleItemAnimator.java:114) at android.support.v7.widget.RecyclerView.animateAppearance(RecyclerView.java:3528) at android.support.v7.widget.RecyclerView$4.processAppeared(RecyclerView.java:461) at android.support.v7.widget.ViewInfoStore.process(ViewInfoStore.java:249) at android.support.v7.widget.RecyclerView.dispatchLayoutStep3(RecyclerView.java:3385) at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3135) at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3568) at android.view.View.layout(View.java:18793) at android.view.ViewGroup.layout(ViewGroup.java:5952) at android.support.v4.view.ViewPager.onLayout(ViewPager.java:1766) at android.view.View.layout(View.java:18793) at android.view.ViewGroup.layout(ViewGroup.java:5952) at android.support.design.widget.HeaderScrollingViewBehavior.layoutChild(HeaderScrollingViewBehavior.java:131) at android.support.design.widget.ViewOffsetBehavior.onLayoutChild(ViewOffsetBehavior.java:42) at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onLayoutChild(AppBarLayout.java:1364) at android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:846) at android.view.View.layout(View.java:18793) at android.view.ViewGroup.layout(ViewGroup.java:5952) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323) at android.widget.FrameLayout.onLayout(FrameLayout.java:261) at android.view.View.layout(View.java:18793) at android.view.ViewGroup.layout(ViewGroup.java:5952) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1741) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1585) at android.widget.LinearLayout.onLayout(LinearLayout.java:1494) at android.view.View.layout(View.java:18793) at android.view.ViewGroup.layout(ViewGroup.java:5952) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323) at android.widget.FrameLayout.onLayout(FrameLayout.java:261) at android.view.View.layout(View.java:18793) at android.view.ViewGroup.layout(ViewGroup.java:5952) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1741) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1585) at android.widget.LinearLayout.onLayout(LinearLayout.java:1494) at android.view.View.layout(View.java:18793) at android.view.ViewGroup.layout(ViewGroup.java:5952) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323) at android.widget.FrameLayout.onLayout(FrameLayout.java:261) at com.android.internal.policy.DecorView.onLayout(DecorView.java:818) at android.view.View.layout(View.java:18793) at android.view.ViewGroup.layout(ViewGroup.java:5952) at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2615) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2331) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1490) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7027) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:927) at android.view.Choreographer.doCallbacks(Choreographer.java:702) at android.view.Choreographer.doFrame(Choreographer.java:638) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:913) at android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6688) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
应用程序用于在更新之前正常运行.我已经清理了这个项目.使缓存无效并运行gradle clean.不知道我还能做什么/尝试.我的同事可以建立项目,它没有任何问题.
将此代码写入build.gradle
文件app
夹中的文件中
configurations.all { resolutionStrategy.eachDependency { DependencyResolveDetails details -> def requested = details.requested if (requested.group == 'com.android.support') { if (!requested.name.startsWith("multidex")) { details.useVersion '25.3.0' } } }
ref用这个stackoverflow答案
我希望这会对你有所帮助,编码愉快
我使用的是版本26.0.1(在Android Studio 3.0 beta 2上)支持库有47版本,我遇到了同样的问题.对我有用的是从所有gradle文件中删除/注释这一行:
compile 'com.android.support:support-v4:26.0.1'
然后将以下代码从"Er Pathak Harshal"注释添加到build.gradle文件的底部(Module:app and Module:Library):
configurations.all { resolutionStrategy.eachDependency { DependencyResolveDetails details -> def requested = details.requested if (requested.group == 'com.android.support') { if (!requested.name.startsWith("multidex")) { details.useVersion '25.3.0' } } } }
请注意,如果您有超过1个build.gradle文件,即(模块:库和模块:yourapp),您需要在两个文件中添加该代码以使其正常工作.
你可以将支持v7 lib版本更改为26.0.0-alpha1 shuch:
`compile 'com.android.support:appcompat-v7:26.0.0-alpha1' compile 'com.android.support:design:26.0.0-alpha1' compile 'com.android.support:cardview-v7:26.0.0-alpha1'`
我希望这能帮到您
我能够弄清楚问题是什么.Android工作室更新了"Android支持存储库"(位于sdk管理器中)到版本46,其中包括一堆针对Android O的Alpha支持库.我又回到了版本25,问题得到了解决.显然,Android Studio 2.3不断构建针对Alpha支持库的构建,导致依赖项不匹配,从而导致应用程序崩溃.