【发布时间】:2014-11-19 11:41:54
【问题描述】:
我正在开发一个包含两个 Android 库项目的项目。当我将这些库上传到我的 Maven 存储库 (Nexus) 时,生成的 pom 不会在依赖项中包含 <type>aar</type> 元素。
这是我的依赖树
* App1
\
* lib1
|\
| * lib2
* Other libs
您可以在此图中看到我的app 依赖于lib1,而lib1 又依赖于lib2。这两个库都是 Android 库项目,因此是 AAR。
Lib1/build.gradle
apply plugin: 'com.android.library'
apply from: 'https://raw.github.com/chrisbanes/gradle-mvn-push/master/gradle-mvn-push.gradle'
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion 20
versionCode 1
versionName "1.0"
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
provided project(':lib2')
compile 'com.squareup.picasso:picasso:2.3.3'
}
Lib2/build.gradle
apply plugin: 'com.android.library'
apply from: 'https://raw.github.com/chrisbanes/gradle-mvn-push/master/gradle-mvn-push.gradle'
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion 19
versionCode 1
versionName '1.0'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:19.+'
compile 'com.squareup.retrofit:retrofit:1.6.1'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.0.0'
compile 'com.squareup.okhttp:okhttp:2.0.0'
}
注意Lib1 如何将Lib2 包含为project() 依赖项。
现在,当我使用 Chris Banes 出色的 gradle-mvn-push 插件部署它时,一切都按预期工作。在生成的 pom.xml 中我只注意到一个奇怪的地方。
<dependencies>
<dependency>
<groupId>com.example</groupId>
<artifactId>lib2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
...
</dependencies>
请注意,mavenDeployer 插件在生成 pom 时遗漏了依赖项中的 <type>aar</type> 元素。
在我的应用项目(这是一个 maven 项目)中,我列出了这个依赖项:
<dependencies>
<dependency>
<groupId>com.example</groupId>
<artifactId>lib1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>aar</type>
</dependency>
...
</dependencies>
尝试使用 Maven 构建它时,我收到以下错误。
Could not resolve dependencies for project com.example:app:apk:1.0.0-SNAPSHOT: The following artifacts could not be resolved: com.example:lib2:jar:0.0.1-SNAPSHOT
注意它是如何寻找库的 jar 版本的。我相信,由于 mavenDeployer 插件未在生成的 pom 的依赖项列表中生成 <type>aar</type>,因此 maven 默认会查找 jar。
有人知道如何使用 Gradle 构建包含临时依赖项的 Android 库项目吗?
【问题讨论】:
标签: android maven android-gradle-plugin android-build