I created a new android project with the following gradle file:
android {
...
dexOptions {
javaMaxHeapSize "4g"
}
...
}
dependencies {
...
compile 'com.linkedin.dexmaker:dexmaker-mockito:2.16.0'
...
}
But when I build my app I get:
Conflict with dependency 'com.android.support:multidex' in project
':app'. Resolved versions for app (1.0.3) and test app (1.0.1) differ.
See http://g.co/androidstudio/app-test-app-conflict for details.
How can I solve this issue?
The error says you are using 2 versions of com.android.support:multidex.Check this
https://stackoverflow.com/a/37357786/3111083 So in your case it should be
android {
configurations.all {
resolutionStrategy.force 'com.android.support:multidex:1.0.3'
}
}
After changing this Clean and rebuild.
Mockito depends only on a specific version, so the dependency conflict should be on your side. Do you have any dependencies that depend on specific version? i.e.in your build.gradle file. If so, you can try using a ResolutionStrategy to force 1.0.3 on them.
Related
I would like to prevent the usage of SNAPSHOT dependencies when building with Gradle a release version of an Android application or library.
How can I force the Gradle build to fail if there are any SNAPSHOT dependencies when building the release?
You could use a ResolutionStrategy.
See here for the API:
https://docs.gradle.org/current/dsl/org.gradle.api.artifacts.ResolutionStrategy.html
The below example was posted in the Gradle forums by Peter_Niederwieser
https://discuss.gradle.org/t/enforce-no-snapshot-dependencies-in-gradle/3851/2
configurations.all {
if (isRelease) {
resolutionStrategy.eachDependency { details ->
if (details.requested.version.endsWith("-SNAPSHOT")) {
throw new GradleException("found snapshot dependency")
}
}
}
}
The code must be placed either in the module build.gradle or in the "allprojects" section of the main build.gradle.
I am attempting to add a maven repository to my Android Studio project.
When I do a Gradle project sync everything is fine. However, whenever I try to build my apk, I get this error:
Execution failed for task ':app:javaPreCompileDebug'.
> Annotation processors must be explicitly declared now. The following dependencies on
the compile classpath are found to contain annotation processor. Please add them to
the annotationProcessor configuration.
- classindex-3.3.jar
Alternatively, set android.defaultConfig.javaCompileOptions.annotationProcessorOptions
.includeCompileClasspath = true to continue with previous behavior. Note that this
option is deprecated and will be removed in the future.
See https://developer.android.com/r/tools/annotation-processor-error-message.html for more details.
The link included (https://developer.android.com/r/tools/annotation-processor-error-message.html) in the error 404s so its of no help.
I have enabled annotation processing in the android studio settings, and added includeCompileClasspath = true to my Annotation Processor options. I have also tried adding classindex, classindex-3.3 and classindex-3.3.jar to Processor FQ Name, but that did not help either.
these are the lines I have added to the default build.gradle under dependecies:
dependencies {
...
compile group: 'com.skadistats', name: 'clarity', version:'2.1.1'
compile group: 'org.atteo.classindex', name: 'classindex', version:'3.3'
}
Originally I just had the "clarity" one added, because that is the one I care about, but I added the "classindex" entry in the hopes that it would fix it. Removing "clarity" and keeping "classindex" gives me the exact same error.
I'm not all too familiar with gradle/maven so any help would be appreciated.
To fix the error, simply change the configuration of those dependencies to use annotationProcessor. If a dependency includes components that also need to be on the compile classpath, declare that dependency a second time and use the compile dependency configuration.
For example:
annotationProcessor 'com.jakewharton:butterknife:7.0.1'
compile 'com.jakewharton:butterknife:7.0.1'
This link describes it in detail: https://developer.android.com/studio/preview/features/new-android-plugin-migration.html#annotationProcessor_config
Relevant snippet included for completeness.
Use the annotation processor dependency configuration
In previous versions of the Android plugin for Gradle, dependencies on
the compile classpath were automatically added to the processor
classpath. That is, you could add an annotation processor to the
compile classpath and it would work as expected. However, this causes
a significant impact to performance by adding a large number of
unnecessary dependencies to the processor.
When using the new plugin, annotation processors must be added to the
processor classpath using the annotationProcessor dependency
configuration, as shown below:
dependencies {
...
annotationProcessor 'com.google.dagger:dagger-compiler:' }
The plugin assumes a dependency is an annotation processor if its JAR
file contains the following file: META-
INF/services/javax.annotation.processing.Processor. If the plugin
detects annotation processors on the compile classpath, your build
fails and you get an error message that lists each annotation
processor on the compile classpath. To fix the error, simply change
the configuration of those dependencies to use annotationProcessor. If
a dependency includes components that also need to be on the compile
classpath, declare that dependency a second time and use the compile
dependency configuration.
I was with a similar error. I follow the instructions on the Google link and it works.
try to add the follow instructions to your app gradle file:
defaultConfig {
applicationId "com.yourdomain.yourapp"
minSdkVersion 17
targetSdkVersion 25
versionCode 1
versionName "1.0"
javaCompileOptions {
annotationProcessorOptions {
includeCompileClasspath = false
}
}
}
Attention to -> includeCompileClasspath false
Add this code to your gradle app
defaultConfig{
javaCompileOptions {
annotationProcessorOptions {
includeCompileClasspath true
}
}
}
I found the solution here https://github.com/JakeWharton/butterknife/issues/908
Simply update your butter knife with Annotation processor
compile 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
i hope it's help you
Add this in defaultConfig
android.defaultConfig.javaCompileOptions.annotationProcessorOptions.includeCompileClasspath = true
In the build.gradle(module app)
apply the plugin:
apply plugin: 'com.jakewharton.butterknife'
Add the following lines in the dependencies section:
annotationProcessor 'com.jakewharton:butterknife-compiler:8.7.0'
implementation 'com.jakewharton:butterknife:8.7.0'
in the build.gradle(Project:projectName), add the classPath in the dependencies like this :
classpath 'com.jakewharton:butterknife-gradle-plugin:8.4.0'
It will fix this issue.
In case if not then add maven:
maven {
url 'https://maven.google.com'
}
If you have dependencies on the compile classpath that include annotation processors you don't need, you can disable the error check by adding the following to your build.gradle file. Keep in mind, the annotation processors you add to the compile classpath are still not added to the processor classpath.
android {
...
defaultConfig {
...
javaCompileOptions {
annotationProcessorOptions {
includeCompileClasspath false
}
}
}
}
If you are experiencing issues migrating to the new dependency resolution strategy, you can restore behavior to that of Android plugin 2.3.0 by setting includeCompileClasspath true. However, restoring behavior to version 2.3.0 is not recommended, and the option to do so will be removed in a future update.
See here https://developer.android.com/r/tools/annotation-processor-error-message.html for more details
If nothing works from above answers add following step as well, specially for new update of Android Studio 3.0.1:
Android Studio 3.0.1:
Add this to your app.gradle file in dependencies:
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
In previous versions of the plugin, dependencies on the compile classpath were automatically added to the processor classpath. That is, you could add an annotation processor to the compile classpath and it would work as expected. However, this causes a significant impact to performance by adding a large number of unnecessary dependencies to the processor.
When using the Android plugin 3.0.0, you must add annotation processors to the processor classpath using the annotationProcessor dependency configuration, as shown below:
dependencies {
...
annotationProcessor 'com.google.dagger:dagger-compiler:<version-number>'
implementation 'com.google.dagger:dagger-compiler:<version-number>'
}
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'
}
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')
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.
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.
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:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0-alpha1'
}
}
Known Issues Using Instant Run
Using Instant Run with Reflection
Reflection could show unexpected things, for example:
Classes are all made public
Many other things are also made public
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
Intermittent issues may occur where the IDE loses connection with the app which will trigger a full rebuild.
Third party Gradle plugin compatibility has not yet been tested, especially those that have not been updated to use the new transforms API.
Data-binding is currently broken in this build (capability to be restored).
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
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.
classpath 'com.android.tools.build:gradle:2.0.0-alpha1'
try to change it to
classpath 'com.android.tools.build:gradle:2.0.0-alpha6'
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
Two things you can try
Change your plugin for "android"
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:'
apply plugin: 'com.android.library'
Change your module gradle plugin:
apply plugin: "android" -> apply plugin: 'com.android.application'
org.apache classes are now depcrated
This could also be a possible reason as to why your application isn't compiling anymore. Remove this:
useLibrary 'org.apache.http.legacy'
See Deprecated List.
The library project's build.gradle seems to cause the configuration error (because of some obscure reason). For me it was enough to also add the library project (which is a git submodule) to settings.gradle instead of only adding the library's project module.
Instead of:
include ':libraries:my_library:sdk'
try including both the library subproject and the subproject's module:
include ':libraries:my_library'
include ':libraries:my_library:sdk'
I installed Android Studio and when I try to import a project from gradle this resolve error shows up:
Unable to load class
'org.codehaus.groovy.runtime.typehandling.ShortTypeHandling'.
I deleted the files in my Users .gradle folder and tried different gradle versions. I don't know how to fix this.
This page might help solve the problem. What they say is:
So we leveraged this version to add a new artifact, named
groovy-backports-compat23. This artifact shouldn’t be necessary for
most of you, but if you face an error like:
Caused by: java.lang.ClassNotFoundException:
org.codehaus.groovy.runtime.typehandling.ShortTypeHandling at
java.net.URLClassLoader$1.run(URLClassLoader.java:372)
in your project, then it means that a class has been compiled with
Groovy 2.3+ but that you are trying to use it with an older version of
Groovy. By adding this jar on classpath, you give a chance to your
program to run. This may be particularily interesting for Gradle users
that want to use a plugin built on Gradle 2+ on older versions of
Gradle and face this error. Adding the following line to their build
files should help:
buildscript {
// ...
dependencies {
classpath 'some plugin build on gradle 2'
classpath 'org.codehaus.groovy:groovy-backports-compat23:2.3.5'
} }
Note that for now, this jar only contains the ShortTypeHandlingClass.
Future versions may include more.
- See more at: http://glaforge.appspot.com/article/groovy-2-3-5-out-with-upward-compatibility#sthash.mv7Y8XQv.dpuf
I can fix this error message using these three methods.
use latest gradle version
use latest android SDK and tools.
use proguard-rules.pro
build.gradle (Project:xxxxx)
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
}
}
allprojects {
repositories {
mavenCentral()
}
}
build.gradle (Module:app)
apply plugin: 'android'
android {
compileSdkVersion 22
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 11
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:+'
compile fileTree(dir: 'libs', include: ['*.jar'])
}
I had the same problem. I ran gradle from command line and that did work.
After that, I found File -> Settings -> Build, Execution, Deployment -> Build Tools -> Gradle. There "Use local gradle distribution" was active. Changed it to "Use default gradle wrapper (recommended)" and it worked.
I have had a same problem. And I have found a solution.
Cause
This problem is caused by android gradle plugin does not match for gradle version.
Solution
Edit build.gradle in project. gradle plugin version must be satisfied requirements for android studio.
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
}
And edit distrubutionUrl in gradle/wrapper/gradle-wrapper.properties. version of gradle must be satisfied requirements for gradle plugin.
distributionUrl=http\://services.gradle.org/distributions/gradle-2.2.1-all.zip
You can find version compatibilities between android studio, android gradle plugin and gradle in this page
https://stackoverflow.com/a/29695756/3675925
I have a problem using the android support library in my Android Studio project using gradle.
If I add the support-library as dependency I will receive and "Error: Gradle: Execution failed for task ':AppName:dexDebug'.
I have done a some researches and found the problem using the support-library with other dependencies which are using the support libraries as well (greendao 1.3.0).
I would like to use a NavDrawer in my app, so I have to use these support library.
If I remove the support library, of course I will receive an inflate error for the "android.support.v4.widget.DrawerLayout".
Does somebody here has an idea?
I used two kind of dependency-imports
compile files('libs/android-support-v13.jar')
and
compile 'com.android.support:support-v4:13.0.0'
cause of a found post in a forum. But that doesn't work, too.
Thanks for your support.
Regards,
Marine
If your other dependencies also depend on the support lib, you need to make sure they are not using local dependencies (ie embedding the jar file). You should always use only
dependencies {
compile 'com.android.support:support-v4:x.y.z'
}
and not a local dependencies. Make sure all your dependencies do the same and Gradle will automatically detect that everything depends on the same library and only add it once to dex.
I tried it but I receive the dex error as well.
Attached you could see my current gradle build-file.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
compile 'com.android.support:support-v4:13.0.0'
compile 'com.google.android.gms:play-services:3.1.36'
compile 'de.greenrobot:greendao:1.3.0'
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 15
targetSdkVersion 18
}
sourceSets {
main {
java.srcDirs = ['src/main/java', 'src-gen/main/java']
}
}
}
The src-gen folder is used for my greendao generated classes.
Please let me know if you need some more information.
Edit:
I resolved it using the latest greendao version. Added: compile
de.greenrobot:greendao:1.3.1
instead of compile
de.greenrobot:greendao:1.3.0
Now it works.
Regards,
Marine_of_Hell