I am using the Gradle build system bundled with Android Studio. So far, I am able to build multi-project setups using dependencies that are stored in my project structure. I would now like to use a maven dependency, to no avail. I have written a very simple build.gradle file that always fails :
buildscript {
repositories {
maven { url 'http://repo1.maven.org/maven2' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android'
dependencies {
compile 'com.google.android:support-v4:r7'
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
}
}
with the following message :
* What went wrong:
A problem occurred configuring project ':absabs'.
> Failed to notify project evaluation listener.
> Could not resolve all dependencies for configuration ':absabs:compile'.
> Could not find com.google.android:support-v4:r7.
Required by:
absabs:absabs:unspecified
....
Caused by: org.gradle.api.internal.artifacts.ivyservice.ModuleVersionNotFoundException: Could not find com.google.android:support-v4:r7.
It happens with any artifact I have tried so far. Any idea of what's wrong ?
Thanks
The "repositories" block in the buildscript section only applies to the build environment. You also need to specify which repository to use when resolving dependencies for building your project, so you need to put something like the following in your build.gradle file:
repositories {
mavenCentral()
}
Your complete file would look something like this:
buildscript {
repositories {
maven { url 'http://repo1.maven.org/maven2' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
compile 'com.google.android:support-v4:r7'
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
}
}
Note the two instances of "repositories". You can read more about what this actually means in the gradle docs.
Seems that current Android Studio version doesn't pick up new dependencies immediately. Try to restart IDE.
Edit:
This is not needed for Android Studio >= 0.1.4v. It has build in action Sync Project with Gradle file. You can find it under Tools > Android > Sync Project with Gradle file or just button in Toolbar.
http://tools.android.com/tech-docs/new-build-system/user-guide
Note: This only affects the code running the build, not the project. The project itself needs to declare its own repositories and dependencies. This will be covered later.
So you have to declare
repositories {
mavenCentral()
}
in your project scope once more.
I did it this way:
In Top build.gradle (Project: YourProject) I added:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.h2database:h2:1.4.187'
//NOTE: you can get the latest version in http://mvnrepository.com/artifact/com.h2database/h2
}
}
allprojects {
repositories {
jcenter()
mavenCentral()
}
}
NOTE: I added this along with the predefined jcenter() repositories.
And then for my app/build.gradle file I added whichever library or dependency I needed on:
dependencies {
....//Add dependency here
}
I recently had to use a maven dependency in gradle, maybe this little example will be of use for someone.
In maven:
<dependency>
<groupId>com.turo</groupId>
<artifactId>pushy</artifactId>
<version>0.12.1</version>
</dependency>
In grade that turns into:
repositories {
mavenCentral()
}
dependencies {
compile 'com.turo:pushy:0.12.1'
}
maven
Maven continues using XML as the format to write build specification. However, structure is diametrically different. Maven has its own problems. Dependencies management does not handle well conflicts between different versions of the same library (something Ivy is much better at). XML as the build configuration format is strictly structured and highly standardized. Customization of targets (goals) is hard. Since Maven is focused mostly on dependency management, complex, customized build scripts are actually harder to write in Maven than in gradel.
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 have installed Android Studio version 2.1.2 in my system and if I add any dependencies in the Gradle file then I get failed to resolve error.
It happen the all the libraries likes Picasso not only for Junit
So I tried to add proxy setting in gradle.properties file
systemProp.http.proxyHost=http://xxxx/xxx
systemProp.http.proxyPort=80
systemProp.https.proxyHost=http://xxxx/xxx
systemProp.https.proxyPort=80
but I get the following error:
Error:A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugCompile'.
> Could not resolve junit:junit:4.12.
Required by:
MyApplication2:app:unspecified
> Could not resolve junit:junit:4.12.
> Could not get resource 'https://jcenter.bintray.com/junit/junit/4.12/junit-4.12.pom'.
> Could not GET 'https://jcenter.bintray.com/junit/junit/4.12/junit-4.12.pom'.
> http://xxxx/xxx
How to resolve this issue, please help on that.
build.gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "24.0.0"
defaultConfig {
applicationId "com.example.muraliathmarao.myapplication"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
}
You need to add a section allprojects at the end of your main build.gradle that defines the repositories for the modules of your project:
allprojects {
repositories {
jcenter()
}
}
and this is the build.gradle (project)
buildscript {
repositories {
jcenter()
mavenCentral()
}
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
}
}
allprojects {
repositories {
jcenter()
mavenCentral()
}
}
You should update your Android Repository do to it:
1.Open SDK Manager
2.Android Support Repository
3.Install packages
I am under closed network, it does not allow to get Gradle library get
downloaded
If you're on a completely closed network (no internet access at all), it's common to have a central in-house repository for dependencies, within the local network, where all internal users can get dependencies from. This local repository needs to replicate everything that you would download from external sites/repositories. For example, you must have got your Android Studio install and Android SDK dependencies from somewhere. Also, the Android SDK regularly receives updates - do you see updates when you run the Android SDK manager?
Even if you're the only developer, it may be useful to set up your own local Maven repo to keep all your dependencies in - this needs to be accessible from the machine you're building on (could just be on your development machine). See https://maven.apache.org/guides/introduction/introduction-to-repositories.html#Internal_Repositories. Then you need to add to your local repository with the dependencies you need - how you do this of course will depend on how you get any kind of external file onto your closed network (e.g. like your Android Studio or Android SDK dependencies in the first place).
There could be any one of the following issue,
First check the repository link is accessible or not; through your browser.
(If you're unable to access the link; contact your network infrastructure team)
If link is accessible in browser; then the issue is with your gradle configuration. Make sure you have following entries in your root gradle file.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'>
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
Please check your 'buildToolsVersion' in build.gradle.Please make sure that your sdk files have been updating. Otherwise change buildToolVersion from your current '24.0.0' to '23.0.1' or less in build.gradle file
allprojects {
repositories {
jcenter()
mavenCentral()
google()
}
}
helped for me. google() was the key improvement there, as the desired dependencies were in the google repo.
It wasn't working because I am on a closed network, it does not allow to get Gradle library get downloaded, I am using jar files.
I am trying to make use of some maven dependencies in a new Android project, but I am new to using Android-Studio and Gradle. I looked at a few other solutions such as this:
How to import Maven dependency in Android Studio/IntelliJ?
and thought it looked simple enough. So I modified the build.gradle file to this:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
maven { url 'http://repo1.maven.org/maven2' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
compile 'com.google.android:android:4.1.1.4'
compile 'com.factual:factual-java-driver:1.7.7-android'
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
}
}
but when I compiled the project I got the error:
Gradle: A problem occurred configuring root project 'LookAroundYouProject'.
> Failed to notify project evaluation listener.
> Main Manifest missing from /home/tstewart/AndroidStudioProjects/LookAroundYouProject/src/main/AndroidManifest.xml
I am not really sure what this is telling me. Currently it is just a simple hello world example and it worked before modifying the gradle file.
EDIT:
I moved the compile statements from the Top-level build file to the one within the application itself and for some reason this seemed to work and I no longer appear to be getting errors. Sadly I have no idea why this is the case.
Im trying to build a simple android app using gradle build tools. but im getting an error like this
No signature of method: org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.compile() is applicable for argument types: (java.lang.String) values: [org.gradle.api.plugins:gradle-android-plugin:1.2.0-SNAPSHOT]
Possible solutions: module(java.lang.Object)
ang here's a simple configuration of build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
compile 'org.gradle.api.plugins:gradle-android-plugin:1.2.0-SNAPSHOT'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
processResource {
expand (project.properties)
}
task configureDebug << {
jar.classifier = "debug"
}
task configureRelease << {
proguard.enabled = true
}
When applying a plugin you want tell you build script to use it in its classpath. It is not required for compilation so just change the configuration compile to classpath. More more information see 51.5.1. Using your plugin in another project in the Gradle user guide.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.gradle.api.plugins:gradle-android-plugin:1.2.0-SNAPSHOT'
}
}
EDIT: At the moment the plugin does not support r20 of the Android SDK. For more information see this issue.
Make sure you are writing the dependency block on your application build.gradle "YourProjectName->yourprojectname->build.gradle" in android studio hierarchy .
Use android gradle tools
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}