Android studio 3.0: Unable to resolve dependency for :app#dexOptions/compileClasspath': Could not resolve project :animators - android-studio

I migrate to Android studio 3.0. So, the project become unable to compile a module named ":animator" and it displays me this error:
Error:Unable to resolve dependency for
':app#dexOptions/compileClasspath': Could not resolve project
:animators. <a
href="openFile:/home/mobilepowered/MobilePowered/MyInnovalee/trunk17-10-2017/app/build.gradle">Open
File</a><br><a href="Unable to resolve dependency for
':app#dexOptions/compileClasspath': Could not resolve project
:animators.">Show Details</a>
and show details gives this log :
Unable to resolve dependency for ':app#dexOptions/compileClasspath':
Could not resolve project :animators.
Could not resolve project :animators. Required by:
project :app
Unable to find a matching configuration of project :animators:
- Configuration 'debugApiElements':
- Required com.android.build.api.attributes.BuildTypeAttr 'dexOptions' and found incompatible value 'debug'.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and
found compatible value 'Aar'.
- Found com.android.build.gradle.internal.dependency.VariantAttr 'debug' but
wasn't required.
- Required org.gradle.api.attributes.Usage 'java-api' and found compatible value 'java-api'.
- Configuration 'debugRuntimeElements':
- Required com.android.build.api.attributes.BuildTypeAttr 'dexOptions' and found incompatible value 'debug'.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and
found compatible value 'Aar'.
- Found com.android.build.gradle.internal.dependency.VariantAttr 'debug' but
wasn't required.
- Required org.gradle.api.attributes.Usage 'java-api' and found incompatible value 'java-runtime'.
- Configuration 'releaseApiElements':
- Required com.android.build.api.attributes.BuildTypeAttr 'dexOptions' and found incompatible value 'release'.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and
found compatible value 'Aar'.
- Found com.android.build.gradle.internal.dependency.VariantAttr 'release' but
wasn't required.
- Required org.gradle.api.attributes.Usage 'java-api' and found compatible value 'java-api'.
- Configuration 'releaseRuntimeElements':
- Required com.android.build.api.attributes.BuildTypeAttr 'dexOptions' and found incompatible value 'release'.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and
found compatible value 'Aar'.
- Found com.android.build.gradle.internal.dependency.VariantAttr 'release' but
wasn't required.
- Required org.gradle.api.attributes.Usage 'java-api' and found incompatible value 'java-runtime'.

With Android Studio 2.3(AS) the project works fine and i can able to run the App. After updating the AS to Android Studio 3.0. i too got the error as below for libraries and build types.
Unable to resolve dependency for ':app#dexOptions/compileClasspath': Could not resolve project : library_Name.
Unable to resolve dependency for ':app#release/compileClasspath': Could not resolve project : library_Name.
To Solve the issue, simply.
What ever the
buildTypes{
debug{ ... }
release{ ... }
}
you have in your (app) build.gradle file, You have to include all the buildTypes{ } with same names as like
buildTypes{
debug{ ... }
release{ ... }
}
in to build.gradle files of All libraries/modules included in project.
clean and rebuild the project, the issue will be fixed.
Still issue not fixed, update the gradle-wrapper.properties to
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip

As stated in the official migration guide, this error is encountered when:
Your app includes a build type that a library dependency does not
android {
buildTypes {
release {
...
}
dexOptions {
...
// release & debug is in project animators
matchingFallbacks = ['release', 'debug']
}
debug {
...
}
}
}
Correct place to find the info is now this documentation

Make sure you're in your project
Open the Preferences, by clicking File > Settings (on Mac,
Android Studio > Preferences).
In the left pane, click Build, Execution, Deployment >> Gradle.
Uncheck/disable the Offline work checkbox.
Click Apply or OK.

I spent a lot of time on this issue and none of above solutions work for me. The names and number of build types were also exactly equal in both app and library project.
The only mistake I was making was - In library project's build.gradle, I was using line
apply plugin: 'com.android.application'
While this line should be -
apply plugin: 'com.android.library'
After making this change, this error got resolved.

Modify all
compile project(':library:yourproject')
to
implementation project(path: ':library:yourproject', configuration:'default')
in your app build.gradle. Note the line with configuration.

