Cannot change dependencies of configuration (after enabling instant run)

I had the same problem. I compared it to the (working) sample project by @RaGe and found the minor difference.

The sub project folder has to start with a Upper case letter.

Here is the change I did on @RaGes sample to break it and get it working again.

Broken structure:

android-multi-project-sample
    + .gralde
    + .idea
    + app
    + build
    + gradle
    + myApplication2
    - .gitignore
    - android-multi-project-sample.iml
    - build.gradle
    - gradle.properties
    - gradlew
    - gradlew.bat
    - local.properties
    - settings.gradle

results in the following error:

Error:(8, 0) Cannot change dependencies of configuration ':myApplication2:classpath' after it has been resolved.

Working structure (with upper case sub project)

android-multi-project-sample
    + .gralde
    + .idea
    + app
    + build
    + gradle
    + MyApplication2     // upper case!!!!!!
    - .gitignore
    - android-multi-project-sample.iml
    - build.gradle
    - gradle.properties
    - gradlew
    - gradlew.bat
    - local.properties
    - settings.gradle

also the top level settings.gradle has to be changed:

+ include ':app', ':MyApplication2:mylibrary'
- include ':app', ':myApplication2:mylibrary'

and app/build.gradle has to change this

+ compile project(':MyApplication2:mylibrary')
- compile project(':myApplication2:mylibrary')

Everything compiles

Be careful! Git is not case sensitive by default. Use

git mv -f myApplication2 temp
git mv -f temp MyApplication2

to rename the folder.


I had the same problem. I resolved it by removing the classpath in the submodule Top-level build.gradle file.

dependencies { 
     // classpath 'com.android.tools.build:gradle:1.0.0'
}

I'm not sure if it's the best thing to do, but it worked for me.


gradle reads and executes all build.gradle files in all folders of the included modules. As the error shows, it also tries to execute the root build script of :libraries:my_library.

You have to change your settings.gradle and include the library project by setting its 'projectDir':

include ':app'

// Give your library project any module name, i.e. ':sdk'
include ':sdk'
// Then set the project path of the library module
project(':sdk').projectDir = new File('libraries/my_library/sdk')

With this settings.gradle you can reference the library project as gradle dependency with:

compile project(':sdk')