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

前端 未结 10 2061
暗喜
暗喜 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: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 :-)

提交回复
热议问题