Cannot change dependencies of configuration (after enabling instant run)

后端 未结 8 2168
眼角桃花
眼角桃花 2020-12-08 04:05

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

My project contains git submodules and somehow th

8条回答
  •  臣服心动
    2020-12-08 04:25

    Take your dependencies out of your top level build gradle. As it is you are creating a classpath with your top level gradle and then attempting to overwrite it with your other build.gradles

    From:

    buildscript {
    repositories {
        mavenCentral()
        jcenter()
        maven { url 'https://maven.fabric.io/public' }
    }
    
    dependencies {
        classpath 'com.android.tools.build:gradle:2.0.0-alpha6'
        classpath 'com.novoda:bintray-release:0.2.7'
        classpath 'io.fabric.tools:gradle:1.+'
    }}
    

    To: Note I did not add that commented line, Android-Studio does this automatically

    buildscript {
        repositories {
            jcenter()
        }   
        dependencies {
            classpath 'com.android.tools.build:gradle:2.0.0-alpha6'
    
            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
        }
    }
    
    allprojects {
        repositories {
            jcenter()
        }
    }
    

    You should be able to add any needed Maven repositories into your separate app gradles, as they should be specific and the jcenter would cover many of these, as @AndroidMechanic, and @Hi I'm Frogatto have been trying to say in previous answers and comments. Have a look at read here Bintray - JCenter

    The other thing is, I do not understand why you are managing your libraries build gradle within your project as part of your project. You should be referencing your library from your project, with the app build.gradle. You are treating the library gradle as the app gradle.

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

    Make these changes, then see what duplicates and you can manage that from there.

    Also, I recommend manually syncing project with gradle files when changes are made. I would not rely on instant anything, it's important to make changes step wise and take stock of what's occurring, particularly when it won't compile. That's my opinion only and one way to program in android.

    If instant run creates havoc with a particular project, I would disable it for that project. It is enabled by default and I've had no issues with it. The build mess may be the result of unclear gradles in your project to begin with.

    Also:

    In gradle wrapper properties, grade 2.10 is required for classpath 'com.android.tools.build:gradle:2.0.0-alpha6':

    distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
    

    See here for latest updates Android Tools Project Site

    Or you can install a previous version of Android Studio and use the previous working version of your project.

    If you have multiple git files, I suggest you remove the redundant ones, keep only the ones you are using for version control.

提交回复
热议问题