How to publish my android studio project's apk to a remote maven repo? Please let know if you have any idea, I tried but didn't get any document for publishing projects made in android studio. Any links to such documents would be quite useful.
You can use Bintray plugin. First, create your account in Bintray. Then, configure your build.gradle this way:
apply plugin: 'com.jfrog.bintray'
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.4'
}
}
bintray {
user = yourBintrayUser
key = yourBintrayKey
filesSpec {
from 'build/outputs/apk/'
into 'com/yourcompany/project/1.0.0'
}
pkg {
repo = 'maven'
name = 'your-project-name'
vcsUrl = 'yourVcsUrl'
version {
name = '1.0.0'
desc = 'Your Project v.1.0.0'
}
}
}
Now, you will have a Gradle task named 'uploadBintray' and when you execute it, it will create a repository in your Bintray account and will upload all files inside build/outputs/apk in it.
EDIT
If you have a own downloads server, and you don't want deploy the apk in Bintray servers, you can use my gradle plugin GRelease.
Related
I've got few libraries which I want to deploy on Gradle(google repository, etc)
so that anybody can access it using Gradle as we do in android studio app.gradle file
Eg : implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
I want to know the process of deploying, I already have the libraries.
Thank you
1. Make library module in Android Studio [ Assumed that you have prepared ]
2. Create Space on Bintray
Fill in the required information as shown below with your exact module name and your GitHub repo links and click on “Create Package”.
Congrats! You have successfully completed the second step.
3. Upload your library on Bintray and JCenter
Now you need to configure your library so that you can upload it to Bintray followed by JCenter.
Modify the project build.gradle file by adding these below dependencies:
dependencies {
classpath 'com.android.tools.build:gradle:2.3.1'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
}
Add your Bintray authentication details in the local.properties file. That information should not be pushed to the version control system.
bintray.user= “YOUR USERNAME”
bintray.apikey= “YOUR API KEY”
You can find both credentials in your account by following these steps-
Open your Bintray account, click on your name and then click edit under your name and then the API Key tab.
Now we need to modify our module build.gradle file. Open the file and modify according to the below-mentioned steps.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
}
}
ext {
bintrayRepo = 'Utility' // your repo name
bintrayName = 'time-utils' // has to be same as your library module name
publishedGroupId = 'com.timeutility' // your module package name
libraryName = ‘time-utils’
artifact = 'time-utils' // has to be same as your library module name
libraryDescription = 'A set of methods used to manipulate time object'
siteUrl = 'https://github.com/androidCode/time-utils'
gitUrl = 'https://github.com/androidCode/time-utils.git'
libraryVersion = '1.0'
developerId = ‘sachit’
developerName = Sachit
developerEmail = 'sachit.wadhawan#quovantis.com'
licenseName = 'The Apache Software License, Version 2.0'
licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
allLicenses = ["Apache-2.0"]
}
android {
// -------- your target version and all required configuration. These are normal as for other projects and generate by android studio itself
}
dependencies {
// Your dependecies
}
// add it to the bottom of the file
apply from: 'https://raw.githubusercontent.com/numetriclabz/jcenter/master/installv.gradle'
apply from: 'https://raw.githubusercontent.com/numetriclabz/jcenter/master/bintrayv.gradle'
Sync the project. Once everything is configured, run the command below in your terminal, in root of the project.
./gradlew clean build install bintrayUpload
Shout Hurray! if it shows BUILD SUCCESSFUL.
Check your package in the Bintray web interface. You will see a change in Versions area. Now it needs to be pushed to JCenter. Now once your project is up on Bintray, simply hit “Add to JCenter” button to sync with JCenter.
It may take a few hours before your request has been accepted. When it happens, you should get a notification via email and also see the jCenter badge in your package details under the “Linked to” section.
Congratulations! Your library is now on jCenter!!! You can give the gradle path into your project now. For example my dependency looks like this:
implementation 'xxxxxxxxxx:xxxxxx:1.0'
Thank You :)
You need an artifactory. You can use public ones like maven-central, jitpack or create your own by using JFrog.
Then update your library project that able to work with maven to create an artifact.
After that, you are ready to publish.
I would suggest to use jitpack if you are not familiar since its a huge topic.
I am trying to integrate an Android archive (aar) from local Maven to Android studio in my sample project.
I am getting the following build error in Android studio:
A problem occurred evaluating project :app Could not find property HOME on org.gradle.api.internal.artifacts.repositories.DefaultMavenArtifactRepository_Decorated#181db40.
If you are using local maven to work with android studio you need to do this means that to add a reference to an .aar package it would have to ideally be stored in the central maven repository.
A simple and extremely straightforward option is to create a local maven repository on your dev machine, and install your library in there. Then reference it from your gradle build. And doing it is surprisingly simple!.
Since you're developing for android, I assume you already installed the latest JDK and set the JAVA_HOME environment variable, but if you didn't - now is the time.
Then you'd want to install Maven. You can download it here: http://maven.apache.org/download.cgi
Set the MAVEN_HOME environment variable to the path where you extracted maven, and add the maven's bin folder to the PATH environment variable.
To test that maven is working fine, open a new console window and run the following:
mvn -version
If everything is fine, it's time to add your library to the maven repository. In the command prompt run the following:
mvn install:install-file -Dfile=d:\mylibrary-{version}.aar -DgroupId=com.example -DartifactId=mylibrary -Dversion={version} -Dpackaging=aar
Don't forget to replace the proper path to your library, setting your groupId, artifactId and version number.
Finally, edit your build.gradle to start looking at the local maven repository. For example, if you want to use both maven central and your local repo you can add both of them to the repositories configuration.
Here's an example of a very basic build.gradle for an android app using the library we registered above:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4.2'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
compile('com.example:mylibrary:0.2')
}
android {
compileSdkVersion 17
buildToolsVersion '17.0.0'
}
Finally, run the build command to build your app:
gradle clean build.
The main problem is to get the resulting .aar file in the maven publication profile. To do that we'll run a call to android.libraryVariants, which will initialise this object, and create all the subtasks required for the build, including "bundleRelease" which is creating the .aar file.
Here is what my build.gradle file looks like:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4.2'
}
}
apply plugin: 'android-library'
apply plugin: 'maven-publish'
version '0.2'
group 'com.example'
android {
compileSdkVersion 17
buildToolsVersion '17.0.0'
defaultConfig {
versionCode 2
versionName '0.2'
}
}
android.libraryVariants
publishing {
publications {
maven(MavenPublication) {
artifact bundleRelease
}
}
}
If you want to change the artifactId to something custom, you can change the project name in settings.gradle by adding this line:
rootProject.name = 'mylibrary'
That's it. Now open a command prompt in your project's folder and run the following to build and publish your library to the local maven repository:
gradle clean build publishToMavenLocal
A couple basic articles that I used to get this to work:
How to install maven on windows.
Adding local .aar to gradle build
I have an Android aar library I am using with an Android application. It is working correctly with the aar library included directly in the Android project. I would like to move this library to my internal Nexus maven repository, so that other developers can use the library too.
How do I upload the aar to Nexus (the Maven repository)? There is no apparent option to do so in the web interface:
For Android, we normally have two build.gradle files the one at the top level folder, and another one in the specific module:
app/
---build.gradle
---module/
------build.gradle
In the app/build.gradle file of the clients of this library you will have to add:
repositories {
jcenter()
maven {
url "http://localhost:8081/repository/test-maven-repo/"
}
}
For you library app/module/build.gradle file:
apply plugin: 'maven'
uploadArchives {
repositories {
mavenDeployer {
repository(url: "http://localhost:8081/repository/test-maven-repo/") {
authentication(userName: "admin", password: "admin123")
pom.groupId = "com.example.test"
pom.artifactId = "myexample.test"
pom.version = '1.0.0'
}
}
}
}
And you might want to run it just with:
./gradlew upload
Link to official documentation:
Maven Publish Plugin.
I used gradle's maven plugin to upload to Nexus by modifying the Android build.gradle file.
apply plugin: 'maven'
dependencies {
deployerJars "org.apache.maven.wagon:wagon-http:2.2"
}
uploadArchives {
repositories.mavenDeployer {
configuration = configurations.deployerJars
repository(url: "https://my.example.com/content/repositories/com.example/") {
authentication(userName: "exampleUser", password: "examplePassword")
pom.groupId = "com.example"
pom.artifactId = "myexample"
pom.version = '1.0.0'
}
}
}
To upload: gradlew upload, using the gradlew script that is provided by the Android Studio project.
You can also move the authentication parameters into a file that is not version controlled.
Use maven deploy plugin. Example command:
mvn deploy
This assumes you have correctly configured your pom.xml with distributonManagement section, telling all it needs to know about your Nexus repo
If you're that kind of people who dislike changing your pom.xml, or worse if your code doesn't even have pom.xml but you still want to upload to Nexus anyway, then you can still do it using
mvn deploy:deploy-file -Durl=http://mycompany/nexus/repo/blah -Dfile=/path/to/my/foo.aar -Dpackaging=aar -DgroupId=com.mycompany -DartifactId=foo -Dversion=1.2.3
Refer to maven deploy plugin doc for more info: https://maven.apache.org/plugins/maven-deploy-plugin/
If you are building your project using Gradle, here there is a good tutorial to push your artifacts to Nexus:
https://medium.com/#scottyab/how-to-publish-your-open-source-library-to-maven-central-5178d9579c5#.acynm6j49
Basically, it adds a new Gradle task (uploadArchives) to push your artifacts. So doing something like:
>gradle clean build uploadArchives
You can upload it with Maven or Gradle or manually.
For the manual upload you can just type the package value in the input to be 'aar' and upload as you desire.
It doesn't make any sense that why nexus package have nothing for #aar file but if you try to upload it as a jar then it will not block you and everything is work as it is..
I want to install android library project to local maven repository.
Here is build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android-library'
apply plugin: 'maven'
version = "1.0.0-SNAPSHOT"
group = "com.example"
repositories {
mavenCentral()
}
android {
compileSdkVersion 18
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 9
targetSdkVersion 18
}
}
When I run:
gradle install -i
it gets stuck here:
Executing task ':project:installTest' due to:
Task has not declared any outputs.
Starting process 'command 'd:\android-sdk-windows\platform-tools\adb.exe''. Working directory: D:\Projects\java\....... Command: d:\android-sdk-windows\platform-tools\adb.exe install -r D:\Projects\java\.......\build\apk\project.apk
An attempt to initialize for well behaving parent process finished.
Successfully started process 'command 'd:\android-sdk-windows\platform-tools\adb.exe''
> Building > :project:installTest
So first thing I noticed is that it's trying for some odd reason to deploy it on a device as APK.
Am I doing something wrong or is it just android-library plugin not compatible with maven plugin?
Edit: Please refer to the github page (https://github.com/dcendents/android-maven-gradle-plugin) for the latest instructions and find the correct version to use. The original instructions are not suitable anymore with the latest gradle release.
Original Post:
I've modified the maven plugin to be compatible with android library projects. See the project on github: https://github.com/dcendents/android-maven-gradle-plugin
Configure your android library projects to use it:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.github.dcendents:android-maven-plugin:1.0'
}
}
apply plugin: 'android-library'
apply plugin: 'android-maven'
Then you should be able to install aar into your local maven repository using the install task.
Hope this helps, if you find issues with the plugin please let me know on github and I'll fix it.
Elaborating on CyclingSir's answer, I propose to add a separate "installArchives" task. This should also take care of picking up your custom artifacts (e.g. sources).
apply plugin: 'maven'
task installArchives(type: Upload) {
description "Installs the artifacts to the local Maven repository."
configuration = configurations['archives']
repositories {
mavenDeployer {
repository url: repositories.mavenLocal().url
}
}
}
Note that with Gradle Android plugin v0.5.5, gradle install still tries to install something on a device.
There's an easier solution if you don't want to use a custom plugin. Instead, just recreate the install task with a different name. I called it installArchives. Add the following code to your build.gradle:
task installArchives(type: Upload) {
description "Installs the artifacts to the local Maven repository."
repositories.mavenInstaller {
configuration = configurations.default
pom.groupId = 'my.group'
pom.artifactId = 'my-artifact'
pom.version = '1.0.0'
}
}
You can now run gradle installArchives to install your aar locally.
UPDATE 2014-11-26
The answer below made sense at the time of writing, when Android Build Tools were at version 0.5.5. It is most likely outdated now and probably does not work anymore.
I have personally switched my projects to use android-maven-plugin as described in the answer above, the plugin works fine with the recent versions of Android Build Tools too.
THE ORIGINAL ANSWER FROM FEBRUARY 2014
Publishing as AAR
If you don't mind using an older version of com.android.tools.build:gradle (i.e. 0.5.4), you can use the approach described in this blogpost. Not that according to the discussion in adt-dev mailing-list, this does not work in 0.5.5.
Add the following lines to your build.gradle:
apply plugin: 'maven-publish'
// load bundleRelease task
// this will not load the task in 0.5.5
android.libraryVariants
publishing {
publications {
maven(MavenPublication) {
artifact bundleRelease
}
}
}
To publish to your local maven repo, call this command:
gradle publishToMavenLocal
Publishing as JAR
If your Android Library does not have custom resources and can be published as JAR, then you can use the following build.gradle that works even with 0.5.5.
// build JAR file
task androidReleaseJar(type: Jar, dependsOn: assembleRelease) {
from "$buildDir/classes/release/"
}
apply plugin: 'maven-publish'
publishing {
publications {
maven(MavenPublication) {
artifact androidReleaseJar
}
}
}
To publish to your local maven repo, call this command:
gradle publishToMavenLocal
I just solved the issue by defining an upload archive as described here:
Gradle documentation 52.6.2. Deploying to a Maven repository
uploadArchives {
repositories {
mavenDeployer {
repository(url: "file://${System.env.HOME}/.m2/repository/")
}
}
}
calling
gradle uploadArchives
deploys the artefact to the (in my case local) Maven repo.
I havn't found a simple and more flexible way to specify the local repo's url with e.g. mavenLocal() yet but the above suits my needs.
I am migrating from Eclipse & maven to Android Studio & Gradle build.
My project structure now in Android Studio looks like this:
MyApp
->LibModule
-src
-...
-lib_repo/
-build.gradle
->AnotherModule
...
LibModule is my library module, I want to install the build jar of LibModule to my local maven repository. What I tried in build.gradle (under LibModule/ )is:
apply plugin: 'android-library'
apply plugin: 'maven'
...
group = 'com.my.lib'
uploadArchives {
repositories {
description "Installs the artifacts to the local Maven repository."
mavenDeployer {
repository(url: "file://${System.properties['user.home']}/.m2/repository")
pom.version = '1.1.0'
pom.artifactId = 'MyLib'
}
}
}
}
I also tried:
install {
repositories.mavenInstaller {
pom.version = '1.1.0'
pom.artifactId = 'MyLib'
}
}
I got error "unsupported Gradle DSL method found 'install()'! ".
When I build it in Android Studio IDE, in gradle console, I didn't see anything happen to upload the archive to my local maven repository. I also checked the content of build/ directory, there is no poms/ folder at all. It seems it is not triggered, I followed the gradle document here. Why? What is wrong?
For installing to the local Maven repository (which is mainly useful when exchanging artifacts with local Maven builds), use the install task rather than uploadArchives. For details, check the Gradle User Guide.