Search code examples
androidandroid-studiobuildandroid-multidex

Error: Program type already present: android.support.v4.accessibilityservice.AccessibilityServiceInfoCompat


After upgrading to Android Studio 3.1, I started to get following error during build. Project uses multidex and DX is enabled by default as you would notice in the error. I tried to check dependency graph to understand what is going on but so far have no clue. Interestingly this only fails on my machine. I cleaned up everything, including reinstall etc but nothing worked.

Anyone had the same issue and how did you solve it? Or any direction that I can take a look?

AGPBI: {
    "kind":"error",
    "text":"Program type already present: android.support.v4.accessibilityservice.AccessibilityServiceInfoCompat",
    "sources":[{}],
    "tool":"D8"
}

This is the task that fails:

transformDexArchiveWithExternalLibsDexMergerForDebug

I checked similar issues and it seems random things fixes their problem, I'm not sure what is the real cause.


Solution

  • I managed to determine the root cause by using the following steps. It may be different use case for each issue, therefore this is the way to determine the root cause.

    • Go to android studio
    • Navigate -> Class
    • Check include non-project classes
    • Copy paste full class path with package name. android.support.v4.accessibilityservice.AccessibilityServiceInfoCompat
    • You should be able to see where it is used. Most probably you may need to remove it from one of them.

    In my case the issue was ViewPagerIndicator library was downloading support library as jar. Removing it solved the issue.