I tried everything from unchecking offline work to matchingFallbacks. But nothing worked.
Then, in dependencies of app.gradle,
instead of
implementation project(':lib-name')
I used,
implementation project(path:':lib-name', configuration: 'default')
Eg: implementation project(path:':myService', configuration:
'default')
And it worked like a charm. :)
I was adding a dependency module with service and am not making a library as its a part of AOSP project.
Just in case, it helps someone.

Solution:
Dowload the ultimate version of Gradle
http://services.gradle.org/distributions/
gradle-4.x-rc-1-all.zip.sha256 09-Jan-2018 01:15 +0000 64.00B
Unzip the distribution
Go to Android Studio -> File -> Settings -> Gradle -> Use local gradle distribution
Search the file and OK
In the gradle:app write this, implementation(path: ':animators', configuration: 'default')
dependencies {
.
.
.
implementation project(path: ':animators', configuration: 'default')
}

Here is how I solved my problem:
instead of
compile project(':library_name')
compile project(':library_name')
in app gradle I have used
implementation project(':library_name')
implementation project(':library_name')
And in my build types for example
demoTest {
.........
}
I added this line
demoTest {
matchingFallbacks = ['debug', 'release']
}

I had the same issue, and solved it by adding 'mavenCentral()' to build.gradle(Project)
allprojects {
repositories {
...
mavenCentral()
}
}

My problem is below
Unable to resolve dependency for ':app#debug/compileClasspath': Could not download rxjava.jar (io.reactivex.rxjava2:rxjava:2.2.2)
Solved by checking Enable embedded Maven Repository

Even, I have faced the same issue.
I have fixed the issue by referring the above
Solution 2 with the new g‌​radle-4.1 :
I have done the following gradle changes.
It seems downloading resources through maven Amazon helped me to fix the issue, there are issues with appcompat library. Check and ensure that appcompat compatible support libraries downloaded in your system. What I feel, it just simply the resources not downloaded through maven, causing the compile error issue. Ensure the resources are found in your local drive to fix the issue.
Just Played around with
Maven Amazon url
repositories {
maven {
url "https://s3.amazonaws.com/repo.commonsware.com"
}
jcenter()
}
Compatible support libraries downloaded in the drive and referring compatible libraries in gradle.
dependencies {
implementation fileTree(dir: 'libs', include: \['*.jar'\])
implementation 'com.android.support:appcompat-v7:26.0.0-alpha1'
implementation 'com.android.support:support-v4:26.0.0-alpha1'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
}
Complete file
apply plugin: 'com.android.application'
repositories {
maven {
url "https://s3.amazonaws.com/repo.commonsware.com"
}
jcenter()
}
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.cognizant.interviewquestions.cognizantiqpractice2"
minSdkVersion 18
targetSdkVersion 26
versionCode 1
versionName "1.0"
javaCompileOptions {
annotationProcessorOptions {
includeCompileClasspath false
}
}
dexOptions {
javaMaxHeapSize "4g"
preDexLibraries = false
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: \['*.jar'\])
implementation 'com.android.support:appcompat-v7:26.0.0-alpha1'
implementation 'com.android.support:support-v4:26.0.0-alpha1'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
}
---------------------------------------------------------------------------

Change this code in gradle:
compile project(':yourLibrary')
to
implementation project(path: ': yourLibrary', configuration:'default')

