Publish library for use it with Gradle - android

When you want to use a library from GitHub that the owner tells you to copy something like this to your dependencies and then you have access to it:
compile 'com.1gravity:android-rteditor:1.6.2'
How can I make this kind of URL for my library?

You have to publish to some public library repositories like jcenter, Maven Central or jitpack.

Related

Android Studio 3rd Party Library Integration

I've got to integrate a 3rd party library in to My Android Studio project and that works great without any issue.
It asks to add following configuration to the project's build.gradle (sample configuration as follows)
allprojects {
repositories {
jcenter()
maven {
url "http://link/location"
}
}
}
And then to add dependencies to the app.gradle as follows
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.android.support:support-v4:24.1.1'
compile 'com.android.support:cardview-v7:24.1.1'
compile 'xxx.xx:xxx:1.11.0:#aar'
}
But my requirement here is to create a library module (with in the project) that wraps this 3rd party library integration with in that.
Idea is to distrubute my library that contains few public methods (that use this 3rd party library methods in that) to others to integrate with in their apps.
As I mentioned earlier to use this 3rd party library I need to use their own Maven Repository and asks to place setting in Projects build.gradle. But as I want to warp all within My Library Module I just tested adding repository bit in to Library Module's build.gradle. But this provides compile errors.
repositories {
jcenter()
maven {
url "http://link/location"
}
}
My Question is can I achieve what I am trying to do? If so what I am missing here. Thanks
EDITS
Briefly what I am trying to do.
This 3rd party library is not available in standard jcenter or mavenCentral repositories. Instead it resides on their own Maven Repository Server. That's why when need to integrate it asks to specify server location in root level (project) build.gradle as follows. Then I can add dependencies...
allprojects {
repositories {
jcenter()
maven {
url "http://link/location"
}
}
}
But as I want to wrap up this integration within Library Module tried to add above repository location in to gradle.build with in My Library Module.
So I can Access those classes but Main Application that compile MY Library project saying can't resolve libraries in 3rd party Library location. Actually Main Application should NOT want to know as long as My Library Module knows it...
Actually Main Application should NOT want to know as long as My Library Module knows it
If the third-party module is open source, fork it, put your wrapper code in the fork, and ship the fork by your own means.
If the third-party module is not open source, discuss with the vendor what your options are for distributing this code by some other means (e.g., your own internal repository, alongside your own library).

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 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 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