2016-08-15 89 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秒。

我希望这会有所帮助。