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.
Related
how to import JAR or AAR package as new project module in A new Android Studio Arctic Fox | 2020.3.1 Canary 9 ?
please let me know.
This works on Android Studio Arctic Fox Beta 02
Step 1 : Navigate to, File -> Project Structure. You can also press Ctrl+Alt+Shift+S
You will see a window just like below.
Step 2 : Click On app module as shown in image
Step 3 : Click on + icon as marked in image
Step 4 : You will see option to select jar/aar dependency. Click on it
You will see another window just like above asking you to specify path. Specify the path in which you kept the aar/jar file and hit Ok.
That should work
You can directly implement using JAR/ARR file path.
implementation files('/File Path/file.aar')
For Android Studio Bumblebee, original answer given here
I have followed steps suggested by the Android developer site:
Copy .aar file into the libs folder of the app
File -> Project Structure... -> Dependencies
Click on "+" icon and select JR/AAR Dependency and select app module
Add .aar file path in step 1.
Check your app’s build.gradle file to confirm a declaration.
Step 1: Put your aar file in the libs folder. And let’s take the file name is supernover.aar as an example.
Step 2: Put the following code in your Project level
build.gradle file,
allprojects {
repositories {
jcenter()
flatDir {
dirs 'libs'
}
}
}
and in the app level module write the below code,
dependencies {
Implementation(name:'supernover', ext:'aar')
}
Step 3: Then Click sync project with Gradle files.
If everything is working fine, then you will see library entry is made in build ->intermediates -> exploded-aar.
In my opinion, the best way to do this is to deploy the jar/aar to a local maven repository. if you install maven, you can use the mavenLocal() repository in gradle and read from there as with any other repo, regardless of the IDE you are using. All versions of Android Studio will work, all version of IntelliJ will work, VSCode will work, the command line will work, etc. Another advantage is, you'll be able to swap versions of the library as you do with all the others, just change the version in gradle (after deploying the new one), and will work for all your projects. Putting jars/aars manually into a project is just a bad practice, and reaaally outdated to top.
Once you installed maven, type this in your terminal:
mvn install:install-file -Dfile=d:\mylibrary-{version}.aar -DgroupId=com.example -DartifactId=mylibrary -Dversion={version} -Dpackaging=aar
Where you swap aar and jar depending on the type. The package name, group ID and library name are up to you, anything will work. I would use the library's package and name, and version 1.0 if you don`t have a version.
Here's an example link. Is old, but the process is the same. mvn install, then consume from mavenLocal().
For anyone in search of a solution still.
Create a new android Application project.
Convert new project into a standalone Library module.
Add maven-publish plugin to the module-level build.gradle
Connect your project to your Github repository (or create a new one).
In the module-level build.gradle, implement the Github Packages authentication flow. I'm using 'zuko' as an example - replace every instance of that name with your Github login.
android {
...
publishing {
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/zuko/[git-repository]")
credentials {
username = 'zuko'
password = 'token' // this is a Git Personal Access Token
}
}
}
publications {
release(MavenPublication) {
groupId 'com.zuko.libraries'
artifactId 'choose-a-name'
version '1.0.0'
artifact("$buildDir/ogury-mediation-mopub-5.2.0.aar")
// you can actually put the artifact anywhere you want.
// This is the location of where you place your .aar file
}
}
}
...
}
If everything is connected properly, save your work, and run the the task: ./gradlew publish. The error logs are straightforward so just defer to the instructions and Google for more assistance.
To install a successfully published package into your desired project, use the same auth procedure for publishing.repositories, you don't need the second half, publishing.publications.
example: implementation 'com.zuko.libraries:choose-a-name:1.0.0'
You could configure a repository in you buildscript that looks for dependencies in a local directory
Use this to register a local directory as repository in your app module's build.gradle where libs is a directory under app module (<project>/app/libs/)
buildscript {
repositories {
flatDir { dirs 'libs' }
}
}
then declare your dependencies from the local file tree you registered earlier
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
}
This will include all jar/aar artifacts present under libs directory to be included in your module's dependencies.
PS: Local jar/aar artifacts will expect any transitive dependencies to be on the classpath unless they are fat-jars (package all transitive dependencies within the artifact), so these need to be added explicitly as dependencies.
Two flavors but just i need to use Analitic-kit in: online flavor (when comment all about analitic-kit can build ),i need rigth way ,(thank you any suggestions)
Trying this
app
/src
/main
/online
agconnect-services.json
/offline
I get
HAPlugin cannot find "agconnect-services.json" in path: "C:\Users\XL\AndroidStudio\ProjectDemoWithAnalitic\app". Please check the file.*
****
dependencies {
classpath 'com.huawei.agconnect:agcp:1.4.0.300'
classpath 'com.huawei.hms.plugin:analytics:5.0.1.300'
}
Solution:
Please remove the following code:
classpath 'com.huawei.hms.plugin:analytics:5.0.1.300'
apply plugin:'com.huawei.hms.plugin.analytics'
Description:
Based on the Analytics Kit Integration Documentation, the HMS Core SDK integration consists of the following steps:
Add the AppGallery Connect configuration file of the app to your Android Studio project.
Add the Maven repository address and Analytics service dependencies in the build.gradle file of your project.
maven {url 'https://developer.huawei.com/repo/'}
classpath 'com.huawei.hms.plugin:analytics:5.0.1.300'
Add the plug-in configuration and SDK version to the build.gradle file in the app directory.
apply plugin:'com.huawei.hms.plugin.analytics'
implementation 'com.huawei.hms:hianalytics:5.0.1.301'
Click Sync Now or Sync Project with Gradle Files to build a project.
The function of the plug-in is to check whether the integration with Analytics is complete. Besides, the plug-in does not support the flavor. Therefore, if you use flavors, you are advised not to use the analytics plug-in.
I'm using the oss-licenses plugin (Android - Including Open Source Notices) for my Android app to gather the license information from all the open source repositories being used.
But some publishers have not included the <licenses> tag in their repository's POM file. This is why the plugin won't find the license file and these libraries are missing when using OssLicensesMenuActivity to display the listing.
Is there a way to enter additional entries for OssLicensesMenuActivity?
There is still no easy way to do this. However, there is an open merge request that would add this feature.
Anyway, I solved it with a workaround. First, create an empty library and publish it to your local maven(or some other maven repo), and then add the library as a dependency.
You can publish the library to the local maven repo using this plugin.
The gradle file of the library would look like this:
publishing {
publications {
release(MavenPublication) {
groupId = "com.stephan"
artifactId = "mylib"
version = "1.0.0"
pom {
name = 'The name I want to show in the list'
licenses {
license {
name = 'The license'
url = 'https://url.to.license'
}
}
}
}
}
}
And the command to publish to the local maven repo: ./gradlew :nameoflibmodule:publishToMavenLocal
In the app project this can be easily added as a dependency with the usual implementation 'com.stephan:mylib:1.0.0' (also add mavenLocal() to the repositories in the build file)
The library can be empty, the only important part is that there is a pom file containing a <licenses> element. This can be verified by looking into the local maven repo at $USER_HOME/.m2/repositories/
For my example this would be $USER_HOME/.m2/repository/com/stephan/mylib/1.0.0/mylib-1.0.0.pom
I have a project that have the following structure:
projectRoot
build.gradle
module1/
build.gradle
artifact1.aar
module2/
....
My artifact1.aar is a compiled artifact and i have no access to the sources.
my module 1 gradle build file is the following:
configurations.maybeCreate("default")
artifacts.add("default", file('artifact1.aar'))
With this the code contains in the .aar is available in module 2 by simply reference a gradle project dependency.
But i want to publish the .aar in my maven local, in order that it can be accessible for other android project.
I check the maven-publish plugin and the android-maven-publish plugin but the two seems to be called after java-library plugin or com.android.library plugin.
So my question is how to publish in my maven local repository an existing aar with gradle ?
I'm using gradle in version 4.8.
I used an rxbinding aar for this example.
As you correctly mentioned, there has to be a subproject in the "publisher" project, which must contain the aar, and a build file with the following content:
// rxbinding/build.gradle
apply plugin: "maven-publish"
configurations.maybeCreate("default")
def publishArtifact = artifacts.add("default", file('rxbinding-2.1.1.aar'))
publishing {
publications {
aar(MavenPublication) {
groupId = 'my.sample.artifact'
artifactId = 'somerandomname'
version = '1.0.0'
artifact publishArtifact
}
}
}
You can apply the maven-publish plugin to any project, but then you have to define the artifacts manually, like we've just done here. Some plugins (like the java-library plugin) are integrated with the maven-publish plugin to automatically publish the default artifacts of the project.
Now run ./gradlew rxbinding:publishToMavenLocal - This should place the artifact into your local repo
Add implementation 'my.sample.artifact:somerandomname:1.0.0' to the consumer app, in any project on your machine.
It is very important to mention any aar published this way, will not bring it's dependencies, so you have to know what libs are needed to actually use the published aar.
I have also created an example project, where you can try this.
If you have maven installed, you could use the install-file goal of the maven-install-plugin.
I'm trying to publish an Android library as a Maven artifact on a Bitbucket repository, starting from this article that was linked in an Android Weekly newsletter issue some time ago. The article describes how to perform publication and how to link the published artifact from another Android project. However, I have not even managed to make the publishing part to correctly work.
Currently, this is the relevant content of the build.gradle file belonging to the library project:
apply plugin: 'maven'
allprojects {
repositories {
jcenter()
maven {
url "https://raw.github.com/synergian/wagon-git/releases"
}
}
}
configurations {
deployerJar
}
dependencies {
deployerJar 'ar.com.synergian:wagon-git:0.2.5'
}
The relevant parts of the build.gradle file of the library module in the project are as follows:
apply plugin: 'maven'
uploadArchives {
configuration = rootProject.configurations.archives
repositories {
configuration = rootProject.configurations.deployerJar
mavenDeployer {
pom.groupId = 'com.example'
pom.artifactId = 'example-library'
pom.version = '1.0.0'
repository(url: "${bitbucketUrl}") {
authentication(userName: bitbucketUsername, password: bitbucketPassword)
}
}
}
}
where bitbucketUrl, bitbucketUsername and bitbucketPassword are included in the gradle.properties file at the root of the project.
So, what's the problem? When I run the uploadArchives task from Android Studio, Gradle shows that the operation has been performed successfully. But nothing appears on the Bitbucket repository.
Nothing is also written about the structure of that repository, except on Wagon Git's website (calling it documentation seems a little bit of a stretch to me) where, given repository URL of the form
git:releases://git#github.com:synergian/wagon-git.git
it is said that releases represent a branch of the repository. I obliged that part about the structure, even tried to add a repository directory (to mimick the local Maven repository on my machine) but with no luck, and, above all, no clue.
An even more severe issue is that, while I was experimentating with different configurations, I noticed I had the repository URL wrong; however, never, ever, during execution, Gradle noticed the error, and warned or informed me with a suitable message. This lead me to suspect that it wasn't even preparing the artifact to upload, nor trying to connect to Bitbucket, but I was not able to find any pointer as to understand why.
Finally, an even more strange thing happens: when I comment out the line:
configuration = rootProject.configurations.deployerJar
in the module build.gradle file and I run the uploadArchives task, Gradle stops with an error saying that it is unable to find a proper wagon to manage the git protocol, which is expected; however, in the process, the Maven artifact appears in the local repository on my machine. So, by making the publishing process crash, at least I am able to work locally with my library from other projects depending on it, through Gradle management of Maven-like dependencies.
What am I doing wrong?
Fails silently, turn on --info. Probably the biggest hurdle in debugging the problem. For some reason, the folks who wrote the wagon-git deployer decided to write out error messages at the info level. So gradle fails silently without showing you any error messages. This is one of the messages I got with --info turned on:
[INFO] [git] fatal: 'git#bitbucket.org/foragerr/mvn-deploy-test.git' does not appear to be a git repository
This is apparently a fatal error, but as far as gradle is concerned, everything is fine and dandy. Once you start reading these error messages, we can make real progress!
git url: The git URL as outlined here, starts with git:. The wagon-git deployer is activated when the url starts with git:. It is possible to use a https: url, but maven plugin will use an internal deployer rather than wagon-git. To explicitly use wagon-git, the url has to start with git:
repository(url: "git:releases://git#bitbucket.org:foragerr/mvn-bitbucket-deploy-test.git")
where
releases is branch
foragerr is bitbucket username
mvn-bitbucket-deploy-test is bitbucket repo
Authentication: wagon-git uses SSH to connect to bitbucket. You need to setup both git on the local end and bitbucket repo on the remote end to use SSH.
Setting up SSH for git (I recommend not using a passcode, less secure, but convenient for automated deployments)
All Set! deploy to your bitbucket repo using gradle uploadArchives. See example repo here.
Sample build.gradle:
group 'net.foragerr.test'
version '1.2-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'maven'
sourceCompatibility = 1.5
repositories {
mavenCentral()
maven {
url "https://raw.github.com/synergian/wagon-git/releases"
}
}
configurations {
deployerJar
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
deployerJar "ar.com.synergian:wagon-git:0.2.3"
}
uploadArchives {
repositories.mavenDeployer {
configuration = configurations.deployerJar;
repository(url: "git:releases://git#bitbucket.org:foragerr/mvn-bitbucket-deploy-test.git")
}
}
Here is all you need to do, you even need to use the git protocol (this examples show how to use the HTTPS instead):
1) create an app password for your app in Bitbucket
https://bitbucket.org/account/user/YOUR_USERNAME_HERE/app-passwords
2) inside build.gradle:
apply plugin: 'java'
apply plugin: 'maven'
// artifact --> rootProject.name at settings.gradle <--
// DOWN HERE just add your artifact INFO
group = 'br.com.fora.temer'
version = '0.1-SNAPSHOT'
description = """Diretas Ja"""
dependencies {
// your dependencies goes here, like this -->
// compile group: 'br.gov.governo', name: 'golpista', version:'2.0'
}
apply from: 'uploadArchives.gradle' // --> deploy configuration
3) inside uploadArchives.gradle (you need to create it):
configurations {
deployerJars
}
dependencies {
deployerJars "ar.com.synergian:wagon-git:0.2.5" // plugin
}
uploadArchives {
configuration = configurations.archives
repositories.mavenDeployer {
configuration = configurations.deployerJars
repository(url: "git:releases://https://YOUR_USERNAME:YOUR_APP_PASSWORD#bitbucket.org/YOUR_COMPANY/repo-release.git")
snapshotRepository(url: "git:snapshots://https://YOUR_USERNAME:YOUR_APP_PASSWORD#bitbucket.org/YOUR_COMPANY/repo-snapshot.git")
}
}
allprojects {
repositories {
mavenCentral()
maven { url "https://raw.github.com/synergian/wagon-git/releases"}
}
}
To deploy use:
gradle uploadArchives
TIP: beware the order of the entries... if you change it, it will break everything.
I know the question is old, but there isn't a lot of information on the topic, so I guess it is the right place to add some clues. I faced the same problems, there seemed to be no way to get it working. So there are some clues which might help:
As already been said, this whole maven plugin wagon thingy uses SSH to connect to repository (Bitbucket in my case). So you need to check a few things:
that Bitbuchet knows about your SSH key.go to your profile settings(not repository settings!) -> SSH keys and put there your public key received by keygen. There is instruction in the little 'insert key' window on Bitbucket to help you out.
that you have added your private key generated by keygen to your ssh agent (type ssh-add ~/.ssh/id_rsa fot Linux and probably mac)
also add credentials to your repository element:
repository(url: 'git:releases://git#bitbucket.org:gendalf/repo.git'){
authentication(userName: "gendalf", password: "swordfish") }
That plugin won't get confuzed about your output file. When I started to try uploading my library to the repository, I had flavors in it, so plugin didn't know which variant to select and selected nothing (apparently).
this stuff doesn't work with flavors as far as I know. So if you have flavors in the library which you are posting to private repository... consider getting rid of flavors. You probably don't need them anyway.
if you tried other publishing plugins before trying out maven (for example maven-publish), comment out all the script related to other stuff or delete it. My gradle was confused because of the additional scripts.
Consider trying out this https://jeroenmols.com/blog/2016/02/05/wagongit/ solution. It's what I used to finally publish, although it is pretty confusing about checking out from your just-created repository. Don't check out. Create the repository and publish right after that.
I hope this helps.