[英]Android multi module with flavors to maven repository
I've been trying to upload a project to a maven repository unsuccessfully. 我一直试图将项目上传到Maven存储库失败。 Here is my project structure : 这是我的项目结构:
_root
|_ lib1 (aar)
|_ lib2 (aar)
|_ javalib (jar)
Problem is when I launch uploadArchives task I have no pom.xml created. 问题是当我启动uploadArchives任务时,我没有创建pom.xml。 It seems to be due to my flavors (when I remove flavors it works fine), and I can't figure out how to fix this problem. 这似乎是由于我的口味(当我删除口味时效果很好),我不知道如何解决此问题。 I really need to work with flavors ... any help is welcome ;) 我真的需要与口味合作...欢迎任何帮助;)
here are my build.gradle files : 这是我的build.gradle文件:
root : 根 :
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
ext.versionName = "$System.properties.version"
configure(subprojects) {
apply plugin: 'maven'
group = 'com.test.build'
version = project.versionName
uploadArchives {
repositories {
mavenDeployer {
repository(url: "http://localhost:8081/content/repositories/test/") {
authentication(userName: "admin", password: "admin123")
}
}
}
}
}
allprojects {
repositories {
jcenter()
}
}
lib1 : lib1:
apply plugin: 'com.android.library'
android {
publishNonDefault true
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName project.versionName
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
prod{}
intg{}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
intgCompile project(path: ':lib2', configuration: 'intgRelease')
prodCompile project(path: ':lib2', configuration: 'prodRelease')
}
lib2 : lib2:
apply plugin: 'com.android.library'
android {
publishNonDefault true
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName project.versionName
}
buildTypes {
debug {
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
prod{}
intg{}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(path: ':javalib')
}
javalib : javalib:
apply plugin: 'java'
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
I finally found the answer to my issue : it is NOT possible, but it might be possible to do it one day : see documentation about that : http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Library-Publication 我终于找到了解决我问题的答案:这是不可能的,但是有一天可能会做到:请参阅有关文档: http : //tools.android.com/tech-docs/new-build-system/用户导#TOC-库的公开
I went through this problem with this solution : 我通过以下解决方案解决了这个问题:
// default publication is production which will be published without env name
publishNonDefault true
defaultPublishConfig "productionRelease"
if (android.productFlavors.size() > 0) {
android.libraryVariants.all { variant ->
// Publish a main artifact, otherwise the maven pom is not generated
if (android.publishNonDefault && variant.name == android.defaultPublishConfig) {
def bundleTask = tasks["bundle${name.capitalize()}"]
artifacts {
archives(bundleTask.archivePath) {
classifier null
builtBy bundleTask
}
}
}
}
}
I am not satisfied with it but it will do the job for now ... 我对此不满意,但它现在可以做...
I spend a lot time to discover why my Android project din't upload my modules to maven. 我花了很多时间发现为什么我的Android项目没有将我的模块上传到Maven。 The problem is because I didn't set the defaultPublishConfig
inside the android {}
brackets in the file build.gradle
. 问题是因为我没有在build.gradle
文件的android {}
括号内设置defaultPublishConfig
。 The snippet below is how I solved my problem. 下面的代码段是我解决问题的方式。 You need set what flavor you wanna publish to Maven (access build variants tab in the Android Studio to see all your flavors name): 您需要设置要发布到Maven的风味(访问Android Studio中的构建变体选项卡以查看所有风味名称):
android {
...
defaultConfig {
...
defaultPublishConfig "myFlavorDebug"
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.