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.
Related
I have downloaded a lot of libraries from Github. When I want to add it in android studio, there's no .jar file in every library I have. Why is it that it has no jar file ? How do I add those libraries in android studio?
Whenever possible, you should find the correct line to add to the dependencies block in your build.gradle file. For example, look at the README for the Boom Menu library which you mentioned in your comment. Under the heading Gradle & Maven, you see
compile 'com.nightonke:boommenu:2.1.0'
Add this line to the dependencies block in build.gradle, sync Android Studio, and then use the library as you wish.
libraries from GitHub... Example is the Boom Menu library
This one? ... Well, you're just not reading the documentation
Otherwise, if there isn't a BinTray dependency.
This is exactly what JitPack is for
To get a Git project into your build:
Step 1. Add the JitPack repository to your build file
Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency
dependencies {
compile 'com.github.User:Repo:Tag'
}
Regarding your questions
Why is it that it has no jar file ?
Because GitHub isn't meant for storing (potentially large) binaries of compiled code, and many Android libraries prefer BinTray over GitHub releases.
How do I add those libraries in android studio?
You could clone them directly into your project
app/
build.gradle
library/
build.gradle
settings.gradle
build.gradle
In settings.gradle
include :app, :library
In app/build.gradle
dependencies {
compile project(":library")
}
All day I'm trying to add my Android library to Github with JitPack.
I did everything described on: https://jitpack.io/docs/ANDROID/, with no success.
The problem is, when i try to build project, Android Studio give me message:
Error:(47, 13) Failed to resolve: com.github.linean:btleuart:v1.0.0
Here is my repo: https://github.com/linean/btleuart
If anyone have any idea what should I check please tell me.
Sorry for my english :)
The release "v1.0.0" does not exist. The release name is "1.0.0". So, in your app or library gradle file, replace
compile 'com.github.linean:btleuart:v1.0.0'
by
compile 'com.github.linean:btleuart:1.0.0'
In addition, make sure that you have included JitPack repo in your root gradle file.
allprojects {
repositories {
jcenter()
maven {
url "https://jitpack.io"
}
}
}
You can read some examples describing how to use JitPack to include libraries in your projects
I found solution !
Clean project
use /.gradlew build
use /.gradlew install
Compille project
Git - and now its working
Thanks cricket_007 for info about JitPack build log :)
main build.gradle file should have this:
allprojects {
repositories {
jcenter()
maven {
url "https://jitpack.io"
}
}
}
you can check a working example here: https://github.com/matoelorriaga/pokemon-mvp/blob/master/build.gradle
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.
I have a library such as LibraryOne and it's package name is com.gorkem.libraryone and i pushed library to github. When i use this library on other project, i want to access this library with dependecies like that: compile 'com.gorkem.libraryone' how they do that ? i can give many example such as compile 'com.google.code.gson:gson:2.3.1'. Are there any tutorials for this issiue ?
You just need to publish your library in JCenter or Maven.
Just follow this tutorial: https://www.virag.si/2015/01/publishing-gradle-android-library-to-jcenter/
https://jitpack.io must be what you want,use this and you can use
repositories {
maven {
url "https://jitpack.io"
}
}
dependencies {
compile 'com.gorkem.libraryone:v1.0.0'
}
You can refer to this project as example
I want to compile the following library in my project in build.gradle:
https://github.com/theDazzler/Android-Bootstrap
It is forked from https://github.com/Bearded-Hen/Android-Bootstrap, but no documentation in the repository explains how to include in in project.
I tried something like this:
compile 'com.theDazzler:androidbootstrap:+'
but gradle failed and shows error that library not found.
Edit: Can anyone fork it and/or publish it?
This fork isn't published in the maven central repo.
Then you can't use an import like compile com.theDazzler:androidbootstrap:+
You have to:
- clone this library locally as a module in your project
Clone the
https://github.com/theDazzler/Android-Bootstrap/tree/master/AndroidBootstrap folder in your root/module1 folder.
root:
module1
build.gradle
app
build.gradle
settings.gradle
Change your settings.gradle file in
include ':module1'
include ':app'
In your app/build.gradle file you have to add:
dependencies {
// Module Library
compile project(':module1')
}
Finally in your module1/build.gradle you have to check the level used for gradle plugin.
EDIT 31/10/2015:
You can use another way to add a dependency with a github project,using the github repo and the jitpack plugin
In this case you have to add this repo tp your build.gradle
repositories {
// ...
maven { url "https://jitpack.io" }
}
and the dependency:
dependencies {
compile 'com.github.User:Repo:Tag'
}
It can be simply done by using Jitpack.
Step 1. Add the JitPack repository to your build file
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency
dependencies {
compile 'com.github.User:Repo:Tag'
}
for eg: compile 'com.github.sachinvarma:JcPlayer:0.0.1'
The issue is: has that theDazzler/Android-Bootstrap been published anywhere? In any gradle/maven repo?
The usual build.gradle file has a section repositories which should reference that maven repo.
So it is possible any project using theDazzler/Android-Bootstrap should reference the repo where it is published, And with a project like gradle-git-repo-plugin, you could publish that fork on its own release section to publish it.
That task gets wrapped into a publishToGithub task that handles committing and pushing the change. Then you can run
gradle -Porg=layerhq -Prepo=gradle-releases publishToGithub
You can also run
gradle -Porg=layerhq -Prepo=gradle-releases publish
to stage a release in the local github repo and commit it manually.
Hi i had the same issue but with a different project :)
So first you should have the library code on your dev machine.
Next steps are: add a new file called settings.gradle to the root of your project if its not already there.
inside add this:
include 'AndroidBootStrap'
project('AndroidBootStrap').path = "path/to/AndroidBootstrap/AndroidBootStrapLibrary"
also add include for your root project if its not there.
Inside your build.gradle file add
compile project(':AndroidBootStrap')
to add the dependency.
How your folder Structure should look:
root
YourProject
settings.gradle
YourProjectModule
build.gradle
AndroidBootStrap
AndroidBootStrapLibrary
build.gradle
In the end the files look like this:
settings.gradle:
include 'AndroidBootStrap'
project('AndroidBootStrap').path = "../AndroidBootstrap/AndroidBootStrapLibrary"
include 'YourProjectModule'
build.gradle (YourModule):
...
dependencies {
...
compile project(':AndroidBootStrap')
}
Maybe its necessary to modify some point but i hope you get the idea!
Cheers
Neri