Android: 属性 'rippleColor' 已经被定义

Android: Attribute 'rippleColor' has already been defined

我的 Android 应用程序对此 build.gradle 文件没有问题。

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

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "com.marshall.opensurvey"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

repositories {
    jcenter()
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.0'
    compile 'com.android.support:design:23.1.0'
    compile 'com.android.support:support-annotations:23.1.0'
    compile 'com.android.support:support-v4:23.1.0'
    compile 'com.android.support:support-v13:23.1.0'
    compile 'com.squareup.okhttp:okhttp:2.0.0'

    // Material Drawer Library by Mike Penz
    compile('com.mikepenz:materialdrawer:4.3.9@aar') {
        transitive = true
    }
    // Android Iconics Library by Mike Penz
    compile 'com.mikepenz:iconics-core:1.7.9@aar'
    compile 'com.mikepenz:google-material-typeface:1.2.0.1@aar'
    // Google Analytics Library
    compile 'com.google.android.gms:play-services-analytics:8.1.0'
    // Circle Image View Library
    compile 'de.hdodenhof:circleimageview:2.0.0'
    // Flat Button Library
    compile 'info.hoang8f:fbutton:1.0.5'
    // Process Button Library
    compile 'com.github.dmytrodanylyk.android-process-button:library:1.0.4'
    // Fancy Button Library
    compile 'com.github.medyo:fancybuttons:1.5@aar'

    // Card View and Recycler View Library
    compile 'com.android.support:cardview-v7:23.1.0'
    compile 'com.android.support:recyclerview-v7:23.1.0'
}

但是,当我在 build.gradle 文件中添加另一个依赖项并同步时,它开始显示错误,说属性 'rippleColor' 已经被定义。我放在 gradle 文件中的新依赖项是这样的。

// Material Design Library
compile 'com.github.navasmdc:MaterialDesign:1.5@aar'

我认为显示此错误是因为新添加的库包含一个与先前添加的库中已定义的名称相同的属性。我应该在这个文件中修改什么以使第三方库不会相互崩溃?

问题是 MaterialDesign 库没有为其属性添加前缀。

属性在 attrs.xml 中定义,您必须将 rippleColor 属性重命名为其他名称。 这里的一个好建议是为所有特定于该库的属性添加前缀,这样就不会与其他库冲突。

所以它看起来像这样

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="CustomAttributes">
        <!-- Color of ripple animation -->
        <attr name="mdl_rippleColor" format="color|reference" />
        <!-- You can also prefix all other attributes -->
    </declare-styleable>
</resources>

之后,您必须在 MaterialDesign 库的代码中找到所有出现的此内容,并为它们加上前缀,以便可以通过编程方式读取这些属性。一个在 LayoutRipple (Line: 56) class.

这个库似乎也不再积极维护了。大约 200 个未解决问题和 30 个拉取请求。


为了简化一切,我修改并修复了源代码(我还更新了最新的 v23.1.0 支持库)并将其上传到 SNAPSHOT maven 中央存储库。您可以通过执行以下 2 个步骤来使用它:

将 SNAPSHOT maven 存储库添加到您的根 build.gradle

maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }

如图所示:SNAPSHOT maven repository

将依赖项添加到您的 build.gradle

compile 'com.mikepenz.thirdparty:material-design-library:1.5.0-SNAPSHOT'

Here's the link to the SNAPSHOT *.aar。 Maven 组不同,因为我不允许与原始 Maven 组一起托管它。

我修正了这个错误。请检查

<attr name="rippleColor" format="color" />

在值文件夹中的 attrs.xml 文件中。重构此 "rippleColor" 值,使其不影响您当前对该名称的使用。然后在你的 gradle 文件中:

 compile 'com.github.navasmdc:MaterialDesign:1.5@aar'
compile 'com.nineoldandroids:library:2.4+'

这个问题现在应该得到解决。

我想它已经解决了,但我找到了一个不同的解决方案。由niwinnm解决 问题原因 com.android.support:design 所以你应该把 com.github.navasmdc:MaterialDesign:1.5@aar 这个改成 'com.github.vajro:MaterialDesignLibrary:1.6'

enter for solution

只需删除 build.gradle

中的代码行

编译'com.github.navasmdc:MaterialDesign:1.5@aar'

如果您的项目中存在它,它可以提供帮助。