2016-08-15 25 views
0

我想在Android Studio中構建一個arr包。此軟件包包含Zendesk的依賴項:Gradle:如何包含來自存儲庫的依賴關係以輸出aar文件

allprojects { 
    repositories { 
     maven { url 'https://zendesk.artifactoryonline.com/zendesk/repo' } 
    } 
} 

compile (group: 'com.zendesk', name: 'sdk', version: '1.7.0.1') { 
    transitive = true 
} 

compile (group: 'com.zopim.android', name: 'sdk', version: '1.3.1.1') { 
    transitive = true 
} 

我想爲Unity3d項目構建此程序包。這個包應該包含Zendesk的所有依賴關係(transitive = true屬性)。當我打開aar文件時,Zendesk沒有任何依賴關係。哪裏不對?

回答

3

默認情況下,AAR不包括任何依賴項。如果要包括他們,你有,無論是做手工,從artifactory的/你的緩存文件夾,這些庫複製到你的包或這個任務可以幫助你:https://stackoverflow.com/a/33539941/4310905

0

當您編譯項目,它編譯針對必要的庫,但庫不會自動打包。

你需要什麼叫做「fatjar/uberjar」,你可以通過Gradle shadow plugin來實現。

+0

但res會被刪除。 – 2017-03-03 05:29:21

0

我知道這個答案來得有點晚,但仍...

你寫的transitive參數是要包括傳遞依賴(你的依賴的依賴),其中有在pom.xml文件進行設置您設置爲compile的依賴關係。所以你不需要爲aar包裝做這件事,除非它是用於任何其他目的。

首先,認爲你可以打包一些jar S的內部(在 libs文件夾)的aar,但你不能打包aaraar內。

的方法來解決你的問題是:

  • 從你感興趣的依賴獲得解決文物
  • 檢查其解決文物的有jar文件。
  • 如果它們是jar,將它們複製到一個文件夾中,並將dependencies關閉中的文件夾設置爲compile

所以更多或更少的東西是這樣的:

configurations { 
    mypackage // create a new configuration, whose dependencies will be inspected 
} 

dependencies { 
    mypackage 'com.zendesk:sdk:1.7.0.1' // set your dependency referenced by the mypackage configuration 
    compile fileTree(dir: "${buildDir.path}/resolvedArtifacts", include: ['*.jar']) // this will compile the jar files within that folder, although the files are not there yet 
} 

task resolveArtifacts(type: Copy) { 
    // iterate over the resolved artifacts from your 'mypackage' configuration 
    configurations.mypackage.resolvedConfiguration.resolvedArtifacts.each { ResolvedArtifact resolvedArtifact -> 

     // check if the resolved artifact is a jar file 
     if ((resolvedArtifact.file.name.drop(resolvedArtifact.file.name.lastIndexOf('.') + 1) == 'jar')) { 
      // in case it is, copy it to the folder that is set to 'compile' in your 'dependencies' closure 
      from resolvedArtifact.file 
      into "${buildDir.path}/resolvedArtifacts" 
     } 
    } 
} 

現在你可以運行./gradlew clean resolveArtifacts buildaar包將有內部解決jar秒。

我希望這會有所幫助。

相關問題