I found two type of solutions :
Solution with the old g‌​radle-3.3 :
As first and temporary solution to make the project run with android studio 3.0 , I maintain the old config of my previous of Android Studio 2.3
distributionUrl=https://services.gradle.org/distributions/g‌​radle-3.3-all.zip , compileSdkVersion 25** and **buildToolsVersion "25.0.3" and classpath 'com.android.tools.build:gradle:2.3.3
Solution with the new g‌​radle-4.1 :
To work with the new features of gradle 4.1 and the classpath com.android.tools.build:gradle:3.0.0' , I followed this link https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html . So, Those are my implementations :
In the file gradle-wrapper.properties :
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
In the file build.gradle of the project :
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
//classpath 'me.tatarka:gradle-retrolambda:3.3.1' remove this line
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
In the file build.gradle of the app :
apply plugin: 'com.android.application'
//apply plugin: 'me.tatarka.retrolambda' remove this line
repositories {
maven {
url "https://s3.amazonaws.com/repo.commonsware.com"
}
jcenter()
mavenCentral()
maven { url "https://jitpack.io" }
}
android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
defaultConfig {
applicationId "com.imennmn.myprojectid"
minSdkVersion 21
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
/**
* Enabling multidex support.
*/
multiDexEnabled true
missingDimensionStrategy 'minApi' , 'minApi24'
javaCompileOptions {
annotationProcessorOptions {
includeCompileClasspath true
}
}
dexOptions {
javaMaxHeapSize "4g"
preDexLibraries = false
}
}
buildTypes {
release {
shrinkResources false
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
lintOptions {
checkReleaseBuilds false
abortOnError false
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
configurations.all {
resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
}
/**
* Solve the problem when using multiple free source libs
* NOTICE or LICENSE files cause duplicates
*/
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
exclude 'META-INF/DEPENDENCIES'
//exclude duplicate butterknife and parceler libs
exclude 'META-INF/services/javax.annotation.processing.Processor'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/rxjava.properties'
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation files('libs/motwin-android-sdk-3.2.0-RELEASE-TLS.jar')
implementation files('libs/notifmanager-android-lib-3.1.0-RELEASE.jar')
implementation files('libs/commons-lang-2.4.jar')
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'com.android.support:appcompat-v7:26.0.2'
implementation 'com.android.support:support-v4:26.0.2'
implementation 'com.android.support:design:26.0.2'
implementation 'com.android.support:multidex:1.0.2'
api 'com.jakewharton:butterknife:7.0.1'
implementation 'de.hdodenhof:circleimageview:2.1.0'
implementation 'com.android.support:percent:26.0.2'
implementation 'com.google.android.gms:play-services-maps:11.4.2'
implementation 'com.github.bumptech.glide:glide:3.7.0'
implementation 'com.google.code.gson:gson:2.8.1'
testImplementation 'junit:junit:4.12'
implementation 'com.facebook.rebound:rebound:0.3.8'
implementation 'com.google.android.gms:play-services-gcm:11.4.2'
implementation 'io.reactivex.rxjava2:rxjava:2.1.1'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
implementation project(':animators')
// Retrofit2 & XmlConverter
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
implementation 'com.squareup.retrofit2:converter-gson:2.1.0'
implementation 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
implementation('com.squareup.retrofit2:converter-simplexml:2.3.0') {
exclude group: 'xpp3', module: 'xpp3'
exclude group: 'stax', module: 'stax-api'
exclude group: 'stax', module: 'stax'
}
implementation 'com.squareup.okhttp3:okhttp:3.4.1'
implementation 'com.squareup.okhttp3:logging-interceptor:3.4.1'
//Library to reports crash
implementation('ch.acra:acra:4.5.0') {
exclude group: 'org.json'
}
implementation 'com.github.kenglxn.QRGen:android:2.3.0'
}
In the build.gradle of the library animator I upgrade targetSdkVersion to 26 :
apply plugin: 'com.android.library'
android {
compileSdkVersion 26
buildToolsVersion '26.0.2'
defaultConfig {
minSdkVersion 21
targetSdkVersion 26
versionCode 1
versionName "1.0"
}
}
dependencies {
implementation "com.android.support:support-compat:26.0.2"
implementation "com.android.support:support-core-ui:26.0.2"
implementation "com.android.support:recyclerview-v7:26.0.2"
}

you just need to reset dependencies in app.gradle file
like old one as
androidTestImplementation 'com.android.support.test:runner:0.5'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:2.2.2'
to new one as
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'

Make sure you have disabled "Offline work" in Gradle settings (Setting->Build, Execution, Deployment->Build Tools->Gradle).
I made this mistake. I followed a guide on speeding up gradle builds and had turned on the Offline work option. If that is enabled, Gradle won't be able to download any new dependencies and hence will result in the "Unable to resolve dependency" error.

I met the same problems and has solved.
Due to my situation, I guess your build.gradle file for app project contains snippets below:
android {
...
buildTypes {
debug {...}
release {...}
dexOptions {...}
}
}
but actually, dexOptions is not a build type, you should move dexOptions section out buildTypes, like this:
android {
...
dexOptions {
...
}
buildTypes {
debug {...}
release {...}
}
}
Hope that can help someone.

Adding productFlavors{} to the app build.gradle solved the issue for me. See below:
buildTypes {
release {
...
}
}
productFlavors {
}

This may also happen when you add a reference to the feature module that uses the incorrect plugin type. Simply change com.android.application to com.android.feature or com.android.library
https://i.stack.imgur.com/NDjnG.png

I think it's from gradle-wrapper.properties file :
make distribution url distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
and do not upgarde to : distributionUrl=https\://services.gradle.org/distributions/gradle-4 ....

It seems like it's a bug on Gradle. This solves the problem for me, but it's not a solution. We have to wait for a new version fixing this problems.
On build.gradle in the project set classpath 'com.android.tools.build:gradle:2.3.3' instead classpath 'com.android.tools.build:gradle:3.0.0'.
On gradle-wrapper.properties set https://services.gradle.org/distributions/gradle-3.3-all.zip instead https://services.gradle.org/distributions/gradle-4.1.2-all.zip

In my case, the problem I had was due to a dependency I was trying to import (BottomNavigationViewEx).
This dependency requires to be downloaded from jitpack.io and maven.google.com, and I was putting this config in buildscript section:
buildscript {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" } // this is incorrect
maven { url "https://maven.google.com" } // this is incorrect
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
}
}
which it was incorrect, I need to remove these two maven lines and include them in the right section, 'allprojects':
allprojects {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
maven { url "https://maven.google.com" }
}
}
Hope it helps somebody as same for me.

