117

I am using the volley library to perform network operation in android. So I am trying to add this library in my project which is created in Android Studio and gradle system.

I added the volley library in my project but when I sync with gradle then I am getting error message. I tried all the answers which I see here but nothing worked for me.

Error message : Configuration with name 'default' not found in Android Studio

Volley/build.gradle

apply plugin: 'android-library'

android {

    compileSdkVersion 19
    buildToolsVersion '19.0.1'

    sourceSets {
        defaultConfig {
            minSdkVersion 8
            targetSdkVersion 19
        }

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

        }
    }
}

app/build.gradle

apply plugin: 'android'

android {
    compileSdkVersion 19
    buildToolsVersion '19.0.1'

    defaultConfig {
        minSdkVersion 8
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

dependencies {
    compile 'com.android.support:appcompat-v7:19.+'
    compile project(':library:volley')
}

root/build.gradle

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

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.9.1'
    }
}

allprojects {
    repositories {
        mavenCentral()
    }
}

settings.gradle

include ':app'
include ':library:volley'
Bot
  • 2,285
  • 3
  • 17
  • 20
  • Have you added library folder at correct location like projectname/library?? – Ajay S Mar 30 '14 at 12:00
  • I added library directory in the app directory – Bot Mar 30 '14 at 12:03
  • http://stackoverflow.com/questions/22547364/configuration-with-name-default-not-found-android-studio – k3b Sep 13 '15 at 05:53
  • Possible duplicate of [Android Studio Gradle Configuration with name 'default' not found](http://stackoverflow.com/questions/17188489/android-studio-gradle-configuration-with-name-default-not-found) – tir38 Jun 02 '16 at 19:23
  • 1
    In my case one of my gradle configuration file is missing.It is not properly push. – Zar E Ahmer May 17 '17 at 05:45

11 Answers11

97

Try:

git submodule init
git submodule update
ViliusK
  • 11,345
  • 4
  • 67
  • 71
  • 1
    This definitely works for libraries that are added as submodule, thanks! – Arne Dec 09 '14 at 13:13
  • @Vilius, from which directory do I run this in Terminal? I tried to run it in my project directory, but it says `Not a git repository (or any of the parent directories)`. I have a sample app I tried to import, and it was not set up for gradle, so they wrapped it. I wonder if that's part of the problem. In fact, I don't even have a `settings.gradle` file. Only `build.gradle` and some others. – Azurespot Jun 05 '15 at 03:46
  • 2
    You should run from project's root dir. It should be a project from git repo. And it should be a project with subprojects. Look in `build.gradle` file for something like `compile project(':libs:my-custom:library')` – ViliusK Jun 05 '15 at 22:05
  • 1
    >A submodule allows you to keep another Git repository in a subdirectory of your repository. The other repository has its own history, which does not interfere with the history of the current repository. This can be used to have external dependencies such as third party libraries for example. [source](http://git-scm.com/docs/git-submodule) – ViliusK Sep 04 '15 at 15:12
  • 3
    How does git submodule have anything to do with gradle build error? – teddy Jun 08 '16 at 14:54
68

Add your library folder in your root location of your project and copy all the library files there. For ex YourProject/library then sync it and rest things seems OK to me.

Ajay S
  • 48,003
  • 27
  • 91
  • 111
  • 5
    It may also mean that the build.gradle file or .iml files are missing inside the library directories – W.K.S Feb 26 '15 at 11:33
  • 7
    @aleb to get full error message you just need to run terminal command: `./gradlew assembleDebug`. You can do it from `Android Studio` or an external terminal app. – eleven Apr 15 '15 at 12:40
  • Can you post example and photos ? thanks , because this method not work –  Jan 22 '16 at 07:58
  • 1
    This lead me to realize I was missing my submodules, which is more explicitly expanded on by @ViliusK's answer. – Ionoclast Brigham Apr 04 '16 at 18:43
  • this means you have need to remove library projects name from setting or build.gradle file , which you have deleted recently – Lucky Rana Jun 14 '16 at 09:48
  • I needed to correct the paths of imported projects in the "settings.gradle". The project was imported with `project(':UISDK').projectDir = new File('../UI_Android_SDK/UISDK')`, I needed to fix the path sent to `File()`. – Sufian Aug 30 '17 at 07:46
22

This is probably a rare case, but for me a library that was included in the settings.gradle was not there.

E.g. I had: include ':libraries:Android-RateThisApp:library' in my settings.gradle

but the folder Android-RateThisApp was empty. As soon as I checked out this submodule the gradle sync succeed.

alexgophermix
  • 4,189
  • 5
  • 32
  • 59
  • Yes, you've probably had to `git submodule init` and `git submodule update`. It's common case when checking out a project with submodules. – ViliusK Jun 05 '15 at 22:09
  • not rare at all....this is the case for me with this sorta error..ALOT of the time. – sirvon Jun 23 '15 at 21:34
  • This was the case for me! Updated react-native-maps and it changed the path to the android directory – cbartondock Jul 26 '17 at 17:53
14

If you want to use the same library folder for several projects, you can reference it in gradle to an external location like this:

settings.gradle:

include 'app', ':volley'
project(':volley').projectDir = new File('../libraries/volley')

in your app build.gradle

dependencies {
    ...
    compile project(':volley')
...}
Björn Kechel
  • 7,933
  • 3
  • 54
  • 57
  • This worked for me when I had a whole project as a submodule but I only wanted to use that project's library module (and exclude the sample app). – phreakhead Aug 30 '16 at 03:19
6

I also facing this issue but i follow the following steps:-- 1) I add module(Library) to a particular folder name ThirdPartyLib

To resolve this issue i go settings.gradle than just add follwing:-

project(':').projectDir = new File('ThirdPartyLib/')

:- is module name...

Ali Behzadian Nejad
  • 8,804
  • 8
  • 56
  • 106
sharma_kunal
  • 2,152
  • 1
  • 28
  • 28
3

To diagnose this error quickly drop to a terminal or use the terminal built into Android Studio (accessible on in bottom status bar). Change to the main directory for your PROJECT (where settings.gradle is located).

1.) Check to make sure your settings.gradle includes the subproject. Something like this. This ensures your multi-project build knows about your library sub-project.

