When using Android Studio, I am aware that you can add dependencies like so:
Then you can search to find repositories, and Android Studio will notify you when you need to update the version of your library dependency.
I also have a library (currently on Bintray), but it doesn't appear in the library dependency list (as in the first screenshot) - is this because the list shows libraries from Maven Central?
If so, how would I go about putting my library on Maven Central? I have looked at some results on Google, but different blog pages and tutorials show different steps, so it can be very confusing.
Since my library (view on GitHub) is using the Novoda Bintray Release plugin, I have tried following the instructions from this wiki page to add my library to Maven Central, but I'm not really sure where to go from here.
So, to summarise, what I am asking is:
Do I need to upload my library to Maven Central?
If so, how would I do that? Should I carry on using the Novoda plugin, or should I switch to something easier to use.
The current default maven repository for android gradle plugin is not Maven Central, but JCenter, and this is probably what you are looking for. If you currently have a library deployed to your maven repository on Bintray, publishing to JCenter (also managed by Bintray) is very easy and requires clicking a button, describing your library and waiting for approval. The whole process is neatly explained here.
Related
I've created an Android library called Library and I want to publish it to a private maven repository and then consume it in an app called App.
I am encountering an issue however which is making the usage of the library untenable for App. The issue is that one of the dependencies of Library is hosted in a "non standard" maven repository, and is forcing the consuming App to add this repository to it's repositories block.
To explain this further; Library has lots of dependencies, most of which are pulled from google and mavenCentral repositories (both of which the consuming App has in the repositories block because all Android apps will include these repositories). However, one of the dependencies, Quikkly, is hosted in a "non standard" maven repository (i.e. one with a non standard URL), which also requires a github personal access token to access. So in my Library repositories block, I have to add this maven repo in order to pull this specific dependency:
maven {
url 'https://maven.pkg.github.com/quikkly/quikkly-android-sdk'
credentials {
username = <github_username>
password = <github_access_token>
}
}
All well and good; I can build Library just fine, and the Quikkly dependency is pulled successfully from this repository.
The issue arises when I use Library in App. I published Library to mavenLocal (or my own private maven repository depending on when I'm ready to actually push a release). When I pull Library into App and then build, the build fails because Quikkly could not be resolved.
The errors show that the locations searched were just the repositories defined in App and not those defined in Library. I can make the build succeed if I add the Quikkly custom maven repo (and github access token) to App but I don't want to force App developers to need to add custom repos just to use my library - surely my library should be responsible for properly packaging it's own dependencies such that consumers just need to use my library via a one line gradle import.
I've done some research on this, and I think the solution involves adding the custom maven repository URL to a <server> element in my libraries .pom file, however the repository also requires a github username and personal access token in order to pull the library from it... my research shows that I need to add these details to "somewhere" (but not in the .pom file as this would be insecure and/or wouldn't even work).
I'm now getting pressured to release something working, but I'm pretty stuck with this. Can anyone help?
I have an Android application using an Android library. The library is a pretty big open-source project on GitHub, and its authors publish the artifacts to Bintray. I can specify the dependency with the usual syntax dependencies { implementation 'group:artifact:version' } in the app's build.gradle.
Now I want to change some code in the library. I git clone it on my machine, I make my changes, then I build the library. But how can I tell my app to use the library I built locally, instead of the one in Bintray?
I don't want to follow the approach in Gradle Local Project Dependency, because that means that the library code is now part of the application project, but I really want to keep things separated.
I think the solution involves publishing to a local Maven repository. I followed the guide at https://proandroiddev.com/tip-work-with-third-party-projects-locally-with-gradle-961d6c9efb02 but the app's Gradle is still picking the original library from Bintray.
Bintray-based projects have the install task. That's the one to be used instead of publishToMavenLocal.
When using install, the artifact version is automatically set to X.X.X before publishing to the local repository. Therefore, in order for the app to pick up the local library, you have to edit the implementation row to group:artifact:X.X.X.
As the guide https://proandroiddev.com/tip-work-with-third-party-projects-locally-with-gradle-961d6c9efb02 suggests, you also need to add mavenLocal() as the first entry in the repositories section in the top-level build.gradle of the application.
It is possible to easily use third party libraries with gradle. For example, the following allows me to use Retrofit in my app.
dependencies {
compile 'com.squareup.retrofit:retrofit:1.9.0'
}
How does this work? Where does the library come from? In general terms, how would I go about publishing a library so that other people can import it like this?
Note: this is not a duplicate of Publish jar library to bintray using gradle/publish-jar-library-to-bintray-using-gradle. That question was asking a spefic question about one particular way to publish libraries.
Lots of this is answered in this tutorial.
How does this work?
Gradle imports the libraries from a Maven repository. The Maven repository can contain both regular .jar files and regular .aar files.
Where does the library come from?
By default, new versions of Android Studio import from JCenter. JCenter is a Maven Repository run by the company Bintray.
If you look at your Android Studio project's build.gradle, you'll see the following lines
repositories {
jcenter()
}
This tells gradle where it should look when attempting to import com.squareup.retrofit:retrofit:1.9.0.
In general terms, how would I go about publishing a library so that other people can import it like this?
You need to create a Bintray account in order to upload to JCenter since Bintray owns JCenter. Bintray's website is pretty easy to use compared to what Maven Central, the past default Maven Repository used by Android Studio.
After you've created a normal Library module inside Android Studio, you'll need to hand tweak your library module's build.gradle file in order to configure it for Maven. Finally, you use a pre-baked script to upload everything to Bintray.
I made a android library in github that i want to add to Gradle,
that other people can add
compile "my project ..."
to there android build.
how can i upload it to Gradle?
(I didn't find an answer for this anywhere)
EDIT:
To clear my question, I want to release a library for developers.
Thanks
You don't "upload a library to gradle" ;-), you make it accessibla via gradle, so you first have to compile your library and publish the generated artefacts (aar or jar files) to a central repository, like Maven Central.
There are two common Maven repositories at time of this writing:
Maven Central http://search.maven.org/
JCenter https://bintray.com/bintray/jcenter
See this guide as a direction for mavenCentral:
http://www.vandalsoftware.com/post/52468430435/publishing-an-android-library-aar-to-a-maven
Since recent Android Studio versions, JCenter is the preferred default repository, so you may register there and upload your archives to it, like explained here:
https://www.virag.si/2015/01/publishing-gradle-android-library-to-jcenter/
Hope that helps.
The easiest way to expose your library to other developers is by using the JitPack service.
The requirement is that you create a GitHub release and that you have a build file in your repository. It doesn't require that you upload your library.
Does anyone have an idea if it's possible to use a github repo as a dependency, without it being published to maven central.
Let's say I'm developing an android library that has it's own github repo. I'd like to be able to "compile" this library has gradle dependency, in my android studio project, without having to publish to maven central (at least for the moment).
In other words : I want to use a dependency that is not on maven central. It's a straight github repo (an android library that also uses gradle).
I'd like my build.gradle to do something like this :
dependencies {
// Google Play Services (normal dependency)
compile "com.google.android.gms:play-services:5.2.08"
// The library I want to pull from github
compile "path_to_my_github_repo"
}
Thanks!
You can do that with Jitpack with Maven, Gradle and sbt.
However, I would strongly suggest to use binary artifact instead so that you are guaranteed that it is the same upon each build of your application, you control the artifact storage and you are using the official release of a project and not some downstream build. It will also make your builds much faster and more stable.
Publishing to the Central Repository is free, easy and well documented at e.g. http://central.sonatype.org/pages/producers.html and specifically for Gradle at http://central.sonatype.org/pages/gradle.html. You can also find lots of real world examples on the Nexus community site.
If you do not control the project you want to consume, I would suggest to send these pointers to the project and maybe even help them with a pull request ;-)
This should be possible and there is an unofficial gradle plugin called Gradle Git Repo plugin that claims to do what you're looking for. Note however, that I did not play with it myself to verify that it works.
What you need to use is a binary repository. It will contain your dependencies during development.
If you plan to publish your package to jcenter (and maven central) eventually, you can get a free Artifactory account in oss.jfrog.org.
Once doing that, your CI server can deploy your dependency to it and Gradle will resolve it from there.