I tried all the solutions given above and none of them worked for me, I ensured that I have exact build types and product flavours in my library module and app module.

This thread seems to have wondered a bit, however as relating to the original question, not only do you have to have your buildTypes in both build.gradle files, you need to have your productFlavors (if you are using them of course) in both build.gradle files as well.

I tried running Android studio 3.0.1 with internet connection. Android studio started downloading something from a link automatically which was showing in Gradle build notification. I can't say this is a sure answer but try this out.. maybe you can get your issue resolved.

If using Android Studio on Linux:
go to: Home/Android Studio Projects folder/App name folder
open terminal on that page and type:
./gradlew -Dhttp.proxyHost
check if JAVA_HOME is set on valid directory, if not set valid location finally rebuild your project.
NOTE: if that doesn't work remove gradle cache folder or all of that
and download again with Android Studio.

Add the library from File->Right click->New->Module->Import Eclipse ADT project->brows your library->finish
Now add in the app gradle setting following code:
implementation project(':library')
Finally add in the setting gradle following code:
include ':app', ':library'

After updating android studio to 3.3. I faced this problem when I tried to load Firebase JobDispatcher.
Adding this link on gradle.properties solved my problem
distributionUrl=https://services.gradle.org/distributions/gradle-4.1-all.zip

I know none of the above solutions is gonna work as I have remained stuck into this sort of issue a long time, finally resolved this issue after watching the issue very carefully, which is pointing that
Unable to resolve dependency for ':app#dexOptions/compileClasspath':
Could not resolve project : library_Name.
You need to make a sure and double check if the class is residing there. This one thing will prove much helpful to many I guess because focusing on this point took me much closer to the solution. Now if nothing exists in that folder path you need to get the whole stuff like src folder build folder etc everything, copy that and paste it over there sync/rebuild project, if needed try invalidate and restart android studio. Hope so this will get you out of trouble as happend in my case.
Thanks

changing implementation 'com.android.support:appcompat-v7:27+' to implementation 'com.android.support:appcompat-v7:+' worked for me
I am using Intellij 2019 CE, with Kotlin

In my case it was so:
Unable to resolve dependency for ':app#debug/compileClasspath': Failed to transform artifact....
I tried ten solutions, no one worked, thus my solution was to remove C:\Users\djdance.gradle\caches and restart AS

Related

Build error when trying to Run basic activity

