chargerstriker
chargerstriker

Reputation: 496

Editing external libraries in Android Studio

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?

Upvotes: 23

Views: 26895

Answers (3)

ganjaam
ganjaam

Reputation: 1286

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

Upvotes: 0

Samir Alakbarov
Samir Alakbarov

Reputation: 1145

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.

Upvotes: 10

Shailendra Madda
Shailendra Madda

Reputation: 21531

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

Upvotes: 30

Related Questions