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

狂风中的少年 提交于 2019-11-28 10:58:26

I have my solution by change this:

implementation 'com.android.support:appcompat-v7:27.0.0'

to

implementation 'com.android.support:appcompat-v7:26.0.0'

it works for me.

For my solution (I do not know it will work for you):

Firstly I followed @Orhan Obut's solution:

Search for duplicate classes in your project

I found that there are more than one class files in different libraries.

Then I put the ignore annotation above my support dependency in my project module's build.gradle (app folder):

 //noinspection GradleCompatible
    implementation 'com.android.support:appcompat-v7:28.0.0'

I realized that ignorance is no solution, because the error did not go away, even after clean-rebuilding and clearing/invalidating cache for the project.

See: Infographic: 11 Most Common Android Errors and How to Fix Them

So I explored more, and found out this link:

Android - Understanding and dominating gradle dependencies

It suggests ways to resolve conflicts. Hence I put this on my gradle just above the declarations of dependencies:

configurations.all {exclude group: 'com.android.support', module: 'support-v4'}

Since then when I search for duplicate classes for this one using @Orhan Obut's solution above, I find only single entry in the result. That meant that there were no duplicates.

Also, it will be better if you migrate to AndroidX with latest SDK and build tools. Make sure you don't have older support dependencies anywhere.

Happy Coding :-)

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.

For the easy option just add

configurations.all {exclude group: 'com.android.support', module: 'support-v4'}

before dependencies in build.gradle app module, it should ignore v4 support libraries, and the duplicate error will go away.

As for me this helps to resolve such issues

all support libraries (also included thirdy-part) reduces to specified version

configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        def requested = details.requested
        if (requested.group == 'com.android.support') {
            if (!requested.name.startsWith("multidex")) {
                details.useVersion '28.0.0-beta01'
            }
        }
    }
}

Adding the below line in the build.gradle of the app level worked for me

    implementation 'com.android.support:support-v4:28.0.0'

I also faced the same problem just a while ago. In my case the third party library used the older AccessibilityServiceInfoCompat version v4 22 and i already updated to newer one v4 28 so both support library classes clashed

In y case I've resolved issue by

implementation 'com.android.support:appcompat-v7:26.0.0'

to

 implementation 'com.android.support:appcompat-v7:27.1.1'

some third-party library may be use different version of support library. you can use ./gradlew :app:dependencies find out it, and then import the current version of the support library.

I have my solution by change this :
android / build.gradle
buildscript {
    ext {
        supportLibVersion = "27.0.3"
    }
}
to
buildscript {
    ext {
        supportLibVersion = "26.0.0"
    }
}
directory android / app / build.gradle
defaultConfig {
    multiDexEnabled true
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!