I'm on day 1 of learning Android Studio / Kotlin and working my way through the (official?) tutorials.
Having added some basic views to an empty layout and resolved a couple of "coding practice" warnings, when I try to run the app on a USB connected tablet, I get a build failed message.
(I haven't got as far as any Kotlin coding yet.)
I'm completely out of my depth at this stage and can't find a solution that isn't beyond my level of understanding.
The errors are ...
Caused by: java.lang.NoClassDefFoundError: kotlin/reflect/full/KClasses
Caused by: java.lang.ClassNotFoundException: kotlin.reflect.full.KClasses
If there's any other information worth sharing, I'm afraid I don't know what it is at the moment.
ANy suggestions on what I need to do to or investigate to resolve the build fail?
First build.gradle file:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.5.10"
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:4.2.2"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
mavenCentral()
jcenter() // Warning: this repository is going to shut down soon
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Second build.gradle file:
plugins {
id 'com.android.application'
id 'kotlin-android'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.example.test04"
minSdkVersion 19
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:2.0.4'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
Try these steps.
Update your Kotlin version from "1.5.10" to the latest "1.5.31" in your first build.gradle file. Also update the Kotlin plugin: File -> Settings -> Languages and Frameworks -> Kotlin and if there's a new version there will be an Install button to click. Then restart Android Studio and run your project to see if it will work.
If that doesn't work, you can manually add the missing reflection library to your project. I don't see in your dependencies anything that uses reflection, but maybe I'm missing something. So, add this line into the dependencies section of your second build.gradle file:
implementation "org.jetbrains.kotlin:kotlin-reflect"
Then click the "Sync Project with Gradle Files" button near the right end of the toolbar (elephant with blue arrow icon), and try running your project again.
The Android Build Tools you're using is also out of date. I'm not sure it could be related, but you can update that as well in the first build.gradle file. Change the 4.2.2 to 7.0.3 and click the Gradle sync button again. Android Studio might complain that you need to update your Gradle version, so click yes if it offers to update it for you.

Error:Conflict with dependency 'com.google.code.findbugs:jsr305'

I created a new project in Android Studio 2.2 Preview 1 with Android App and Backend module with Google Messaging. This is the app file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.xxx.xxx"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha1'
compile 'com.google.android.gms:play-services-gcm:9.0.0'
testCompile 'junit:junit:4.12'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support:support-annotations:23.4.0'
compile project(path: ':backend', configuration: 'android-endpoints')
}
But it's giving:
Error:Conflict with dependency 'com.google.code.findbugs:jsr305'. Resolved versions for app (1.3.9) and test app (2.0.1) differ. See http://g.co/androidstudio/app-test-app-conflict for details.
I am new to Android and not able to find what is this error. How do I fix it?
In your app's build.gradle add the following:
android {
configurations.all {
resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
}
}
Enforces Gradle to only compile the version number you state for all dependencies, no matter which version number the dependencies have stated.
This is due to espresso. You can add the following to your apps build.grade to mitigate this.
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2') {
exclude group: 'com.google.code.findbugs'
}
METHOD 1:
I deleted the androidTestCompile on espresso-core line which was automatically included in a new project. Then my Android Studio compiles clean.
The androidTestCompile is in "build.gradle (Module:app)":
dependencies {
...
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
...
}
I don't know whether this deletion will have any problem down the road, but it surely works for my current project now.
METHOD 2: Adding an exclude on findbugs works too:
dependencies {
...
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
exclude group: 'com.google.code.findbugs'
})
...
}
METHOD 3: Forcing compiling with a specific version:
(In the following I force it to compile with the higher version.)
dependencies {
...
androidTestCompile 'com.google.code.findbugs:jsr305:3.0.0'
...
}
From Gradle Plugin User Guide:
When instrumentation tests are run, both the main APK and test APK share the same classpath. Gradle build will fail if the main APK and the test APK use the same library (e.g. Guava) but in different versions. If gradle didn't catch that, your app could behave differently during tests and during normal run (including crashing in one of the cases).
To make the build succeed, just make sure both APKs use the same version. If the error is about an indirect dependency (a library you didn't mention in your build.gradle), just add a dependency for the newer version to the configuration
Add this line to your build.gradle dependencies to use newer version for both APKs:
compile('com.google.code.findbugs:jsr305:2.0.1')
For future reference, you can check your Gradle Console and it will provide a helpful link next to the error to help with any gradle build errors.
The reason why this happen is that diff dependency use same lib of diff version.
So, there are 3 steps or (1 step) to solve this problem.
1st
Add
configurations.all {
resolutionStrategy.force 'com.google.code.findbugs:jsr305:2.0.1'
}
to your build.gradle file in android {...}
2nd
Open terminal in android studio
run ./gradlew -q app:dependencies command.
3rd
Click Clean Project from menu bar of android studio in Build list.
It will rebuild the project, and then
remove code in 1st step.
Maybe you need just exec 2nd step. I can't rollback when error occurs.
Have a try.
When I added module: 'jsr305' as an additional exclude statement, it all worked out fine for me.
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
exclude module: 'jsr305'
})
The problem, as stated in your logs, is 2 dependencies trying to use different versions of 3rd dependency.
Add one of the following to the app-gradle file:
androidTestCompile 'com.google.code.findbugs:jsr305:2.0.1'
androidTestCompile 'com.google.code.findbugs:jsr305:1.3.9'
The accepted answer is one way of fixing the issue, because it will just apply some strategy for the problematic dependency (com.google.code.findbugs:jsr305) and it will resolve the problem around the project, using some version of this dependency. Basically it will align the versions of this library inside the whole project.
There is an answer from #Santhosh (and couple of other people) who suggests to exclude the same dependency for espresso, which should work by the same way, but if the project has some other dependencies who depend on the same library (com.google.code.findbugs:jsr305), again we will have the same issue. So in order to use this approach you will need to exclude the same group from all project dependencies, who depend on com.google.code.findbugs:jsr305. I personally found that Espresso Contrib and Espresso Intents also use com.google.code.findbugs:jsr305.
I hope this thoughts will help somebody to realise what exactly is happening here and how things work (not just copy paste some code) :).
Add this this to dependencies to force using latest version of findbugs library:
compile 'com.google.code.findbugs:jsr305:2.0.1'
delete espresso dependencies in gradle file works for me.
delete those lines in app gradle file:
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
i was trying to use airbnb deeplink dispatch and got this error. i had to also exlude the findbugs group from the annotationProcessor.
//airBnb
compile ('com.airbnb:deeplinkdispatch:3.1.1'){
exclude group:'com.google.code.findbugs'
}
annotationProcessor ('com.airbnb:deeplinkdispatch-processor:3.1.1'){
exclude group:'com.google.code.findbugs'
}
Those who are getting same error in Android 3.0.1,can resolve it by simply update the versions of compileSdkVersion and targetSdkVersion to 27 and also Implement com.android.support:appcompat-v7:27.1.1' in dependencies.
In project ':app' you can add the following to your app/build.gradle file :
android {
configurations.all {
resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
}
}
For react-native-firebase, adding this to app/build.gradle dependencies section made it work for me:
implementation('com.squareup.okhttp3:okhttp:3.12.1') { force = true }
implementation('com.squareup.okio:okio:1.15.0') { force = true }
implementation('com.google.code.findbugs:jsr305:3.0.2') { force = true}
REACT NATIVE
If you looking for react native solution, then write this snippet in your affected node_modules gradle build file, e.g. firebase in my case.
android {
configurations.all {
resolutionStrategy.force 'com.google.code.findbugs:jsr305:3.0.0'
}
}

