How do I host Github repository to Gradle - android

I have a repository on Github, I would like to use my repository in Android Studio using: dependencies {compile 'com.google.code.gson: Gson: 2+'} for gradle. Does someone know how to do this?

You could use JitPack.io to expose your repository as a Maven dependency. Then including it in Android Studio is easy with gradle:
compile 'com.github.YourUsername:RepoName:ReleaseVersion'
There are more instructions on the website.

I don't know if I really got the question...I understood that you want to compile some jar files that are not local to your project and are hosted in your repository. If it is the matter, I guess you should use a custom maven repository, not a Github one. If this is the problem I can give you more details on how to create a custom maven repo.

It's like #dometheshooter said.
See:
How to publish aar file to Apache Archiva with Gradle
Guide to publish an aar to maven using gradle
How to deploy JAR to Maven remote repository
Guide to uploading artifacts to the Central Repository
Guide to deploying 3rd party JARs to remote repository

Related

Using personal library hosted on github as gradle dependency

I have an android library that is hosted on github and need to add it as a dependency to another project without manually cloning the repository and adding it as a module dependency. How do I go about creating my own gradle dependency with link from github? Thanks!
If you've pushed your code to GitHub then sharing your library is easy with JitPack.
Your users will just need to add the repository to their build.gradle:
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
and then your GitHub repository as dependency:
dependencies {
compile 'com.github.YourUsername:Repo:Release'
}
JitPack acts as a maven repository and can be used like Maven Central. The nice thing is that you don't have to upload your library. Behind the scenes JitPack will check out the code from GitHub and compile it. As you publish a new release on GitHub it becomes available for others to use.
There is also a guide on how to prepare an Android project.
You have to release your library to a repository which can be used by Gradle. When you want the library to be publicly available you can publish it to Maven Central. See http://central.sonatype.org/pages/gradle.html#releasing-the-deployment-to-the-central-repository for details about how to publish your library from gradle to Maven Central.
Once published in Maven Central use the normal gradle dependency declaration.
Github is not a maven repository.
if it's "free for all" license, you can clone project and post it for example in jCenter, then add it as gradle dependency.

How does publishing android libraries that can be imported easily by other people work?

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.

How to add a github library to gradle

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.

Android studio - Gradle - GitHub Repo

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.

add library from Git to Android Studio

I know this must be a pretty basic question, but I'm new to Android Studio and gradle, and I can't find any up-to-date info on this.
I'm trying to add this library to my project: android-segmented-control.
It doesn't look like I can add it to my build.gradle file (correct?). I'd like to do it that way, of course, and not download the project if possible.
If I do need to download the project, how do I link it up with my existing project? Again, I haven't been able to find anything that is current that describes this process for Android Studio 0.5.3
The library you mentioned does not seems to be pushed on maven central or any other maven repository. As this library contains resources files, you cannot add it as a jar.
The only way to use it is clone the git repository and add it as a module to your android app project.
Meanwhile, you can ask the author to make it available on a Maven repository like OSS sonatype
Thanks #Thomas Bouron for the hint !
I have pushed my library to maven center, so you just need to add the following dependency to your build.gradle.
dependencies {
compile 'info.hoang8f:android-segmented:1.0.0'
}
(A little late for #workInAFishBowl but it may be helpful for others.).

Categories

Resources