Is it possible to declare git repository as dependency in android gradle? Is it possible to declare git repository as dependency in android gradle? android android

Is it possible to declare git repository as dependency in android gradle?


For me the best way is:

https://jitpack.io

Step 1. Add the JitPack repository to build.gradle at the end of repositories:

repositories {    // ...    maven { url "https://jitpack.io" }}

Step 2. Add the dependency in the form

dependencies {    implementation 'com.github.User:Repo:Tag'}

It is possible to build the latest commit on the master branch, for example :

dependencies {    implementation 'com.github.jitpack:gradle-simple:master-SNAPSHOT'}


Or you can register a repository as a submodule like this

$ git submodule add my_sub_project_git_url my-sub-project

Then include the project in your settings.gradle file which should look like this

include ':my-app', ':my-sub-project'

Finally, compile the project as a dependency in your application build.gradle file like this

dependencies {  compile project(':my-sub-project')}

Then, when cloning your project, you will only have to add the option --recursive to make git automatically clone the root repository, and all its submodules.

git clone --recursive my_sub_project_git_url

I hope it helps.


There is now a new feature in gradle that lets you add source dependencies from git.

You first need to define the repo in the settings.gradle file and map it to a module identifier:

sourceControl {    gitRepository("https://github.com/gradle/native-samples-cpp-library.git") {        producesModule("org.gradle.cpp-samples:utilities")    }}

You will need to use URI("https://github.com/gradle/native-samples-cpp-library.git") instead of "https://github.com/gradle/native-samples-cpp-library.git" if you're using Kotlin gradle.

And now in your build.gradle you can point to a specific tag (e.g.: 'v1.0'):

dependencies {    ...        implementation 'org.gradle.cpp-samples:utilities:v1.0'}

Or to a specific branch:

dependencies {    ...        implementation('org.gradle.cpp-samples:utilities') {        version {            branch = 'release'        }    }}

Caveats:

  • Gradle 4.10 or higher required
  • Does not support authentication yet

References: