2015-11-02 74 views
4

我的Android應用程序對這個build.gradle文件沒有問題。Android:屬性'rippleColor'已經定義

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:[email protected]') { 
     transitive = true 
    } 
    // Android Iconics Library by Mike Penz 
    compile 'com.mikepenz:iconics-core:[email protected]' 
    compile 'com.mikepenz:google-material-typeface:[email protected]' 
    // 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:[email protected]' 

    // 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:[email protected]' 

我假定示出此錯誤,因爲新增加的一個包含具有在先前添加的庫中定義的相同名稱的屬性。我應該在這個文件中修改什麼,以便第三方庫不會彼此崩潰?

+0

如果您已經在使用最新的支持庫,您是否真的需要另一個MaterialDesign庫? – codeskraps

+0

@codeskraps因爲在另一個庫中有一個用戶界面,我想使用.. – MarshallLee

+1

這個想法是我不認爲有什麼可以在build.gradle文件中做到的。不要使用該庫,或者如果UI元素很小,您可以手動將它添加到您的項目,只需導入您需要的類和xml屬性 – codeskraps

回答

2

問題是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支持庫),並將其上傳到快照的Maven中央存儲庫的一切。您可以通過以下兩個步驟使用它:

快照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組託管它。

+0

我用你的lib。應用程序編譯成功,但問題是我無法使用'ButtonRectangle'的setText()方法。應用程序總是崩潰。但是,通過將該類更改爲普通的「Button」,該方法工作正常。似乎有些東西是錯誤的lib。謝謝。 – Hesam

1

我修正了這個錯誤。請檢查

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

在值文件夾中的attrs.xml文件中。重構此「rippleColor」值,以便它不會影響您當前使用此名稱。然後在您的gradle這個文件:

compile 'com.github.navasmdc:MaterialDesign:[email protected]' 
compile 'com.nineoldandroids:library:2.4+' 

這個問題應該得到現在固定。

+1

沒有爲我工作:( – Hesam

1

我想它解決了,但我找到了不同的解決方案。它是由niwinnm 導致問題com.android.support:design的解決,所以你應該改變com.github.navasmdc:質感設計:[email protected]這樣一來「com.github.vajro:MaterialDesignLibrary:1.6 「

enter for solution

+0

這對我有效。 –

0

只是刪除的代碼行的build.gradle

編譯 'com.github.navasmdc:質感設計:[email protected]'

如果這存在於您的項目中,它可以提供幫助。