rha*_*ter 10 android maven android-build android-gradle-plugin
我正在开发一个包含两个Android库项目的项目.当我将这些库上传到我的Maven仓库(Nexus)时,生成的pom不包含<type>aar</type>依赖项中的元素.
这是我的依赖树
* App1
\
* lib1
|\
| * lib2
* Other libs
Run Code Online (Sandbox Code Playgroud)
您可以在此图中看到我的app依赖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'
}
Run Code Online (Sandbox Code Playgroud)
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'
}
Run Code Online (Sandbox Code Playgroud)
请注意如何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>
Run Code Online (Sandbox Code Playgroud)
请注意,mavenDeployer插件<type>aar</type>在生成pom时遗漏了依赖项中的元素.
在我的应用程序项目(这是一个maven项目)中,我列出了这个依赖项:
<dependencies>
<dependency>
<groupId>com.example</groupId>
<artifactId>lib1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>aar</type>
</dependency>
...
</dependencies>
Run Code Online (Sandbox Code Playgroud)
当尝试使用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
Run Code Online (Sandbox Code Playgroud)
请注意它是如何寻找库的jar版本的.我相信,由于mavenDeployer插件没有<type>aar</type>在生成的pom的依赖项列表中生成,因此maven默认为查找jar.
有谁知道如何使用Gradle构建包含瞬态依赖项的Android库项目?
只需使用任何文本编辑器将 aar 添加到 pom 即可。之后,在项目的根目录(pom 所在的位置)中打开控制台并运行“mvn clean install”。aar 工件将生成并部署到您的 Maven 存储库。
无论如何,使用 Maven 创建 aar 库要容易得多。只需使用任何 android 库原型创建一个 Maven 项目(de.akquinet 非常好,但您必须使用 3.8.2 和 3.9 之间的插件版本,http://mvnrepository.com/artifact/de.akquinet.android。原型)。只需创建项目,添加库,然后运行命令“mvn clean install”将它们安装到本地 maven 目录中。之后,只需将它们用作普通的 aar 依赖项即可。
| 归档时间: |
|
| 查看次数: |
663 次 |
| 最近记录: |