how to import your own github forked library into android studio

跟風遠走 提交于 2019-12-20 12:36:55

问题


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?


回答1:


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.



回答2:


I think the previous answers are both outdated. 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.




回答3:


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



回答4:


You need to add your own git respository as remote. You can't however do this within Android Studio, according to this thread. Use the command line instead:

git remote add remoteName remoteUrl
git fetch remoteName

Then you can go to Android Studio, VCS > Git > Pull and select your added remote repository.



来源:https://stackoverflow.com/questions/28749014/how-to-import-your-own-github-forked-library-into-android-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!