I've juste added some flavors
(or productFlavors
if you want) to my project.
The fact is that when I publish the library to bintray, all flavors are uploaded (which is great), but I'm unable to use them. The plugin used is the official one here.
The uploaded aar:
androidsdk-0.0.4-fullRelease.aar
androidsdk-0.0.4-fullDebug.aar
androidsdk-0.0.4-lightRelease.aar
androidsdk-0.0.4-lightDebug.aar
As you noted, the fullRelease
is named as the classifier
, see doc chapter 23.4.1.3.
I am searching for a solution to choose which flavors that I want to upload.
I've already looked at bintray examples (here and here) and this, with also other examples but I'm still stuck.
Here is my current script:
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'
buildscript {
repositories {
jcenter()
}
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
minSdkVersion 9
targetSdkVersion 23
versionCode 64
versionName "0.0.4"
}
publishNonDefault true
productFlavors {
full {
}
light {
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:recyclerview-v7:23.1.1'
fullCompile 'com.squareup.picasso:picasso:2.5.0'
}
version = android.defaultConfig.versionName
uploadArchives {
repositories.mavenDeployer {
pom.project {
packaging 'aar'
}
}
}
////////////////////////////////
// Bintray Upload configuration
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
bintray {
user = properties.getProperty("bintray.user")
key = properties.getProperty("bintray.apikey")
configurations = ['archives']
pkg {
repo = "MyRepo" // repo name
userOrg = 'hugo'
name = "AndroidSDK" // Package name
websiteUrl = siteUrl
vcsUrl = gitUrl
publish = true
}
}
To import the library I'm currently using this:
compile ('com.example.lib:sdk:0.0.8:fullRelease@aar') {
transitive = true;
}
The setup:
The fix:
This fix will still publish all the artifacts, but it will publish a default artifact without the flavour suffix, which is enough to make it all work.
The fix to upload only the default artifact would be this (if the bintray plugin knew what POM filters are):
I faced the same challenge, and here's the best I could make yet:
Using
mavenPublications
and the gradlemaven-publish
plugin along the bintray plugin, you can publish any variant to mavenLocal and bintray.Here's the
publish.gradle
file I apply at the end of all my project's library modules I want to publish:In order for this to work, I need to have the
bintray_user
andbintray_api_key
properties defined. I personally just have them in my~/.gradle/gradle.properties
file like this:I also need to define the following ext properties I used in the
publish.gradle
file in my root project'sbuild.gradle
file:And now, I can finally use it in my android library module, where I have multiple
productFlavors
. Here's a snippet from a publishable library module'sbuild.gradle
file:When you have all of this setup properly, with the name of your library instead of mine's (which you can use as an example), you can try publishing a version of your flavored library by trying to first publishing to mavenLocal. To do so, run this command:
You can then try adding
mavenLocal
in your app's repositories (example here) and try adding your library as a dependency (artifactId should be the flavor name, with "_" replaced with "-") and building it. You can also check with your file explorer (use cmd+shift+G on Mac in Finder to access hidden folder) the directory~/.m2
and look for your library.When it's time to publish to bintray/jcenter, you just have to run this command:
Important:
Before you publish your library to mavenLocal, Bintray or another maven repository, you'll usually want to try your library against a sample app which uses the library. This sample app, which should be another module in the same project just need to have the project dependency, which should look like this:
compile project(':myLibrary')
. However, since your library has multiple productFlavors, you'll want to test all of them. Unfortunately, it's currently impossible to specify which configuration you want to use from your sample app'sbuild.gradle
file (unless, you usepublishNonDefault true
in your library'sbuild.gradle
file, which breaks maven and bintray publications), but you can specify the default configuration (i.e. buildVariant) in your library's module as such:defaultPublishConfig "myLibraryDebug"
in theandroid
closure. You can see the available build variants for your library in the "Build Variants" tool Windows in Android Studio.Feel free to explore my library "Splitties" here if you need an example. The flavored module is named
concurrency
, but I use my script for unflavored library modules too, and I tested it throughly on all the library modules in my project.You can reach me out if you need help setting it up for you.
If someone is still stuck with this problem here's what worked for me -
Let's say you want to publish the release build for your flavour1 add this to your
build.gradle
Remove
publishNonDefault true
if it is present in your gradle file.Add this inside the
bintray
block like thisThen just run the
bintrayUpload
task as you would.The
defaultPublishConfig
will have to be changed everytime you need to publish a new flavour.It sounds like you don't want the classifier in the filename. It looks like the classifier is the same as the generated library file name. Have you tried giving them the same filename but outputting them to separate directories? E.g. in the android scope:
I didn't try it so I will delete the answer if it doesn't resolve the issue.
You should post a different artifact for each flavor (or build variant if you prefer).
In this way you will have in jcenter x artifacts, each of them with a pom file.
Something like:
In your top level file you can define
Then in your library module:
Finally make sure to publish only the release build type (why also the debug version?)