2016-04-22 30 views
5

我有一個Android應用程序項目,其中包含獨立的Android庫模塊,它以二進制格式發佈。我想添加一個能力,在從源代碼構建庫或使用發佈的工件之間切換gradle。 Android應用程序在默認情況下取決於二進制神器:具有庫的Android應用程序的Gradle - DependencySubstitution

compile "com.example.konstantin.mylibrary:mylibrary:${mylibraryVersion}"

現在我想通過源代碼來代替我的二進制神器,所以我加根的build.gradle文件下面的代碼:

configurations.all { 
resolutionStrategy { 
    dependencySubstitution { 
     substitute module("com.example.konstantin.mylibrary:mylibrary:${mylibraryVersion}") with project(':mylibrary') 
    } 
} 

但是,當我試圖構建gradle仍然採取二進制神器。這裏有什麼問題?

here is the full source code

同樣有趣的是,如果我移動依賴性替代代碼allprojects部分或應用程序模塊的build.gradle文件,比gradle這個構建失敗,以下消息:

Error:Module version MyApplication:app:unspecified, configuration '_debugCompile' declares a dependency on configuration 'default' which is not declared in the module descriptor for MyApplication:mylibrary:unspecified 
+1

似乎[此android插件錯誤](https://code.google.com/p/android/issues/detail?id=189483)可能與問題有關 – akd005

回答

1

最後,我已經找到了一個工作解決方案。不知何故,如果我反過來這樣做的話。相反,與項目模塊

substitute module("com.example.konstantin.mylibrary:mylibrary:${mylibraryVersion}") with project(':mylibrary') 

替代二元的,我可以替代項目模塊二進制:

substitute project(':mylibrary') with module("com.example.konstantin.mylibrary:mylibrary:${mylibraryVersion}") 

,比神品。 完整的工作代碼可以在separate branch of an example repo

但是這不是一個理想的解決方案,因爲我總是在settings.gradle鏈接項目模塊,不能建立一個沒有檢查出來。

相關問題