how to import your own github forked library into android studio
Asked Answered
K

4

36

I found a nice open library on GitHub, I imported it into my Android Studio project using Gradle dependencies, but then I realized I need to make little modifications on it.

So I forked the library on my GitHub, done the modifications and asked for a pull request, but I can't wait until they approve and merge my modifications with the original code.

Is there a way to use dependencies to import my forked library (in my Github) into my Android Studio project, rather than the original library?

Krimmer answered 26/2, 2015 at 17:33 Comment(1)
I have the same problem, but all i can think of is Import as Module way , since you have it in your disk. I know this isnt the solution your looking for but I think this is the only way(I think) as of now.Napolitano
K
34

There is actually a really easy way to do this nowadays: jitpack.io

All you need to do is.

  1. add in your root build.gradle at the end of allprojects repositories:

    allprojects { repositories { ... maven { url 'https://jitpack.io' } } }

  2. Add the dependency in your app build.gradle:

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

If you don't have any releases/tags, you can also just do com.github.User:Repo:branchname-SNAPSHOT to build from the latest commit on that branch.

Knowle answered 8/9, 2018 at 17:20 Comment(6)
this is actually the cleanest way to import a lib. thanks for sharing!Burgener
Can jitpack.io also be used to install a forked plugin instead of a library? I would like to install github.com/hierynomus/license-gradle-plugin/pull/184 in my project, but this approach doesn't work or at least it's not clear to me how to apply to a plugin ...Billet
When we move from jCenter to mavenCentral we should use this advice. For example, implementation 'com.github.savvisingh:DateRangePicker:master', implementation 'com.github.RedMadRobot:input-mask-android:6.0.0'.Connotative
Strong +1 for the branchname-SNAPSHOT thingAvicenna
branchname-SNAPSHOT work for me, thank youQuadroon
how about mono repo github.com/androidx/androidx/tree/androidx-main/compose/…Softener
G
16

I know that this is an old post, but for someone with similar problem, if you simply want a way to change a lib and use it in your project, you can download the lib code, change it and import into your project as a module:

  1. Open your project in Android Studio
  2. Download the library (using Git, or a zip archive to unzip)
  3. Go to File > New > Import Module and import the library as a module
  4. Right-click your app in project view and select "Open Module Settings"
  5. Click the "Dependencies" tab and then the '+' button
  6. Select "Module Dependency"
  7. Select the imported module
  8. Open your build.gradle file and check that the module is listed under dependencies.
Gorgias answered 12/1, 2018 at 7:2 Comment(0)
S
4

This is how you should do it:

  • Fork the repo.
  • make changes and commit them
  • edit the push urls to your github forked repository.
  • make a release/tag
  • head over to jitpack.io
  • generate a url to add to your gradle file
Sketchy answered 11/11, 2018 at 12:50 Comment(0)
O
1
  • Fork and library from Github you want improve
  • Open Android Studio > Load Project from Version Control
  • Select the project or enter the url (You must be signed to Github version control)
  • Now you can Commit and Push to Github without any issues.
  • Tag the project with new version, Git > Tag > Create tag
  • Open the app gradle file and add:
apply plugin: 'com.github.dcendents.android-maven'
    group='com.github.yourgithubusername'

and open the root gradle file and add:

   classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
  • Go to Android Studio Terminal And type: ./gradlew install
  • Now Commit and Push to github
  • Go to Jitpack (SignIn with Github on 1st Use)
  • Select the library
  • Copy the Gradle plugin code after selecting the tag:

implementation 'com.github.username:repo:tag'

Offal answered 25/12, 2019 at 11:26 Comment(1)
With version 2.1 I had not have to add apply plugin and the group.Aquacade

© 2022 - 2024 — McMap. All rights reserved.