Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
231 views
in Technique[技术] by (71.8m points)

android - 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'

}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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')

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...