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

前端 未结 10 2044
暗喜
暗喜 2020-12-10 03:56

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

相关标签:
10条回答
  • 2020-12-10 04:27

    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.

    0 讨论(0)
  • 2020-12-10 04:28

    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.

    0 讨论(0)
  • 2020-12-10 04:31

    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 :-)

    0 讨论(0)
  • 2020-12-10 04:37

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

        implementation 'com.android.support:support-v4:28.0.0'
    
    0 讨论(0)
提交回复
热议问题