sanic
sanic

Reputation: 2085

Include Git Library with Project on Android Studio using aar?

I'm a total beginner with Android Studio and haven't been able to figure out how to get this library to work with my app. Can someone walk me through how to install and use in my project. I tried adding the project as a module but that didn't work for me like other libraries/modules.

Here is the project I'm trying to add:

https://github.com/rengwuxian/MaterialEditText

Thank you.

EDIT:

build.gradle

buildscript {
repositories {
    mavenCentral()
}
dependencies {
    classpath 'com.android.tools.build:gradle:1.0.0'
}
}
apply plugin: 'com.android.application'

dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.android.support:appcompat-v7:21.0.3'
compile project(':AndroidBootstrap')
compile project(':android-support-v4-preferencefragment-master')
compile project(':google-play-services_lib_lollipop')
compile 'com.rengwuxian.materialedittext:library:1.7.1'
}

android {
compileSdkVersion 21
buildToolsVersion "21.1.2"

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



    // Move the tests to tests/java, tests/res, etc...
    instrumentTest.setRoot('tests')

    // Move the build types to build-types/<type>
    // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
    // This moves them out of them default location under src/<type>/... which would
    // conflict with src/ being used by the main source set.
    // Adding new build types or product flavors should be accompanied
    // by a similar customization.
    debug.setRoot('build-types/debug')
    release.setRoot('build-types/release')
}
}

Upvotes: 3

Views: 2018

Answers (1)

bjiang
bjiang

Reputation: 6078

I tried and I just add a line compile 'com.rengwuxian.materialedittext:library:1.7.1' to in the app folder build.gradle, such that

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.2'
    compile 'com.rengwuxian.materialedittext:library:1.7.1'
}

Sync the gradle. Then, just use com.rengwuxian.materialedittext.MaterialEditText instead of EditText in your layout xml, such that:

<com.rengwuxian.materialedittext.MaterialEditText
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:hint="Basic"/>

MaterialEditText has directly inherited EditText, so you don't have to change your java code.

EDIT

build.gradle in app

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.1"

    defaultConfig {
        applicationId "com.example.myapplication"
        minSdkVersion 15
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.2'
    compile 'com.rengwuxian.materialedittext:library:1.7.1'
}

build.gradle in root

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.0.0-rc1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

settings.gradle

include ':app'

Upvotes: 1

Related Questions