Two Android Studio Projects, Library & Application – How to link them.

Prepare two projects as follows

1. Library

LibraryProject
+ LibraryModule

2. Application

ApplicationProject
+ ApplicationModule

Set the dependency relations as follows

1. In LibraryProject

in “build.gradle” inside your LibraryModule folder,
make sure to set it as library using plugin and disable proguard

apply plugin: 'com.android.library'
:
:
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
    }
}

2. In ApplicationProject

in “settings.gradle”

include ':ApplicationModule', '..:LibraryProject:yourLibraryModule'

in “build.gradle” inside your ApplicationModule folder

apply plugin: 'com.android.application'
:
:
compile project(':..:LibraryProject:yourLibraryModule')

Reference:

http://stackoverflow.com/questions/22243269/how-to-share-a-single-library-source-across-multiple-projects

http://stackoverflow.com/questions/20117884/android-studio-app-with-library-project-fails-to-build

Advertisements

Published by