Could not execute build using Gradle distribution - android-studio

I have the following error: "Could not execute build using Gradle distribution 'https://services.gradle.org/distributions/gradle-4.4-all.zip'."
It only occurs if I have this in my gradle file:
"classpath 'com.android.tools.build:gradle:3.1.2'"
if I switch it back to:
"classpath 'com.android.tools.build:gradle:3.0.1'"
everything works again. This started after I updated gradle and android studio today.
I have tried just about every solution in this question but nothing helped:
Gradle error: could not execute build using gradle distribution
from above:
-I tried deleting the .gradle in the user folder, and restarting android studio (I also restarted my computer after several other attempts)
-gradle build is successful, I tried invalidate caches and restart. (I tried this before deleting the .gradle, would it make a difference doing it again?)
-I tried setting gradle home to several other paths but nothing helped. If I go to my android studio folder/gradle theres a gradle-4.4 folder but not any of the previous versions that work. .gradle has both 4.4 and 4.1 though.
I tried the following gradle home paths:
C:/Program Files/Android/Android Studio/gradle/gradle-4.4
C:/Users/Joseph/.gradle/wrapper/dists/gradle-4.4-all/9br9xq1tocpiv8o6njlyu5op1/gradle-4.4
/usr/local/opt/gradle/libexec/
and path/to/gradle/libexec/
as well as the default wrapper. (which I have it set to now)
It's possible my jdk/jre are set wrong but they have been working up until now.
my project gradle:
buildscript {
repositories {
mavenLocal()
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
jcenter()
google()
}
dependencies {
classpath 'de.richsource.gradle.plugins:gwt-gradle-plugin:0.6'
classpath 'com.android.tools.build:gradle:3.1.2'
classpath 'com.mobidevelop.robovm:robovm-gradle-plugin:2.3.1'
}
}
allprojects {
apply plugin: "eclipse"
apply plugin: "idea"
version = '1.0'
ext {
appName = "IdlePortalDefense"
gdxVersion = '1.9.6'
roboVMVersion = '2.3.1'
box2DLightsVersion = '1.4'
ashleyVersion = '1.7.0'
aiVersion = '1.8.0'
}
repositories {
mavenLocal()
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "https://oss.sonatype.org/content/repositories/releases/" }
google()
}
}
project(":desktop") {
apply plugin: "java"
dependencies {
implementation project(":core")
implementation "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
implementation "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
implementation "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-desktop"
implementation "com.badlogicgames.gdx:gdx-tools:$gdxVersion"
}
}
project(":android") {
apply plugin: "android"
configurations { natives }
dependencies {
implementation project(":core")
implementation "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-arm64-v8a"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86_64"
implementation "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi"
natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi-v7a"
natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-arm64-v8a"
natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-x86"
natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-x86_64"
}
}
project(":ios") {
apply plugin: "java"
apply plugin: "robovm"
dependencies {
implementation project(":core")
implementation "com.mobidevelop.robovm:robovm-rt:$roboVMVersion"
implementation "com.mobidevelop.robovm:robovm-cocoatouch:$roboVMVersion"
implementation "com.badlogicgames.gdx:gdx-backend-robovm:$gdxVersion"
implementation "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-ios"
implementation "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-ios"
}
}
project(":core") {
apply plugin: "java"
dependencies {
implementation "com.badlogicgames.gdx:gdx:$gdxVersion"
implementation "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
}
}
tasks.eclipse.doLast {
delete ".project"
}
my graddle wrapper:
#Wed Apr 25 00:05:44 EDT 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip

Thanks FF7Squirrelman for sharing the problem the solution.
For me I have also fixed the problem by updating gradle distribution from gradle-4.4-all.zip to gradle-4.7-all.zip
The problem I got is I can "Build APK" and run it on my mobile via Android Studio. However, when I generate signed APK, i got the error same as above.
Looking around the web, it sounds like there is bug on gradle-4.4 which causes the issue and I have proceed below to solve the issue as F7Squirrelman suggested:
updating gradle-wrapper.properties:
distributionUrl=https://services.gradle.org/distributions/gradle-4.7-all.zip
Go to File -> Setting -> Build,Execution and Deployment -> Compiler
Uncheck the box: Configure on Demand
It will allow the project built in gradle 4.7 and finally it solves the issue.

Related

Node Build fail after upgrade to Gradle 7.3

