2016-03-14 31 views
2

在我的Android項目中,我使用的庫很少。問題的關鍵是,當我加入一個新的,例如:資源項目activity_horizo​​ntal_margin已定義

compile(group: 'com.example', name: 'example_sdk', version: '+', ext: 'aar') { 
    transitive = true; 
} 

,並試圖構建項目,我從gradle這個獲得下輸出錯誤:

D:\AndroidStudioProject\MyProject\res\values-w820dp\dimens.xml Error:(2) Resource entry activity_horizontal_margin is already defined. D:\AndroidStudioProject\MyProject\build\intermediates\exploded-aar\com.example\example_sdk\3.2.7\res\values-w820dp-v13\values-w820dp-v13.xml Error:(2, 1) Originally defined here. Error:Execution failed for task ':processMyAppUniversalDebugResources'. com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'D:\Tools\Android_SDK\build-tools\23.0.1\aapt.exe'' finished with non-zero exit value 1

我的猜測是,在一些庫中,我們有默認的定義值-w820d/dimen.xml,它們是衝突的。但問題是如何合併它們,因爲關鍵是一樣的。

values-w820d/dimen.xml content : 
<resources> 
<!-- Example customization of dimensions originally defined in res/values/dimens.xml 
    (such as screen margins) for screens with more than 820dp of available width. This 
    would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). --> 
<dimen name="activity_horizontal_margin">64dp</dimen> 

當我重新命名activity_horizontal_marginactivity_horizontal_margin_default - 衝突解決我的項目,但衝突似乎與其他圖書館。 也許我可以添加一些gradle-override屬性或修改gradle腳本來忽略它?

回答

1

當我問這個問題時,我已經做了一個解決方法。我在values-w820d/dimen.xml內有兩個衝突的庫,默認值爲activity_horizontal_margin。所以,因爲其中一個庫是本地的.aar--我將它解壓縮並刪除了衝突的文件,然後將其壓縮並解決問題。這種方法不是很優雅 - 但它對我很有用。我一直在等待更好的解決方案,但並未到來。所以這樣的混亂應該由圖書館開發者來處理。這裏是Xavier Ducrohet的一個有用答案: https://stackoverflow.com/a/16351116/3874721