Koos
Koos

Reputation: 117

How do I fix Duplicate class android.support.design.widget.CoordinatorLayout?

I am trying to make a file picker for an android app and I do not see any issues but when I run it, I get:

Duplicate class android.support.design.widget.CoordinatorLayout found in modules classes.jar (com.android.support:coordinatorlayout:28.0.0) and classes.jar (com.android.support:design:25.3.1)

I have tried syncing Gardle again and it does not work

In the Gardle file Project I added this:

maven {
            url  "http://dl.bintray.com/lukaville/maven"
        }

and in the Gardle file Module, I added this:

compile 'com.nbsp:library:1.8'

and to use this Library, I added this into the MainActivity.java:

button = (Button)findViewById(R.id.button); textView = (TextView) findViewById(R.id.textView);

    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            new MaterialFilePicker()
                    .withActivity(MainActivity.this)
                    .withRequestCode(1000)
                    .withFilter(Pattern.compile(".*\\.txt$")) 
                    .withFilterDirectories(true)  
                    .withHiddenFiles(true) 
                    .start();
        }
    });
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == 1 && resultCode == RESULT_OK) {
        String filePath = data.getStringExtra(FilePickerActivity.RESULT_FILE_PATH);
        textView.setText(filePath);
    }

I do not get any syntax errors but when I run, I get an error in logcat saying: :app:checkDebugDuplicateClasses

and

Duplicate class android.support.design.widget.CoordinatorLayout found in modules classes.jar (com.android.support:coordinatorlayout:28.0.0) and classes.jar (com.android.support:design:25.3.1)

and similar of those besides.

Upvotes: 1

Views: 3438

Answers (2)

Schnelldev
Schnelldev

Reputation: 1482

I found that updating the android support design library solves the problem. Simply implement this class in your app's Gradle file: com.android.support:design:28.0.0 It seems the issue comes because there are two conflicting versions of the CoordinatorLayout in the two different versions of the support library that Android Studio mentioned.

I hope this helps someone.

Upvotes: 3

Jasurbek
Jasurbek

Reputation: 2966

This issue is occurring because of the fact that the lib is out of date. It has not been updated for a long time.

this is gradle of MaterialFilePicker project. You can see, whatever Android Studio is saying is right.

Solution:

  1. Decrease your dependencies libs version
  2. Or open issue on github, which is nearly impossible
  3. Or take the source code and recompile with updated libraries

Understand why it is happening. Since this is normal Android support libs their version should be identical. That is one of the reasons why jetpack introduced AndroidX.

Upvotes: 0

Related Questions