We have upgrade gradle from 4.8 to 7.3 after that nodeSetup build gets fail with below error.
Could not find method layout() for arguments [pattern, com.moowork.gradle.node.task.SetupTask$_addRepository_closure5$_closure7#25995910] on object of type org.gradle.api.internal.artifacts.repositories.DefaultIvyArtifactRepository.
Below are code snippet of build.gradle.
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "com.moowork.gradle:gradle-node-plugin:1.3.1"
classpath "io.spring.gradle:dependency-management-plugin:1.0.11.RELEASE"
}
}
apply plugin: "com.moowork.node"
apply plugin: "io.spring.dependency-management"
node {
version = "16.13.12"
npmVersion = "6.12.0"
download = true
nodeModulesDir = file("/XXX")
}
Cause:
There is a breaking change in gradle 6.8 which is you can checkout here:
https://docs.gradle.org/current/userguide/upgrading_version_6.html#configuring_the_layout_of_an_ivy_repository
"The 'layout' method taking a configuration block has been removed and
is replaced by 'patternLayout'
Your plugin "com.moowork.gradle:gradle-node-plugin:1.3.1" is using that method which not upgraded in this library.
Solution:
You can use this gradle-node-plugin instead of "com.moowork.gradle:gradle-node-plugin:1.3.1"
Installation:
https://github.com/node-gradle/gradle-node-plugin/blob/master/docs/installation.md
Installing the node-related plugins can be done in multiple ways. The easiest is to use the plugins-closure in your build.gradle file:
plugins {
id "com.github.node-gradle.node" version "3.1.1"
}
You can also install the plugins by using the traditional Gradle way:
buildscript {
repositories {
gradlePluginPortal()
}
dependencies {
classpath "com.github.node-gradle:gradle-node-plugin:3.1.1"
}
}
apply plugin: 'com.github.node-gradle.node'

Upgrading gradle breaks exoplayer on build, can't find core or dash

Android studio
Gradle version: 4.1
Android plugin version: 3.0.1
implementation 'com.google.android.exoplayer:exoplayer:2.8.4'
Build works fine. Upgrade to these versions:
Gradle version: 4.6
Android plugin version: 3.2.1
implementation 'com.google.android.exoplayer:exoplayer:2.8.4' //unchanged
Build fails with these messages:
Failed to resolve: com.google.android.exoplayer:exoplayer-core:2.8.4
Failed to resolve: com.google.android.exoplayer:exoplayer-dash:2.8.4
I've been stuck on this for a day. I can't find any reason why it should work with the old version, but not the new.
I had to add the following line to allprojects repositories.
allprojects {
repositories {
google()
jcenter()
maven { url 'https://google.bintray.com/exoplayer/' } //new line
}
}
Apparently, Exoplayer is no longer in JCenter. But, the files are still in bintray.
Here you can find explanation and temporary solution for this problem
https://github.com/google/ExoPlayer/issues/5225
you add project build.gradle
repositories {
google()
jcenter()
}
and add
compileOptions {
targetCompatibility JavaVersion.VERSION_1_8
}

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

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

Add maven dependency to Android Studio gradle

Just trying Android Studio & Gradle and I want to add Roboguice to my Project, this is my build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.8.+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
dependencies {
compile 'org.roboguice:roboguice:2.0'
}
gives me
Gradle 'TestApp' project refresh failed:
Build script error, unsupported Gradle DSL method found: 'compile()'!
I tried to move the line
compile 'org.roboguice:roboguice:2.0'
within the dependencies in buildscript but that also failed.
How is this done correctly?
dependencies {
compile 'org.roboguice:roboguice:2.0'
}
Move this part from build.gradle in root (top level build file) to build.gradle in your module

Errors with gradle on Android Studio 0.4.6

Hello StackOverflow,
I have recently updated my Android Studio to the latest version (0.4.6), and I am encountering weird problems with it. When first creating my project, I got this error:
So I obviously went to my SDK Manager and updated my Build Tools to version 19.0.2. However, I still got this error message. I took a look into my build.gradle file and saw that I am missing the android paragraph, So I changed it from this:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.8.+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
To this:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.8.+'
}
}
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion '19.0.2'
//Other Configuration
}
allprojects {
repositories {
mavenCentral()
}
}
But now I am getting this error message when trying to build (and the older Build Tools error):
I'm not sure what to do now.. How can I solve this?
As suggested by Scott keep your Root level build.gradle file like this
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.8.+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
Content of this file will be included in each module level build.gradle file at the type of Gradle sync or compilation.
Check all build.gradle files inside your modules. They all should look similar to this
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion '19.0.2'
//Other Configuration
}
dependencies{
// Your all module dependencies here
}
Undo the changes you made to the top-level build file, and make those changes to the build files in your individual modules. In particular, putting an apply plugin: 'android' statement or android block in your top-level build file in that manner won't work. The error message you're seeing is happening because the build system is trying to build an Android app out of the root directory of your project, but none of the source files for such a project are there.

Resources