Gradle dependency for MPAndroidChart not working in Android Studio

Trying to install MPAndroidChart, I tried to follow the instructions in the Readme for adding the library as a gradle dependency.
EDIT:
I didn't edit the top-level build.grade file, only the build.gradle file in my app directory. The latter looks like this:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.0"
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "com.gmail.konstantin.schubert.workload"
minSdkVersion 16
targetSdkVersion 23
versionCode 7
versionName "1.1.5"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
maven { url "https://jitpack.io" }
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.google.guava:guava:17.0'
compile 'joda-time:joda-time:2.8.2'
compile 'com.android.support:design:23.0.0'
compile 'com.github.PhilJay:MPAndroidChart:v2.2.3'
}
As you can see, I have added the maven repository and the compile instruction in the dependencies.
However, Android Studio gives me an error:
Error:(32, 13) Failed to resolve: com.github.PhilJay:MPAndroidChart:v2.2.3
EDIT: Here are the instructions as given by JitPack: https://jitpack.io/
I believe I followed them to the letter.
What am I doing wrong? What am I forgetting?
EDIT: The question is really following the wrong lead. Looking at my gradle log, I discovered the following error:
* What went wrong:
A problem occurred configuring project ':app'.
Could not resolve all dependencies for configuration ':app:_debugCompile'.
Could not resolve com.github.PhilJay:MPAndroidChart:v2.2.3.
Required by:
workload:app:unspecified
Could not GET 'https://jitpack.io/com/github/PhilJay/MPAndroidChart/v2.2.3/MPAndroidChart-v2.2.3.pom'.
> peer not authenticated
This is a much better lead to follow and can easily be googled.
please edit your top level gradle file like this:
allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
}
other thing.. take a look at gradle console in the bottom right of android studio, and show me the log.
It is a problem with java/gradle on linux not recognizing the ssl certificate. The easiest solution is to use java 8, see https://www.jitpack.io/docs/FAQ/.
I am on Debian 8.5 Jessie and using openjdk 8 (instead of the stock 7 version) from jessie/backports solved the issue (building gnucash-android) on my system.