include ':apps:App1', ':apps:App2', ':library:Lib1'

Where the text between the colons are sub-directories.

2.) Run the following gradle command just see if Gradle can give you a list of tasks for the library. Use the same qualifier in the settings.gradle definition. This will uncover issues with the Library build script in isolation.

./gradlew :library:Lib1:tasks --info

3.) Make sure the output from the last step listed an "assembleDefault" task. If it didn't make sure the Library is including the Android Library plugin in build.gradle. Like this at the very top.

apply plugin: 'com.android.library'

I know the original poster's question was answered but I believe the answer has evolved over the past year and I think there are multiple reasons for the error. I think this resolution flow should assist those who run into the various issues.

PaulR
  • 3,223
  • 1
  • 21
  • 32
3

Check the settings.gradle file. The modules which are included may be missing or in another directory. For instance, with below line in settings.gradle, gradle searches common-lib module inside your project directory:

include ':common-lib'

If it is missing, you can find and copy this module into your project or reference its path in settings.gradle file:

include ':common-lib'
project(':common-lib').projectDir = new File('<path to your module i.e. C://Libraries/common-lib>') // 
Devrim
  • 15,345
  • 4
  • 66
  • 74
0

For me, (as per some comments I have seen), the issue was that gradle could not find the build.gradle for the imported library. This configuration is straight-forward but the error message is a bit cryptic. For instance I was using the android-map-utils project and had to include it in my settings.gradle by appending these 2 lines like this.

include ':android-map-utils'
project(':android-map-utils').projectDir = new File(settingsDir, '..\\..\\modules\\android-maps-utils-master\\library')

Path of the library is relative to the my project's settings.gradle file. Then, I simply referenced it in my dependencies of my app's build.gradle file like this

...

    dependencies {
    ....
        compile project(':android-map-utils')
    ....

    }

I recommend importing one module at a time, compiling and checking it.

angryITguy
  • 9,332
  • 8
  • 54
  • 82
0

If suppose you spotted this error after removing certain node modules, ideally should not be present the library under build.gradle(Module:app) . It can be removed manually and sync the project again.

deva11
  • 881
  • 10
  • 25
0

I also faced the same problem and the problem was that the libraries were missing in some of the following files.

settings.gradle, app/build.gradle, package.json, MainApplication.java

Suppose the library is react-native-vector-icons then it should be mentioned in following files;

In app/build.gradle file under dependencies section add:

compile project(':react-native-vector-icons')

In settings.gradle file under android folder, add the following:

include ':react-native-vector-icons' project(':react-native-vector-icons').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-vector-icons/android')

In MainApplication.java, add the following:

Import the dependency: import com.oblador.vectoricons.VectorIconsPackage;

and then add: new VectorIconsPackage() in getPackages() method.

gbhati
  • 493
  • 1
  • 8
  • 20
0

Removing few react-native dependencies solved the problem

Deleting these lines the problem is resolved. This line is created by rnpm link but is a bug.

compile project(':react-native-gps')
compile project(':react-native-maps')
HimalayanCoder
  • 9,630
  • 6
  • 59
  • 60