34

After updating Android Studio to version 2.3. Every time I swipe my ViewPager I keep getting this error and the app crashes:

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)

The app use to work well before the update. I already cleaned the project. Invalidate caches and run a gradle clean. No idea what else what I can do/try. My coworker can build the project and it works without any issue.

Samuel Liew
  • 76,741
  • 107
  • 159
  • 260
tonyo.dev
  • 692
  • 1
  • 5
  • 12

10 Answers10

23

write this code in your build.gradle file in the app folder

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 with this stackoverflow answer

I hope this will help you, happy coding

Community
  • 1
  • 1
Harshal Pathak
  • 757
  • 1
  • 6
  • 18
  • 6
    This solution only seems to work if I'm ok with reverting to version 25. I need features exposed in version 26 (specifically fonts in xml). How can I use version 26 and also avoid this NoClassDef error on AnimatorCompatHelper? Thanks! – vm2000 Oct 02 '17 at 20:06
14

I was using version 26.0.1 (on Android Studio 3.0 beta 2) support libraries had version 47 and I had the same issue. What worked for me is to remove/comment this line from all gradle files:

compile 'com.android.support:support-v4:26.0.1'

Then added the following code from "Er Pathak Harshal" comment to the bottom of (Module: app and Module: Library) in build.gradle files:

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'
            }
        }
    }
}

Please note if you have more than 1 build.gradle files i.e. (Module: library and Module: yourapp) you need to add that code in both files to make it work.

Desolator
  • 22,411
  • 20
  • 73
  • 96
9

you can change support v7 lib version to 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'`

I hope this will help you

Jiansion
  • 91
  • 2
7

I was able to figure out what the issue was. Android studio updated the "Android support Repository"(located in sdk manager) to version 46 which included a bunch of Alpha support libs for Android O. I reverted back to version 25 and the issue was resolved. Apparently Android Studio 2.3 kept building against the Alpha support libraries causing a mismatch in dependencies which caused the app to crash.

tonyo.dev
  • 692
  • 1
  • 5
  • 12
  • 2
    Hey, could you please tell me how do we revert back to version 25? We have the same problem here. - Thanks in advance – rahulrvp Mar 27 '17 at 09:14
2

i fixed the error updating version in Gradle app

implementation 'com.android.support:design:27.0.2'
implementation 'com.android.support:support-v4:27.0.2'

To

implementation 'com.android.support:design:27.1.1’
implementation 'com.android.support:support-v4:27.1.1’
Erick Amoedo
  • 475
  • 1
  • 4
  • 9
1

Just generate an "APK" instead of instant run, and it will work perfectly.

rgv
  • 1,186
  • 1
  • 17
  • 39
Ajith K P
  • 398
  • 3
  • 12
1

Use the latest support libraries. (Latest stable releases worked for me - i.e. currently upgrading from 27.1.1 or older to 28.0.0 fixes it.)

Gabor
  • 7,352
  • 4
  • 35
  • 56
Oderik
  • 2,242
  • 2
  • 16
  • 25
0

I also had the same problem. After hunting for a whole day found nothing. Then in the morning with fresh mind, i realised that my one of the custom library is using java 8 features and my app module gradle file does not enable it.

So i just added Following line in build.gradle(Modeule:app) file to make it work:

compileOptions {
        targetCompatibility 1.8
        sourceCompatibility 1.8
}

I hope it helps others too.

Sachin Chandil
  • 17,133
  • 8
  • 47
  • 65
0

I faced a same problem while integrating aviary sdk , then solved downgrading things as below . .

  • app compatibility to compile 'com.android.support:appcompat-v7:25.4.0'
  • target sdk version to targetSdkVersion 25
  • compile sdk version to compileSdkVersion 25
roy
  • 6,685
  • 3
  • 26
  • 39
0

Make sure in your build.gradle file all implementations are of the same version.

implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:design:26.1.0'
implementation 'com.android.support:cardview-v7:26.1.0'
ॐ Rakesh Kumar
  • 1,318
  • 1
  • 14
  • 24
Daya Nithi
  • 117
  • 1
  • 10