Adding dependency to Google Play Services inside Android library

I am developing an Android library that depends on Google Play Services.
The instructions provided by Google on how to setup Google Play Services only specify the steps to follow when adding it to an application project and not a library.
I tried following the same steps for my library and ended up with the following build.gradle file:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0-alpha3'
classpath 'com.google.gms:google-services:2.0.0-alpha3'
}
}
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
jcenter()
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:support-annotations:+'
provided 'com.google.android.gms:play-services-auth:8.4.0'
}
apply plugin: 'com.google.gms.google-services'
The problem with this is that when building the project, I get the following exception:
* What went wrong:
Execution failed for task ':processDebugGoogleServices'.
> File google-services.json is missing from module root folder. The Google Services Plugin cannot function without it.
I understand this because, as stated in the Google Play Services documentation (https://developers.google.com/android/guides/setup) , it depends on a json file for configuration. However, since I am building this as a library, I wanted the google-services.json file to be added in the project that will use my library instead of putting it in the library itself.
So how can I do this? How can I compile my library that depends on classes defined in Google Play Services but not really configure Google Play Services inside the library and let it be done by the application that consumes my library?
Thank you!
It was simpler than I thought.
All I had to do was remove the lines classpath 'com.google.gms:google-services:2.0.0-alpha3' and apply plugin: 'com.google.gms.google-services' from the library's build.gradle file and then add them only to the gradle file in my application project that depends on this custom library.
You can generate and add the google-services.json using instruction on this page
It has a step by step set of instructions for generation of the file.

java.lang.UnsatisfiedLinkError: Couldn't load from loader dalvik.system.PathClassLoader findLibrary returned null

I understand this is asked many times, but I have done thorough research before posting my query.
I have updated Android Studio to latest version as of March 2nd 2015, version 1.1.0. I think still grade does not package .so files on its own.
I have written NewNDK.c in /jni folder. Ran the ndk-build script and .so files were created in /libs. As per suggestion in one of the posts, I modified libs to lib.
Even then, I am getting java.lang.UnsatisfiedLinkError: Couldn't load from loader dalvik.system.PathClassLoader findLibrary returned null error.
The posts does not say about which files to modify. I am new to Android, request your help.
I have narrowed down the problem to: 1. Gradle is not packaging 2. Gradle scripts should be modified.
The build.gradle (Module: app) is as below:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.example.raghu.newndk"
minSdkVersion 17
targetSdkVersion 17
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
}
The build.gradle (project) is as below:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
Please let me know what is missing.
Thank You!
As per suggestion in one of the posts, I modified libs to lib.
It doesn't really make sense to do that. lib is the folder where your .so files will go inside the APK, but this step will be handled directly by the packaging tools if your project is correctly organized.
Inside an Android Studio project, you should put the .so files inside jniLibs/<ABI> where <ABI> is the target architecture of each .so file (armeabi, x86... the same way that they are generated from the NDK inside libs).
So you can either rename your libs folder to jniLibs, or configure your build so your .so files from libs will be directly integrated:
android {
...
sourceSets.main {
jniLibs.srcDir 'src/main/libs'
}
}
Open the project properties > go to Andriod options > select Advance tab > just uncheck "armeabi","armeabi-v7a","arm64-v8a" and save the project.
The Error will be removed.

Resources