简体   繁体   中英

Import repository from github in gradle

I am building a react native android library which depends on:

dependencies {
    compile 'com.google.maps.android:android-maps-utils:0.5'
}

It turned out that android-maps-utils isn't working the way I want so I forked it and I wanted to use my version of this library instead of the official one. I can't find a way to do it though, I searched how to import a library from github inside gradle and I found ajoberstar/gradle-git but there is no clear instruction on how to do it and all examples I found doesn't work for me (for example this one: Gradle: how to clone a git repo in a task? ). Is there any easier way on how to accomplish something like that?

EDIT:

This is my structure (simplified):

root:
| build.gradle
| settings.gradle
| aars
 | map-util.aar
| libs
 | android
  | build.gradle

root build.gradle -> repositories { flatDir { dirs 'aars' } }

settings.gradle ->

include ":react-native-maps-lib"
project(":react-native-maps-lib").projectDir = file("./lib/android")

android/build.grandle -> compile(name: "map-util", ext:"aar")

Reference the AAR you build from building the forked source somewhere on your local filesystem.

repositories {
   flatDir {
       dirs 'libs'
   }
}

then put the artifact in .../libs , and add it normally to your dependencies, of course matching the version to what you just built.

I figured out what is the problem! Let me first make clear though what I wanted to do - I'm building react native project. It uses my forked version of react-native-maps, which uses android-maps-utils. I wanted to fork android-maps-utils and use my forked version.

android-maps-utils produces aar file that I needed to import locally. Following Jeffrey Blattman suggestion I added libs directory inside react-native-maps and put aar file named android-maps-utils.aar there. I also added this inside react-native-maps build.gradle:

allprojects {
  repositories {
    ...
    flatDir {
      dirs "$rootDir/libs"
    }
  }
}

and this inside react-native-maps/android/build.gradle:

dependencies {
  ...
  compile(name: "android-maps-utils", ext:"aar")
}

Now react-native-maps compiles but my react-native project doesn't due to:

A problem occurred evaluating project ':react-native-maps'.

So, I also needed to include this line:

compile(name: "android-maps-utils", ext:"aar")

inside my react native app android directory. Now everything compiles!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM