Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding Android Library to Existing Project on Android Studio 0.3.6

I am trying to add a library, https://github.com/edmodo/cropper, to my Android project. I am following the methods described here: How do I add a library project to Android Studio?

but the Android Studio has changed since then and I can no longer "Import a Module". I can only add a new one. Here are the steps I have tried:

Copy the library into a folder named libraries. project structure before adding module

Open Module Settings, and I am presented with this screen module settings

I click the + sign to add a new module and am then presented with this screen first add new module step

I choose to fill in the content root content root select

The rest of the fields autofill to this autofill

The next step... next step

I change the package enter image description here

I hit next and now my project looks like this project structure after new module added

Any idea on the correct way to add an external library in Android Studio 0.3.6+?

like image 780
clocksmith Avatar asked Nov 17 '13 13:11

clocksmith


1 Answers

I don't use the wizard. Usually I edit the gradle files.

Create a structure like this:

- Blunka
    build.gradle
- cropper
    build.gradle
    src
    res
  settings.gradle

In settings.gradle:

include ':Blunka', ':cropper'

In cropper/build.gradle:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.6.+'
    }
}
apply plugin: 'android-library'

android {

   compileSdkVersion 19
   buildToolsVersion "19.0.0"

   defaultConfig {
       minSdkVersion XX
       targetSdkVersion 19

   }    

   sourceSets {
            main {
                manifest.srcFile 'AndroidManifest.xml'
                java.srcDirs = ['src']
                resources.srcDirs = ['src']            
                res.srcDirs = ['res']            
            }
        }
    }

In Blunka/build.gradle add:

dependencies {
    // Libraries
    compile project(':cropper')  
  }
like image 134
Gabriele Mariotti Avatar answered Sep 25 '22 01:09

Gabriele Mariotti