Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot change dependencies of configuration (after enabling instant run)

I just enabled instant run in my android studio project. (Followed the instructions here)

My project contains git submodules and somehow these do not compile anymore.

This is the error i get:

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

Any idea what could be wrong there ?

Top level build.gradle:

buildscript {
repositories {
    mavenCentral()
    jcenter()
    maven { url 'https://maven.fabric.io/public' }
}

dependencies {
    classpath 'com.android.tools.build:gradle:2.0.0-alpha1'
    classpath 'com.novoda:bintray-release:0.2.7'
    classpath 'io.fabric.tools:gradle:1.+'
}}

Module build.gradle:

apply plugin: 'android'
apply plugin: 'io.fabric'

android {

    defaultConfig {
       versionCode 4850
       versionName '4850'
       compileSdkVersion 23
       buildToolsVersion '23.0.1'
    }

    packagingOptions {
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/MANIFEST.MF'
        exclude 'META-INF/NOTICE'
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }

    useLibrary 'org.apache.http.legacy'
}

repositories {
    mavenCentral()
    jcenter()
}


dependencies {
    [skip]
    compile project(':libraries:my_library:sdk')
}

Library build.gradle

apply plugin: 'com.android.library'

android {
    compileSdkVersion 23
    buildToolsVersion '23.0.2'

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 23
    }

    lintOptions {
        abortOnError false
    }
}

repositories {
    mavenCentral()
}

dependencies {
    compile fileTree(include: '*.jar', dir: 'libs')
    compile 'com.android.support:support-v4:23.1.0'
    compile 'com.android.support:appcompat-v7:23.1.0'

    testCompile 'junit:junit:4.12'

}
like image 258
mbonnin Avatar asked Nov 23 '15 18:11

mbonnin


2 Answers

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')
like image 136
thaussma Avatar answered Nov 08 '22 15:11

thaussma


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.

like image 35
o.akrout Avatar answered Nov 08 '22 13:11

o.akrout