我的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)类中。
似乎还没有积极维护此库。大约有200个未解决问题,还有30个请求请求。
为了简化您的工作,我修改并修复了源代码(我还更新到了最新的v23.1.0支持库),并将其上载到SNAPSHOT maven中央存储库。您可以通过执行以下两个步骤来使用它:
将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组一起托管。