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'
}
try to change it to
alpha1 seems obsolete since today (?) and is not compiling any more. Also you'll have to upgrade your gradle to latest 2.10 to work with alpha6
I had the same problem. I resolved it by removing the
classpath
in the submodule Top-levelbuild.gradle
file.I'm not sure if it's the best thing to do, but it worked for me.
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:
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)
also the top level
settings.gradle
has to be changed:and
app/build.gradle
has to change thisEverything compiles
Be careful! Git is not case sensitive by default. Use
to rename the folder.
Two things you can try
With the new gradle tools you need to specify the correct plugin for your module gradle file as well as your library gradle file. If you look closely, your library gradle file is correct:'
Change your module gradle plugin:
This could also be a possible reason as to why your application isn't compiling anymore. Remove this:
See Deprecated List.
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:
To: Note I did not add that commented line, Android-Studio does this automatically
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.
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'
: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.
According to official documentation on instant run.
What happened behind the scenes is that we have updated your project’s build.Gradle file to use the latest version of the Android Gradle plug-in, which is required for Instant Run to work. We also update your Gradle wrapper version to 2.8, and attempt to update the build tools version in all your modules to the latest (23.0.2). This isn't required for Instant Run, but it will use a new faster version of dex, which helps both instant run and a full build be a bit faster.
A Snippet of Application\build.gradle is shown below:
Known Issues Using Instant Run
Using Instant Run with Reflection
Reflection could show unexpected things, for example:
Limitations with Performance Profiling
We suggest temporarily disabling Instant Run while profiling your debug application.
There is a very small performance impact when using Instant Run, and a slightly larger impact when methods are overridden.
Increases in App Methods
Instant Run adds some methods–140 plus three times the number of classes in your app and its local dependencies. If the app was previously just below the dex limit, enabling Instant Run may push your app over the dex limit. Learn how to fix this by Optimizing Multi dex Development Builds.
Other Known Issues
so if you are facing this issue then you can turn off you instant run
go to Settings → Build, Execution, Deployment → Instant Run and uncheck Enable Instant Run… .
Better understanding of instant run go here