I've pulled in a third party custom ListView library into my Android Gradle project. I initially added the project as a gradle library dependency from the jcenter repo. But now I forked the GitHub project and I'm making changes to it.
The original project is no longer maintained, so submitting a pull request is not going to work, I really need my own fork.
What would be a nice way to set this dependency up using Gradle?
I thought of putting the ListView library under the same GitHub repo as my project, but that seems messy, I do want to keep my fork as a separate library.
Another thing I thought about was checking them both out at the same level, and using ".." in my Gradle config to get to the library from my app. This means that if I have a collaborator (and I may soon) they either need to tweak the config to suit them or check things out in the same way I did.
Or I could publish to a repo like mavenCentral or jcenter, but I'm still working on it, so that doesn't sound good either.
Is there a cleaner option that I'm missing?
A simple solution would be to publish your library with JitPack. You just would need to create a GitHub release and have a build file in your repository.
JitPack is a maven repository that pulls in packages from GitHub repositories. It checks out your code and builds it.
Another option is Gradle Source Dependencies.
Basically you declare a dependency on a Git repository:
sourceControl {
gitRepository("https://github.com/gradle/native-samples-cpp-library.git") {
producesModule("org.gradle.cpp-samples:utilities")
}
}
and Gradle will clone and build that project.
Then you can add it as a dependency:
dependencies {
implementation('org.gradle.cpp-samples:utilities') {
version {
branch = 'release'
}
}
}
Related
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.
In android studio how do you git clone a project from github into the same project?
If I got your question correctly, you want to check out some library and add it as a dependency to your (gradle based?) project.
The prefered way would be to checkout it separately and built it as a library project. And if you have maven you can then install it to your local repository.
The other way (and probably what are you trying to achieve) is to add it as a submodule of your local repository.
git submodule add git://repourl.git yourSubmoduleFolder
Then you can add this library as a module dependency to your application module. (You don't have to use git submodules, you can always just get the repo as a zip and extract it into your project)
If you put your library under libraries folder in your project then you can do it like this.
Add this to your settings.gradle
include ':libraries:yourLibraryModuleName'
Add this to your build.gradle
dependencies {
compile project(':libraries:yourLibraryModuleName')
}
You should now be able to build your application with the submodule
Please note that this was just a quick answer, you can find more info on both gradle submodules and gradle module dependencies here on StackOverflow. I guess this should be enough to point you in a right direction.
It does not. However it's a good practice to put it in libraries or libs,...folder
I'm working on an Android app using Android Studio. So far I've been using mavenCentral to depend on all required libraries but now I'd like to add bitcoinj-0.13-SNAPSHOT dependency which is not yet present on mavenCentral.
Is it possible to somehow instruct gradle to get it directly from GitHub repo which is located here: https://github.com/bitcoinj/bitcoinj/tree/master?
For projects that are not yet in mavenCentral you can use JitPack
It will build the github repo for you and provide you with a dependency.
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.
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.).