I have a Github repo and pushed tags on it.
This is my gradle file of my main project.
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.0"
defaultConfig {
applicationId "dropbox.ric.es.myapplication"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
//mavenCentral()
//jcenter()
maven { url "https://jitpack.io" }
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.github.rchampa:DropboxHttpConector:1.0.1'
}
But when I sync gradle I have the following error Failed to resolve com.github.rchampa:DropboxHttpConector:1.0.1
Another attempt:
allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.github.rchampa:DropboxHttpConector:1.0.1'
}
Still failing.
For anyone else that made the simple mistake I made:
Ensure you add the maven { url "https://jitpack.io" } under allprojects instead of buildscript.
Project build.gradle file:
buildscript {
repositories {
jcenter()
// DO NOT ADD IT HERE!!!
}
...
}
allprojects {
repositories {
mavenLocal()
jcenter()
// ADD IT HERE
maven { url "https://jitpack.io" }
}
}
Thanks to Alexander Pacha for pointing that out in a comment above.
Newer versions of Android Studio don't use allprojects anymore.
Open the file settings.gradle and add the repository as shown below:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' } // <- here we go
jcenter()
}
}
Also remove the code below from the file project's build.gradle, if it is still there:
allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
}}
After a few attempts and thanks to jitpack support now I can import my library hosted in Github as a Android Gradle dependency.
I will provide a a few very useful links:
How setup your java library
https://jitpack.io/docs/BUILDING/#gradle-projects
How check logs of your dependency in jitpack
https://jitpack.io/com/github/USER/REPO/TAG/build.log
In my case
https://jitpack.io/com/github/rchampa/DropboxHttpConector/1.0.3/build.log
I have several dependencies from Jitpack and I encountered this issue after migrating to Gradle 2.
The solution in my case was to change the version in distributionUrl in gradle-wrapper.properties from 2.10 (which was automatically set by Studio when I accepted updating the wrapper version) to the latest one.
Hallelujah I got the problem!
So I realised that PROBLEM is relied on my NETWORK! I can't acces https://jitpack.io/ from my IP that's why nothing was working. Just shared internet from a GSM module(to get a different IP) and problem is gone using #SteveMellross solution
Maybe it can be 0.001% that you have the same problem but if nothing works just try to access https://jitpack.io/ ;)
I hope there is just a firewall or internal router error and my IP is not banned by their service.
Verify that maven { url "https://jitpack.io" } is in allprojects section in build.gradle (Project)
For me I did this
1.Forked the original unmaintained repo
2.Did some changes,created the commit
3.Copied commit hash from commit details page url
eg https://github.com/omkar-tenkale/NavigationTabStrip/commit/9d097af9fe2167fc0dfc71d2e63d6194b2cebfb0
4.Created implementation string from repo url
implementation 'com.github.User:Repo:Version'
Group: com.github.Username
Artifact: Repository Name
Version: Release tag, commit hash or master-SNAPSHOT
More at https://github.com/jitpack/jitpack.io
I used commit hash as Version
implementation
'com.github.omkar-tenkale:NavigationTabStrip:9d097af9fe2167fc0dfc71d2e63d6194b2cebfb0'
5.Now added that in android app module's build gradle
6.But got error Unable to resolve dependency for ':app#debug/compileClasspath': Could not resolve...etc
7.Created a link in below format
https://jitpack.io/com/github/USER/REPO/TAG/build.log
In my case
https://jitpack.io/com/github/omkar-tenkale/NavigationTabStrip/9d097af9fe2167fc0dfc71d2e63d6194b2cebfb0/
8.Opened this link in browser
9.Saw something like this
NavigationTabStrip-9d097af9fe2167fc0dfc71d2e63d6194b2cebfb0-javadoc.jar
NavigationTabStrip-9d097af9fe2167fc0dfc71d2e63d6194b2cebfb0-sources.jar
NavigationTabStrip-9d097af9fe2167fc0dfc71d2e63d6194b2cebfb0.aar
NavigationTabStrip-9d097af9fe2167fc0dfc71d2e63d6194b2cebfb0.pom
NavigationTabStrip-9d097af9fe2167fc0dfc71d2e63d6194b2cebfb0.pom.md5
NavigationTabStrip-9d097af9fe2167fc0dfc71d2e63d6194b2cebfb0.pom.sha1
build.log
In studio synced gradle again
It worked!
This is far better then downloading repo,importing as module in our app and then using it etc etc.
Whenever you make changes to this forked repo don't forget to update commit hash too!
I meet this problem when I try to import orhanobut/logger from github.
Then I go to jitpack.io and search for the package:
find logger in jitpack
Then I clicked the log icon,and found:
Start: Thu Jan 14 11:56:56 UTC 2016
Git:v1.9
commit 5abbc1563422457d4c23e1a0a412d2b0c7dc334e
Merge: 8ef1e6b 522d44d
Author: Orhan Obut
Date: Mon May 25 11:34:20 2015 +0200
Merge pull request #30 from orhanobut/oo/settings-fix
submodule status:
Run gradle build
Gradle build script
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
Downloading https://services.gradle.org/distributions/gradle-2.2.1- all.zip
So this is it,it use gradle 2.2.1-all!
Then I go to my project and change gradle version to 2.2.1 in settings.gradle, everything worked fine!
I'm using Android Studio Arctic Fox 2020.3.1 | Canary 8 and had the issue above.
My repo project is a pure Kotlin project that I want to import into my Android project.
Here are a few steps I did that fixed the issue for me - it could be one of the steps or a combination of them that fixed the issue.
The tag I initially pushed was v0.0.1 but in my build.gradle for the Kotlin project it was version '0.0.1' without the v. So I renamed the tag to 0.0.1 and pushed the tag. #Ricardo's answer above about how to check the JitPack build log was super useful!
Next I ran ./gradlew install on my local machine in the Kotlin repo. This is one of the commands run by JitPack - see the JitPack documentation. When I did this I found this message: Declare the version of Java your build requires.
From that message I decided to specify the Java version. In the Kotlin project build.gradle I added sourceCompatibility = 1.8 and
compileKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
}
After re-running the command in step 2, the Java version issue disappeared.
I pushed the new version of my Kotlin repo and added a new tag.
In the Android project, I had to add the maven { url "https://jitpack.io" } in settings.gradle. I encountered errors when adding it in the build.gradle files for the app or the root one.
I know this is old but I had this problem recently and I solved it by adding
maven { url 'https://jitpack.io' }
to the settings.gradle(ProjectSettings) under dependencyResolutionManagement{repositories{$HERE}}. I don't know if it is recommended or just a fluke since I am not that well versed yet.
Related
i try to add recyclerview to my project and get this error appear and i added it from android studio dependencies
Starting from version 26 of support libraries make sure that the repositories section includes a maven section with the "https://maven.google.com" endpoint.
Something like;
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
This is how I have it working.
Add maven { url "https://maven.google.com" } as #Gabriele_Mariotti suggests above.
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
Then on the build.gradle file inside the App folder add
compileSdkVersion 26
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "com.xxx.yyy"
minSdkVersion 16
targetSdkVersion 26
}
Then on the dependencies use
dependencies {
compile 'com.android.support:appcompat-v7:26.0.1'
compile 'com.android.support:design:26.0.1'
compile 'com.google.android.gms:play-services-maps:11.0.4'
compile 'com.google.android.gms:play-services-location:11.0.4'
compile 'com.mcxiaoke.volley:library-aar:1.0.0'
compile 'com.android.support:cardview-v7:26.0.1'
}
If you are using Android Studio 3.0 or above make sure your project build.gradle should have content similar to-
buildscript {
repositories {
google() // add google() before jcenter()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
}
}
allprojects {
repositories {
google() // add google() before jcenter()
jcenter()
}
}
And for below Android Studio 3.0 and starting from support libraries 26.+ your project build.gradle must look like this-
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
Note- position really matters add google() before jcenter()
check these links below for more details-
1- Building Android Apps
2- Add Build Dependencies
3- Configure Your Build
Just add this to your main all project level build.gradle file under allprojects()
maven {
url "https://maven.google.com"
}
I face the same problem while I have updated my SDK and Android studio version(3.0 beta). I have solved this problem going through this tutorial. In this they told us to update are build configuration file like
android {
compileSdkVersion 26
buildToolsVersion '26.0.0'
defaultConfig {
targetSdkVersion 26
}
...
}
dependencies {
compile 'com.android.support:appcompat-v7:26.0.0'
}
// REQUIRED: Google's new Maven repo is required for the latest
// support library that is compatible with Android 8.0
repositories {
maven {
url 'https://maven.google.com'
// Alternative URL is 'https://dl.google.com/dl/android/maven2/'
}
}
Hope it will help you out.
in may case I found OneSignal changed their dependencies
so I changed it from
compile 'com.onesignal:OneSignal:[3.5.8, 3.99.99]'
to
compile 'com.onesignal:OneSignal:[3.5.8, 3.5.8]'
then it works, please check any unspecific dependency.
Add this to the project level build.gradle file and it should work fine.
allprojects {
repositories {
google() // this is to be added if there's something already.
jcenter()
}
}
Google's new Maven repo is required for the latest support library that is compatible with Android 8.0.
Just update your Google's Maven repository like below:
To add them to your build, add maven.google.com to the Maven repositories in your module-level build.gradle file:
repositories {
maven {
url 'https://maven.google.com'
// Alternative URL is 'https://dl.google.com/dl/android/maven2/'
}
}
Alternative you can update build.gradle file like this:
repositories {
jcenter()
google()
}
Then add the desired library to your dependencies block. For example, the cardview library looks like this:
dependencies {
compile 'com.android.support:cardview-v7:26.1.0'
}
in sdk 28
u can use
implementation 'com.android.support:design:28.0.0'
and remove cardView library
Update your Android Support Repository from sdk manager.
There is another way to add google repository
Add gradle-4.1-rc-1-all in gradle-wrapper.properties.
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-rc-1-all.zip
Then add google() in the top-level build.gradle
allprojects {
repositories {
google()
jcenter()
}
}
Simply change the build-version from
compile 'com.android.support:appcompat-v7:26.0.0'
to
compile 'com.android.support:appcompat-v7:26.0.0-alpha1'
This will solve your problem.
If the other solutions here do not work, make sure you are not in 'offline' mode. If enabled, android will not download the required files and you will get this error.
try to compile
compile 'com.android.support:cardview-v7:25.3.1'
Clean your gradle from terminal
./gradlew clean
then use this code in your build.gradle section
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
Make sure, your included library version is available. For your checking, you can use this link
I had this issue when creating a new project in Android Studio using Kotlin. The way that finally helped me:
allprojects {
repositories {
maven {
url "https://maven.google.com"
}
google()
jcenter()
}
}
Ionic 4, opened /platforms/android/platform.properties, changed the version of the listed library throwing the error (in my case, com.android.support:support-v4:27.+) to:
com.android.support:support-v4:28.+
Use compile 'com.android.support:cardview-v7:25.4.0'
If you want version 26 you should use compile 'com.android.support:cardview-v7:26.0.0-beta2', because it is beta for now
android {
compileSdkVersion 26
buildToolsVersion '26.0.2'
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "com.test"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
this is working for me
compile 'com.android.support:cardview-v7:+'
This should pull the most recent version, and allow it to compile.
try this,
goto Android->sdk make sure you have all depenencies required . if not , download them . then goto File-->Settigs-->Build,Execution,Depoyment-->Gradle
choose use default gradle wapper (recommended)
and untick Offline work
gradle build finishes successfully for once you can change the settings
May be this problem is due to facebook library.
Replace
compile 'com.facebook.android:facebook-android-sdk:[4,5)'
by
compile 'com.facebook.android:facebook-android-sdk:4.26.0'
#Aryan is correct Failed to resolve: com.android.support:appcompat-v7:27.+ (Dependency Error)
A picture worth thousand words
2 Steps to fix this..
1, connect to internet.
2, Click on clean project. this will fix it
:)
For me I just had to clean my project.
Build -> Clean Project
Another time I had to:
File -> Sync Project with Gradle Files.
When you sync this dependency to the android studio:
implementation 'com.android.support:cardview-v7:26.0.1-alpha1'
Then, Sync the Gradle with Project Files.
It will say, (Suppose if you are working on new ones like androidx) obviously, it will show error on the dependency.
For that you can go to the File menu and click on the invalidate/restart the code. It will resolve itself and the application will restart without any error.
i try to add recyclerview to my project and get this error appear and i added it from android studio dependencies
Starting from version 26 of support libraries make sure that the repositories section includes a maven section with the "https://maven.google.com" endpoint.
Something like;
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
This is how I have it working.
Add maven { url "https://maven.google.com" } as #Gabriele_Mariotti suggests above.
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
Then on the build.gradle file inside the App folder add
compileSdkVersion 26
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "com.xxx.yyy"
minSdkVersion 16
targetSdkVersion 26
}
Then on the dependencies use
dependencies {
compile 'com.android.support:appcompat-v7:26.0.1'
compile 'com.android.support:design:26.0.1'
compile 'com.google.android.gms:play-services-maps:11.0.4'
compile 'com.google.android.gms:play-services-location:11.0.4'
compile 'com.mcxiaoke.volley:library-aar:1.0.0'
compile 'com.android.support:cardview-v7:26.0.1'
}
If you are using Android Studio 3.0 or above make sure your project build.gradle should have content similar to-
buildscript {
repositories {
google() // add google() before jcenter()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
}
}
allprojects {
repositories {
google() // add google() before jcenter()
jcenter()
}
}
And for below Android Studio 3.0 and starting from support libraries 26.+ your project build.gradle must look like this-
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
Note- position really matters add google() before jcenter()
check these links below for more details-
1- Building Android Apps
2- Add Build Dependencies
3- Configure Your Build
Just add this to your main all project level build.gradle file under allprojects()
maven {
url "https://maven.google.com"
}
I face the same problem while I have updated my SDK and Android studio version(3.0 beta). I have solved this problem going through this tutorial. In this they told us to update are build configuration file like
android {
compileSdkVersion 26
buildToolsVersion '26.0.0'
defaultConfig {
targetSdkVersion 26
}
...
}
dependencies {
compile 'com.android.support:appcompat-v7:26.0.0'
}
// REQUIRED: Google's new Maven repo is required for the latest
// support library that is compatible with Android 8.0
repositories {
maven {
url 'https://maven.google.com'
// Alternative URL is 'https://dl.google.com/dl/android/maven2/'
}
}
Hope it will help you out.
in may case I found OneSignal changed their dependencies
so I changed it from
compile 'com.onesignal:OneSignal:[3.5.8, 3.99.99]'
to
compile 'com.onesignal:OneSignal:[3.5.8, 3.5.8]'
then it works, please check any unspecific dependency.
Add this to the project level build.gradle file and it should work fine.
allprojects {
repositories {
google() // this is to be added if there's something already.
jcenter()
}
}
Google's new Maven repo is required for the latest support library that is compatible with Android 8.0.
Just update your Google's Maven repository like below:
To add them to your build, add maven.google.com to the Maven repositories in your module-level build.gradle file:
repositories {
maven {
url 'https://maven.google.com'
// Alternative URL is 'https://dl.google.com/dl/android/maven2/'
}
}
Alternative you can update build.gradle file like this:
repositories {
jcenter()
google()
}
Then add the desired library to your dependencies block. For example, the cardview library looks like this:
dependencies {
compile 'com.android.support:cardview-v7:26.1.0'
}
in sdk 28
u can use
implementation 'com.android.support:design:28.0.0'
and remove cardView library
Update your Android Support Repository from sdk manager.
There is another way to add google repository
Add gradle-4.1-rc-1-all in gradle-wrapper.properties.
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-rc-1-all.zip
Then add google() in the top-level build.gradle
allprojects {
repositories {
google()
jcenter()
}
}
Simply change the build-version from
compile 'com.android.support:appcompat-v7:26.0.0'
to
compile 'com.android.support:appcompat-v7:26.0.0-alpha1'
This will solve your problem.
If the other solutions here do not work, make sure you are not in 'offline' mode. If enabled, android will not download the required files and you will get this error.
try to compile
compile 'com.android.support:cardview-v7:25.3.1'
Clean your gradle from terminal
./gradlew clean
then use this code in your build.gradle section
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
Make sure, your included library version is available. For your checking, you can use this link
I had this issue when creating a new project in Android Studio using Kotlin. The way that finally helped me:
allprojects {
repositories {
maven {
url "https://maven.google.com"
}
google()
jcenter()
}
}
Ionic 4, opened /platforms/android/platform.properties, changed the version of the listed library throwing the error (in my case, com.android.support:support-v4:27.+) to:
com.android.support:support-v4:28.+
Use compile 'com.android.support:cardview-v7:25.4.0'
If you want version 26 you should use compile 'com.android.support:cardview-v7:26.0.0-beta2', because it is beta for now
android {
compileSdkVersion 26
buildToolsVersion '26.0.2'
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "com.test"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
this is working for me
compile 'com.android.support:cardview-v7:+'
This should pull the most recent version, and allow it to compile.
try this,
goto Android->sdk make sure you have all depenencies required . if not , download them . then goto File-->Settigs-->Build,Execution,Depoyment-->Gradle
choose use default gradle wapper (recommended)
and untick Offline work
gradle build finishes successfully for once you can change the settings
May be this problem is due to facebook library.
Replace
compile 'com.facebook.android:facebook-android-sdk:[4,5)'
by
compile 'com.facebook.android:facebook-android-sdk:4.26.0'
#Aryan is correct Failed to resolve: com.android.support:appcompat-v7:27.+ (Dependency Error)
A picture worth thousand words
2 Steps to fix this..
1, connect to internet.
2, Click on clean project. this will fix it
:)
For me I just had to clean my project.
Build -> Clean Project
Another time I had to:
File -> Sync Project with Gradle Files.
When you sync this dependency to the android studio:
implementation 'com.android.support:cardview-v7:26.0.1-alpha1'
Then, Sync the Gradle with Project Files.
It will say, (Suppose if you are working on new ones like androidx) obviously, it will show error on the dependency.
For that you can go to the File menu and click on the invalidate/restart the code. It will resolve itself and the application will restart without any error.
I want to include a library in Android Studio , but it displays error like below :
"Failed to resolve:com.lemonlab:expandable-button-menu:1.0.0"
How to fix this problem?
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion '21.1.2'
defaultConfig {
applicationId "ayowes.com.newecampus"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-ptimize.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.google.android.gms:play-services:6.5.87'
compile 'com.lemonlab:expandable-button-menu:1.0.0'
compile files('libs/pinchzoom.jar')
}
You go File->Settings->Gradle
Look at the "Offline work" inbox, if it's checked u uncheck and try to sync again
I have the same problem and i try this , the problem resolved. Good luck !
I had the same problem, the first thing that came to mind was repositories. So I checked the build.gradle file for the whole project and added the following code, then synchronized the gradle with project and problem was solved!
allprojects {
repositories {
jcenter()
}
}
Some time you may just need to add maven { url "https://jitpack.io" } in your allprojects block in project level build.gradle file.
Example:
allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
}
To be able to use a lib project you need to include it in your application's settings.gradle add:
include '..:ExpandableButtonMenu:library'
and then in your build.gradle add:
compile project(':..:ExpandableButtonMenu:library')
place ExpandableButtonMenu project along side your own (same folder)
see this How to build an android library with Android Studio and gradle? for more details.
Solved by using "http://jcenter.bintray.com/" instead of "https://jcenter.bintray.com/".
repositories {
jcenter( { url "http://jcenter.bintray.com/" } )
}
Well, it's co.lemonlabs, you have a typo in your build.gradle:
compile 'co.lemonlabs:expandable-button-menu:1.0.0'
Source: https://github.com/lemonlabs/ExpandableButtonMenu#including-in-your-project
Check to see if your gradle is offline. Preferences-ProjectSettings-Gradle.
If you're trying to add a library while offline, you'll see that error. Also, try Build-Clean, it may provide you with more detail.
Try this
Clean project
Invalidate cache and restart studio
Check android SDK path is proper
Check is there any error in any of your resource file
repositories {
mavenCentral()
}
I added this in build.gradle, and it worked.
For me follwing steps helped.
It seems to be bug of Android Studio 3.4/3.5 and it was "fixed" by disabling:
File → Settings → Experimental → Gradle → Only sync the active variant
i had the same problem, i added the following lines in build.gradle
allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
maven {
url 'http://dl.bintray.com/dev-fingerlinks/maven'
}
mavenCentral()
}
}
If adding repositories didn't work, check that your settings.gradle contains:
repositoriesMode.set(RepositoriesMode.PREFER_PROJECT)
This is my first attempt at Android Studio. I installed 0.8.0 and updated to 0.8.2. As soon as a project is created I get the error message:
Error:(1, 0) Plugin with id 'com.android.application' not found
C:\Users\Bob\AndroidStudioProjects\HelloAgain6\app\build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "com.example.bob.helloagain6"
minSdkVersion 15
targetSdkVersion 20
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
and C:\Users\Bob\AndroidStudioProjects\HelloAgain6\build.gradle
// 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:0.12.+'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
Updated Answer (Dec. 2, 2020)
Latest Gradle: 6.5
Version check:
./gradlew -v
How to update:
Set URL: ./gradlew wrapper --gradle-version=6.5 --distribution-type=all
Update: ./gradlew wrapper
Latest Android Gradle Plugin: 4.1.0
If you add the following code snippet to the top of your build.gradle file. Gradle will update the build tools.
buildscript {
repositories {
google() // For Gradle 4.0+
maven { url 'https://maven.google.com' } // For Gradle < 4.0
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
}
}
Read more here: https://developer.android.com/studio/build/index.html and about version compatibility here: https://developer.android.com/studio/releases/gradle-plugin.html#updating-gradle and https://dl.google.com/dl/android/maven2/index.html.
Original Answer
I had this same error, you need to make sure your Gradle version is compatible with your Android Gradle Plugin.
The latest version of Gradle is 2.0 but you need to use 1.12 in order to use the Android Gradle Plugin.
This can happen if you miss adding the Top-level build file.
Just add build.gradle to top level.
It should look 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.xx.y'
}
}
allprojects {
repositories {
mavenCentral()
}
}
In my case, I download the project from GitHub and the Gradle file was missing. So I just create a new project with success build. Then copy-paste the Gradle missing file. And re-build the project is working for me.
Root-gradle file:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:x.x.x'
}
}
allprojects {
repositories {
jcenter()
}
}
Gradle-wrapper.properties file:
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-x.x-all.zip
In the project level build.gradle file, I have replaced this line
classpath 'com.android.tools.build:gradle:3.6.3'
with this one
classpath 'com.google.gms:google-services:4.3.3'
After adding both of those lines, and syncing, everything became fine.
Hope this will help someone.
I am writing this not as a solution meant for many, but for some people who may commit a simple mistake like specifying the wrong url for importing projects from SVN. It is intended for those guys :)
This happened to me when I imported the project from SVN -> automatic prompt by Studio to open the project -> It asked for Gradle location -> D:\Software\Android\gradle-2.5 -> Then the error.
The same project in a different SVN branch works fine with the Gradle plugin and Gradle which I have configured in Studio. I tried changing Android Gradle plugin and Gradle to get it working on the erring branch without any success.
Finally, I figured out that it was my following mistake:
I tried importing a specific Application alone instead of importing the application along with dependent library projects.
The url which I used for import initially had the Application porject's name at the end. Once I removed it, and specified the parent directory which contained both application project and its dependent project, everything went smooth :)
I found the problem after one hour struggling with this error message:
I accidentally renamed the root build.gradle to filename in builde.gradle, so Android Studio didn't recognize it anymore.
Renaming it to build.gradle resolved the issue!
I still got the error
Could not find com.android.tools.build:gradle:3.0.0.
Problem: jcenter() did not have the required libs
Solution: add google() as repo
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:3.0.0"
}
}
I was using IntelliJ IDEA 13.1.5 and faced with the same problem after I changed versions of Picasso and Retrofit in dependencies in build.gradle file. I tried use many solutions, but without result.
Then I cloned my project from remote git (where I pushed it before changing versions of dependencies) and it worked! After that I just closed current project and imported old project from Gradle file to IntelliJ IDEA again and it worked too! So, I think it was strange bug in intersection of IDEA, Gradle and Android plugin. I hope this information can be useful for IDEA-users or anyone else.
Go to your grade file where you can see this:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
And change classpath to this:
buildscript {
repositories {
jcenter()
}
dependencies {
// classpath 'com.android.tools.build:gradle:2.1.0'
classpath 'com.android.tools.build:gradle-experimental:0.7.0-alpha1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
The other answers didn't work for me, I guess something wrong happens between ButterKnife and 3.0.0 alpha5.
However, I found that when I annotated any one sentence, either BUtterKnife or 3.0.0 alpha5, it works normally.
So, you should just avoid the duplication or conflict.
For future reference: For me, this issue was solely caused by the fact that I wasn't running Android Studio as administrator. I had the shortcut on Windows configured to always run as administrator, but after reinstalling Android Studio, the shortcut was replaced, and so it ran without administrator rights. This caused a lot of opaque errors, including the one in this question.
This issue happened when I accidently renamed the line
apply plugin: 'com.android.application'
on file app/build.gradle to some other name. So, I fixed it by changing it to what it was.
[FOR FLUTTER] go to your build Gradle then check if you have three paths
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.google.gms:google-services:4.3.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
I somehow removed the android tools classpath and was getting the error.
This just happened to me using Android Studio 1.3.2, however, since I had just created the project, I deleted it and created it again.
It seems that it had not been properly created by Android Studio the first time, not even the project folders where as expected.
If you run a the module task with android plugin 1.2.3 in module directory , the problem appears. Try this:
../gradlew -b ../build.gradle -c ../settings.gradle :module:xxx
Make sure your two build.gradle and settings.gradle files are in the correct directories as stated in https://developer.android.com/studio/build/index.html
Then open "as existing project" in Visual Studio
Gradle is very finicky about this.
I got this error message after making the following change in my top-level build.gradle to update to the latest version of gradle:
//classpath 'com.android.tools.build:gradle:2.3.2' old
classpath 'com.android.tools.build:gradle:2.3.3' //new
I foolishly made the change while I was connected behind a hostile workplace proxy. The proxy caused the .jar files for the new version of gradle to become corrupt. This can be verified by inspecting the jars to see if they are an unusual size or whether they can be unzipped.
In order to fix the mistake, I connected to my network at home (which is not behind a proxy) and did a refresh dependencies from the Terminal:
./gradlew --refresh-dependencies
This caused the newer version of gradle to be re-downloaded and the error no longer occurs.
Check the spelling, mine was 'com.android.aplication'
This may also happen when you have both settings.gradle and settings.gradle.kts files are present in project root directory (possibly with the same module included). You should only have one of these files.
i had similar problem and i did following things to resolve it.
i referred to https://developer.android.com/studio/build
and copy / pasted these following lines before apply plugin lines
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.0'
}
}
module app build.gradle file
apply plugin: 'com.android.application'
model{
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig.with {
applicationId "com.iamsafe"
minSdkVersion 15
targetSdkVersion 23
}
buildTypes {
debug {
minifyEnabled = false
useProguard = true
proguardFiles.add(file('proguard-rules.txt'))
}
}
}
}
dependencies {
compile 'com.android.support:support-v4:23.0.2'
compile files('libs/asmack-android-8-0.8.10.jar')
compile files('libs/commons-io-2.0.1.jar')
compile files('libs/httpclient-osgi-4.2.1-sources.jar')
compile files('libs/httpcore-4.3.2.jar')
compile files('libs/httpmime-4.1.2.jar')
}
project build.gradle
// 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:2.10'
}
}
allprojects {
repositories {
jcenter()
}
}
In this case of issues check below code
dependencies {
classpath 'com.android.tools.build:gradle:**1.5.0**'
}
and gradle-wrapper.properties inside your project directory check below disctributionUrl:
distributionUrl=https\://services.gradle.org/distributions/gradle-2.9-all.zip
If these are not compatible with each other then you end up in this issue.
For com.android.tools.build:gradle:1.5. you need a version at least 2.8 but if you switch to a higher version like com.android.tools.build:gradle:2.1.0 then you need to update your gradle to 2.9 and above this can be done by changing distributionUrl in gradle-wrapper.properties to 2.9 or higher as below
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
If you work on Windows , you must start Android Studio name by Administrator.
It solved my problem
Just make sure you put the http and https proxy correctly when you create the app
Just when I'd achieved an effective development and build environment with the android-maven-plugin, the new kid on the block, Gradle, starts making inroads into the Android circles. Not being hot on Groovy and with the android-gradle plugin almost as fragmented as the OS itself I've hit some issues. Specifically around building library projects, with flavours and our buddy Robolectric.
Short version
I am at a loss as to what my next move should be upon encountering the gradle error;
Cannot add a SourceSet with name 'testDebug' as a SourceSet with that name already exists.
The error emanates from having productFlavours on a library (i.e. moving to the 0.9.2 android build system) and the gradle-android-test-plugin recently forked by the team over at Robolectric from Jake's creation (see here). I have followed all lines of investigation to near exhaustion and can report that the meer existence of the 'android-test' plugin within my library gradle file sends things awry.
Longer version
Here is the abridged application build.gradle file with pertinent information retained;
apply plugin: 'android-library'
apply plugin: 'android-test'
...
android {
compileSdkVersion 19
buildToolsVersion '19.0.3'
defaultConfig {
minSdkVersion 18
targetSdkVersion 19
versionCode buildNumber().toInteger()
versionName "1.0.0"
}
productFlavors {
estimote {
dependencies {
compile '<flavour specific dependency>'
}
}
radius {
dependencies {
compile '<flavour specific dependency>'
}
}
}
}
...
dependencies {
compile 'com.squareup.dagger:dagger:1.2.1'
compile 'com.squareup.dagger:dagger-compiler:1.2.1'
compile 'com.google.code.gson:gson:2.2.+'
// Testing dependencies
androidTestCompile 'org.mockito:mockito-core:1.9.5'
androidTestCompile 'com.squareup:fest-android:1.0.7'
androidTestCompile 'org.hamcrest:hamcrest-all:1.3'
androidTestCompile 'org.robolectric:robolectric:2.2'
androidTestCompile 'junit:junit:4.11'
}
And here is the abridged root build.gradle file.
buildscript {
repositories {
mavenLocal()
mavenCentral()
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.2'
classpath 'org.robolectric.gradle:gradle-android-test-plugin:0.9.+'
}
}
allprojects {
repositories {
mavenLocal()
mavenCentral()
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots'
}
}
}
If you've got this far down the page, give yourself a pat on the back. Now, the eagle eyed amongst you have probably noticed the omission on the sourceSets redirection with commands akin to;
sourceSets {
androidTest {
setRoot('src/test')
}
}
After the initial error is corrected these lines will need to be reinstated to inform gradle of the project's structure. The project's structure is standard and looks like;
- project_name
+ gradle
- lib
+ flavour1
+ flavour2
- main
+ java
- test
+ java
build.gradle
build.gradle
gradle.properties
settings.gradle
What is being used
The app is using gradle-1.10-all, 0.9.2 android-gradle plugin and 0.9.+ gradle-android-test-plugin.
The question
How should the project be set-up/changed to facilitate Robolectric testing on a library with flavours? Is this even possible yet?
I ran into the same issue, dug into the code, fixed it, and submitted a pull request which has just now been merged. See my explanation on the PR for details, but it boils down to a bad optimization in the plugin code:
https://github.com/robolectric/robolectric-gradle-plugin/pull/70
As of today you need to clone the repo and build and install the plugin to your local maven repo. The next time they do a release to maven central (perhaps release 0.13.1?), you'll be able to use the plugin directly from there.