Adding support:preference-v7 or -v14 library causes Gradle build to fail

1k views Asked by At

My project builds fine, until I attempt to include the Support Preference library.

When I do, build fails with this error:

C:\Users\user\.gradle\caches\transforms-1\files-1.1\appcompat-v7-27.0.0.aar\e8afe3ff4b4dc10495266439a3695e57\res\values\values.xml:252:5-69: AAPT: error: duplicate value for resource 'attr/min' with config ''.

C:\Users\user\.gradle\caches\transforms-1\files-1.1\appcompat-v7-27.0.0.aar\e8afe3ff4b4dc10495266439a3695e57\res\values\values.xml:252:5-69: AAPT: error: resource previously defined here.

C:\Users\user\StudioProjects\project\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:627: error: duplicate value for resource 'attr/min' with config ''.

C:\Users\user\StudioProjects\project\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:483: error: resource previously defined here.

* What went wrong:
Execution failed for task ':app:mergeDebugResources'.
> Error: java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details

I really don't know why this error is occuring...

EDIT: Full build.gradle:

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

android {
    compileSdkVersion 27

    compileOptions { 
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    defaultConfig {
        applicationId "com.myapp"
        minSdkVersion 16
        targetSdkVersion 27
        multiDexEnabled true
        versionCode 1
        versionName "myVersion" 
        resConfigs "en"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }

        debug {
            ext.enableCrashlytics = false
        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')

    def firebaseVersion = '11.4.2'
    def supportVersion = '27.0.0'

    //Firebase Crashlytics
    compile('com.crashlytics.sdk.android:crashlytics:2.7.1@aar') {
        transitive = true
    }

    //Firebase
    implementation 'com.google.firebase:firebase-auth:' + firebaseVersion
    implementation 'com.google.firebase:firebase-core:' + firebaseVersion
    implementation 'com.google.firebase:firebase-firestore:' + firebaseVersion

    //FirebaseUI
    implementation 'com.firebaseui:firebase-ui-auth:3.1.0'

    //Android Support
    implementation 'com.android.support:support-v4:' + supportVersion

    implementation 'com.android.support:appcompat-v7:' + supportVersion
    implementation 'com.android.support:cardview-v7:' + supportVersion
    implementation 'com.android.support:gridlayout-v7:' + supportVersion
    implementation 'com.android.support:recyclerview-v7:' + supportVersion
    implementation 'com.android.support:preference-v7:' + supportVersion

    implementation 'com.android.support:preference-v14:' + supportVersion 

    implementation 'com.android.support:support-vector-drawable:' + supportVersion

    implementation 'com.android.support:design:' + supportVersion

    implementation 'com.android.support.constraint:constraint-layout:1.0.2'

    implementation 'com.android.support:multidex:1.0.2'

    //Material About
    implementation 'com.github.daniel-stoneuk:material-about-library:2.2.3-support26.1.0' //Weird version system

    //OpenCSV
    implementation('com.opencsv:opencsv:4.0') {
        //Transitively requires Apache Commons, which necessitates multidex...
        exclude group: 'commons-beanutils'
    }

    //Gson
    implementation 'com.google.code.gson:gson:2.8.2'
}

apply plugin: 'com.google.gms.google-services'

It wants some more details, so I'll elaborate on the problem. I want to use the AppCompat Preference library, but the error at the beginning pops up whenever I try to add it to my build.gradle.

3

There are 3 answers

0
19lmyers On BEST ANSWER

Apparently the problem was caused by an id in my attrs.xml:

<resources>
    <declare-styleable name="MyView">
        <attr name="min" format="float" />
    </declare-styleable>
</resources>

I fixed this error by changing min to minValue.

4
cshine On

You may go to file->Invalidate caches /restart . This will invalidate any things wrong to you project.. Lets me know if it helps !

0
ישו אוהב אותך On

You can try to excluding support library from Material About library with this:

  implementation ('com.github.daniel-stoneuk:material-about-library:2.2.3-support26.1.0') {
    exclude group: 'com.android.support'
    exclude module: 'appcompat-v7'
    exclude module: 'cardview-v7'
    exclude module: 'design'
  }

Please look at its build.gradle: https://github.com/daniel-stoneuk/material-about-library/blob/master/build.gradle