Reputation: 2095
I want to add an external library GuillotineMenu-Android in my application. I followed the steps given in the most upvoted answer to an existing question How do I add a library project to the Android Studio?
But I am facing error when I try to build project after step 6 i.e. when added dependency in app/build.gradle
as compile project(":guillotinemenu")
. I tried all the stackoverflow links related to this error but its not working out. I have made a folder named libs in my app directory and copied the project folder guillotine menu there. Here is my
build.gradle(Module:app)
file
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.sunshine.bbreaker.appet_i"
minSdkVersion 14
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:recyclerview-v7:+'
compile 'com.github.navasmdc:MaterialDesign:1.+@aar'
compile 'com.android.support:appcompat-v7:22.0.+'
// GuillotineMenu
compile project(":guillotinemenu")
}
settings.gradle(Project Settings) file:
include ':app', ':guillotinemenu'
project(':guillotinemenu').projectDir = new File('libs/guillotinemenu')
build.gradle(Project:guillotinemenu) file:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}} allprojects {
repositories {
jcenter()
}}
settings.gradle(Project:guillotinemenu) file:
include ':app', ':library'
build.gradle(guillotinemenu) file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.yalantis.guillotine.sample"
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile project(':library')
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.1.1'
compile 'com.jakewharton:butterknife:6.1.0'
}
Let me know if you need any more information. Thanks in advance.
Upvotes: 3
Views: 11742
Reputation: 365048
You should have a structure like this:
projectRoot
app
build.gradle
library
build.gradle
build.gradle
settings.gradle
Each module has own build.gradle
file. Also the root/settings.gradle
defines all modules inside a project. Don't use another settings.gradle inside your module.
In settings.gradle :
include ':app', ':library'
In build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
In library/build.gradle
apply plugin: 'com.android.library'
android {
compileSdkVersion ...
buildToolsVersion ...
defaultConfig {
....
}
}
dependencies {
//....
}
In app/build.gradle use your file but change:
dependencies {
//...
// GuillotineMenu
compile project(":library")
}
UPDATE:
After your comment below, I think that in your case the library folder is the root folder of another project. It means that you should refer to the module inside this project.
projectRoot
app
build.gradle
libs
guillotinemenu
build.gradle //top level file of guillotinemenu project
-->> module
build.gradle //build.gradle of the module
So change the settings.gradle of your projectRoot.
include ':app', ':guillotinemenu'
project(':guillotinemenu').projectDir = new File('libs/guillotinemenu/module')
The module (libs/guillotinemenu/module) should have a build.gradle
as the library/build.gradle described above.
Upvotes: 1