23

I am using an image carousel library that I snagged off of github, but there are a few things I would like to change in the code. I have imported it using the compile 'com.theartofdev.edmodo:android-image-cropper:2.6.+' command. Is that code available for me to edit somehow? Or is it downloaded from github every time I run my code?

3 Answers 3

30

For this you need to import it as lib and modify as you like:

To import the library to Android Studio, there are two methods that can work.

Method 1:

  1. Open your project in Android Studio
  2. Download the library (using Git, or a zip archive to unzip)
  3. Create a folder "subProject" in your project
  4. Copy and paste the FreemiumLibrary folder to your subProject folder
  5. On the root of your project directory create/modify the settings.gradle file. It should contain something like the following:
include 'MyApp', ':subProject:FreemiumLibrary'
  1. gradle clean & build/close the project and reopen/re-import it.
  2. Edit your project's build.gradle to add this in the "dependencies" section:
dependencies {
//...
    compile project(':subProject:FreemiumLibrary')
}
  1. Edit your App Activities to extend AdsFragmentActivity instead of Activity.
  2. Edit the library if you want to use it with ActionBarCompat

Method 2:

  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 "Freemium Library" (not Freemium Library Project)
  8. Modify your App Activities to extend AdsFragmentActivity instead of Activity.
  9. Modify the library if you want to use it with ActionBarCompat
7
  • method 1 worked for me, thanks a lot! Only issue I ran into was that the lib I was adding as module had an external .gradle file imported which needed to be removed in order to build successfully
    – batman
    Commented Aug 22, 2018 at 6:51
  • Glad it helped you. Happy coding :) Commented Aug 22, 2018 at 11:52
  • Is there a easy way to update the library afterwards using git? Commented Jan 13, 2020 at 20:29
  • 1
    @MerthanE No idea, please explore and post it as a new answer here if it is easier than this. It may help someone. Commented Jan 14, 2020 at 11:09
  • this feature has a bug in android studio arctic fox. For solving this issue you can use this answer stackoverflow.com/a/68868869/9474700.
    – behrad
    Commented Dec 11, 2021 at 14:58
10

I solved this way. Fork library project. Then clone it (In Android Studio, File -> New -> Project from Version Control -> put the link of your repository that you forked and open it). Edit it and commit it to your master branch. Then push it to your master branch. And finally find snapshot version of that library. For example if you use JitPack. Go to jitpack.io website and search for your repository (forked version with your username). And there go to commits section and get latest version that you committed. And use that library dependency in your project instead of original repo.

2
  • 1
    I am happy that it worked for you. I searched a lot to find this way. And actually I found this solution by myself. You must change version code and name in gradle.build file too. Commented Nov 25, 2020 at 18:41
  • 1
    Oh, you saved me hours of nightmares. Thanks! Commented Dec 1, 2020 at 4:11
0

My approach was similar to @Shailendra Madda's with some minor differences.

At first I downloaded/cloned the project in my PC. Let's say the library's name is 'VideoPlayer'.

I ensured that the module level gradle of VideoPlayer did not contain applicationId. I also ensured that it contained

  plugins {
      id 'com.android.library'
  }

instead of

  plugins {
    id 'com.android.application'
  }

Now the library is ready for import.

In order to import this library into my project, I went to File -> New -> Import Module.

From there, I selected the directory of VideoPlayer. The VideoPlayer project that I downloaded had four modules. In cases like this you can simply select the modules you want to import. I selected the module named core and clicked finish. [Note: instead of selecting VideoPlayer folder from the explorer, you can also select the 'core' folder].

After importing the module, go to File -> Project Structure (or Ctrl+Alt+Shift+S) and select dependencies. From modules section, select app (here, app is the name of my project's module) and then select the + icon in 'declared dependencies' section and select Module Dependency. From the new window, select the module you wish to add as dependency (in my case, it is 'core').

After you click Apply and/or OK, android studio will modify relevant gradle files, so you don't have to worrry about it. And the project will be added as a dependency in your project.

Check this page to learn more: https://developer.android.com/studio/projects/android-library

Not the answer you're looking for? Browse other questions tagged or ask your own question.