How to use my github repository as dependency in android? - android

The problem is, I previously used a github repository (https://github.com/kenglxn/QRGen) as my dependency:
compile 'com.github.kenglxn.QRGen:android:2.4.0'
It worked fine but now i have forked the repository, made some changes and I'm trying to use my repository as dependency, my repository: https://github.com/prasenjeetpaul/QRGen, I'm trying as:
compile 'com.github.prasenjeetpaul.QRGen:android:2.4.0'
I have sync the project many times but couldn't use my repository code, even after removing the old dependency it is still using the old code but not the new code from my github repository.
Is there a way to remove the old dependency code and use my new repository code??
Please help!

Uploading your files to GitHub will not make your code to be available to be included as a dependency. First, make sure that your project is a library, and follow these steps to upload your library to Bintray's jcenter() repository so that your library can be included as a dependency.

I prefer to use bintray to upload my libs to jcenter repository but the process a little bit complicated so you may use jitpack to publish new dependency immediately
Just add jitpack repo link to root build.gradle and it will work
allprojects {
repositories {
...
maven { url 'https://jitpack.io' } // add this line
}
}

Related

How to add something to gradle for other users?

How to add your own project to the gradle so other users can use it as a dependency? E.g.
dependencies {
compile 'com.myDomain.myProject-v1.0'
}
Create a library project. See this.
Push it to github. (Optional).
Publish it to bintray. See this tutorial.
Assuming that Some Other Folder is a gradle project you could add something like the following to your settings.gradle file:
include ':module1'
project(':module1').projectDir = new File(settingsDir, '../Project B/Module 1')
You have to push it in a maven repo, private or public.
You can check for example the bintray repo (jcenter)
You have to make it available in a repository. A very simple one is JitPack.
Host your lib on Github
Add JitPack in repositories
Add the dependency compile 'com.github.User:Repo:Tag'
Sample:
repositories {
...
maven { url 'https://jitpack.io' }
}
...
dependencies {
compile 'com.github.User:Repo:Tag'
}
Full documentation
Please you need to study about how to make library (module) on android studio, what is jcenter, what is maven center and also study about bintray.com.

How to create a library on Github and use it through gradle dependencies in Android Studio

I want to create the library and have access to it through the Internet.
In Android Studio (via Gradle) dependency may be added in this way:
In build.gradle (Module app):
dependencies {
...
compile 'com.android.support:design:23.1.0'
compile 'com.squareup:otto:1.3.8'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.j256.ormlite:ormlite-core:4.48'
compile 'com.j256.ormlite:ormlite-android:4.48'
...
}
How can I add my own library in this way from github?
To achieve it you have some ways:
publish your library (artifact) in central maven or jcenter.
use a github repo and the jitpack plugin
use a private maven
The point 2. is very simple.
Just push your codein github and modify the gradle script in the project where you want to use it.
Just add this repo tp your build.gradle
repositories {
// ...
maven { url "https://jitpack.io" }
}
and the dependency:
dependencies {
compile 'com.github.User:Repo:Tag'
}
To publish a library in Central Maven or JCenter, it is very long to explain in an answer. Hovewer you can read these posts:
Publish on JCenter
Publish on Central Maven. Another blog for Central Maven
Refer Jitpack is best to import your project or libs from Github to gradle
For more information refer Gabriele Mariotti answer
For a quick solution, as the others have said JitPack is probably the way to go. However, if you want to make your library available to a wider audience you should probably add it to jcenter since this is set up by default in Android Studio now. (Previously it was Maven Central.)
This post gives a detailed walkthrough of how to do it. The following is a summary:
Create the Android library
Test to make sure the library is usable locally
Publish the library on Bintray
Add the library to Jcenter
Then all people will have to do to use your library is add a one liner to their build.gradle dependencies.

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 to make it possible to add my Library on GitHub to Android Gradle Files?

I have a project hosted on GitHub at https://github.com/BoardiesITSolutions/NavigationDrawerManager.
I've seen some projects on GitHub state adding it to their gradle file in Android Studio to the dependencies section but this doesn't seem to be working for me.
I have tried compile: 'com.github.boardiesitsolutions.NavigationDrawerManager:+' but it keeps saying it can't find it, I've also tried replacing the + with the version number but no luck, Android Studio keeps saying it can't find it. I've added the repository MavenCentral as well.
Is there something I need to do from GitHub to make it accessible for Gradle?
I don't see it on maven.
You can use this website to use non-mavenized libraries with Gradle.
Just add maven { url "https://jitpack.io" } to repositories section of build.gradle and use compile 'com.github.BoardiesITSolutions:NavigationDrawerManager:0b14c84445' in dependencies.

How do I host Github repository to Gradle

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

Categories

Resources