Why I can not add my project dependencies? - android

When I start a new project, I see the following errors about my dependencies.
Actually, I'm using a VPN but I don't know what's the problem?!
And I didn't have this problem before, but now see that since updating my Android Studio, and I should say I searched about this problem a lot but didn't find any solution
Unable to resolve dependency for ':app#debug/compileClasspath': Could not resolve com.google.android.gms:play-services-maps:16.0.0.
Open File
Show Details
Unable to resolve dependency for ':app#debugAndroidTest/compileClasspath': Could not resolve com.android.support.test:runner:1.0.2.
Open File
Show Details
Unable to resolve dependency for ':app#debugAndroidTest/compileClasspath': Could not resolve com.android.support.test.espresso:espresso-core:3.0.2.
Open File
Show Details
Unable to resolve dependency for ':app#debugAndroidTest/compileClasspath': Could not resolve com.google.android.gms:play-services-maps:16.0.0.
Open File
Show Details
Unable to resolve dependency for ':app#debugUnitTest/compileClasspath': Could not resolve com.google.android.gms:play-services-maps:16.0.0.
Open File
Show Details
Unable to resolve dependency for ':app#release/compileClasspath': Could not resolve com.google.android.gms:play-services-maps:16.0.0.
Open File
Show Details
Unable to resolve dependency for ':app#releaseUnitTest/compileClasspath': Could not resolve com.google.android.gms:play-services-maps:16.0.0.
Open File
Show Details
build.gradle (Module:app):
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.pasargad.test_map"
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
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:28.0.0'
implementation 'com.google.android.gms:play-services-maps:16.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
build.gradle (Project:...):
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

First make sure that you have disabled the gradle offline work like the image below.
Now Connect Pc with the internet. Then Sync your Project Again. It should solve your problem.

make sure that android studio is not in offline mode and re sync with internet connection and if all of those do not work then
1) go to android studio folder on file explorer or something and go to gradle and then look at your gradle file (means version for example mine is gradle-4.6-all and then delete it)
2)go to gradler offilce website and download the same gradle version
gradle official site (for example gradle v4.6)
3)unzip it and paste there where you had been deleted
4)Re sync with internet connection

I found my answer. The problem was because of the proxy info in "gradle.properties" file, I deleted all of the lines about proxy (host, password, etc) and synced the project again

Related

Android studio unable to build my app after gradle plugin updated

I updated the Gradle plugin yesterday and now the android studio is not able to build my app. The app shows the following error.
ERROR: Unable to resolve dependency for ':app#debug/compileClasspath': Could not resolve io.grpc:grpc-core:[1.16.1].
Show Details
Affected Modules: app
ERROR: Unable to resolve dependency for ':app#debugAndroidTest/compileClasspath': Could not resolve io.grpc:grpc-core:[1.16.1].
Show Details
Affected Modules: app
ERROR: Unable to resolve dependency for ':app#debugUnitTest/compileClasspath': Could not resolve io.grpc:grpc-core:[1.16.1].
Show Details
Affected Modules: app
ERROR: Unable to resolve dependency for ':app#release/compileClasspath': Could not resolve io.grpc:grpc-core:[1.16.1].
Show Details
Affected Modules: app
ERROR: Unable to resolve dependency for ':app#releaseUnitTest/compileClasspath': Could not resolve io.grpc:grpc-core:[1.16.1].
Show Details
Affected Modules: app
WARNING: API 'variant.getExternalNativeBuildTasks()' is obsolete and has been replaced with 'variant.getExternalNativeBuildProviders()'.
It will be removed at the end of 2019.
For more information, see https://d.android.com/r/tools/task-configuration-avoidance.
To determine what is calling variant.getExternalNativeBuildTasks(), use -Pandroid.debug.obsoleteApi=true on the command line to display a stack trace.
Affected Modules: app
My app level build.gradle file looks like this:
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.mvp1stockmeter"
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
dataBinding
{
enabled true
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:multidex:1.0.3'
implementation 'org.jsoup:jsoup:1.11.3'
implementation 'com.google.firebase:firebase-core:16.0.7'
implementation 'com.google.firebase:firebase-firestore:18.0.0'
implementation 'com.google.firebase:firebase-core:16.0.7'
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.9'
implementation 'com.firebaseui:firebase-ui-auth:4.3.1'
implementation 'com.google.firebase:firebase-auth:16.1.0'
//implementation 'com.facebook.android:facebook-android-sdk:4.x'
implementation 'com.jjoe64:graphview:4.2.2'
}
apply plugin: 'com.google.gms.google-services'
My project level build.gradle file looks like this:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
maven {
url 'https://maven.fabric.io/public'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
classpath 'com.google.gms:google-services:4.2.0'
classpath 'io.fabric.tools:gradle:1.26.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven {
url 'https://maven.google.com/'
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I searched this on StackOverflow and google as well. But did not find any information. Please help. I am stuck here.
I don't have a clue why this is happening, but it is happening since yesterday, March 21 2019. I think it is a problem in the maven repository? Because the url where android studio is trying to get that library is down.
Anyway, the fix is to "manually" point AS to that missing dependency, adding this line into your build.gradle, inside dependencies{...}
implementation group: 'io.grpc', name: 'grpc-core', version: '1.16.1'
Then sync, then you can delete that line.
Well, I hope someone can explain what happened.
Adding mavenCentral() to allprojects{} section of project level build.gradle file has resolved this issue for me.
Adding mavenCentral() to buildScript{} section of project level build.gradle file has resolved this issue for me. Thanks for your support.
I had three build errors of the following type:
Unable to resolve dependency for ':app#debugUnitTest/compileClasspath': Could not resolve io.grpc:grpc-core:[1.28.0].
As with many of these android studio related issues,
File -> Invalidate Caches / Restart...
did the trick for me.
Delete this line :- testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"...It worked for me
Add mavenCentral() to your buildscripts->repositories and allprojects->repositories both places and sync the project.

Could not resolve com.android.support:design 28.0.0

I am getting below error in my new Android studio version, when I want add floating EditText. I need to add this android.support.design library if I add this in gradle file
This is errors which i'm getting in logcat
Unable to resolve dependency for ':app#debug/compileClasspath': Could
not resolve com.android.support:design-v7:28.0.0 Open File Show
Details
Unable to resolve dependency for
':app#debugAndroidTest/compileClasspath': Could not resolve
com.android.support:design-v7:28.0.0. Open File Show Details
Unable to resolve dependency for
':app#debugUnitTest/compileClasspath': Could not resolve
com.android.support:design-v7:28.0.0. Open File Show Details
Unable to resolve dependency for ':app#release/compileClasspath':
Could not resolve com.android.support:design-v7:28.0.0. Open File Show
Details
Unable to resolve dependency for
':app#releaseUnitTest/compileClasspath': Could not resolve
com.android.support:design-v7:28.0.0. Open File Show Details
Note: I referred more links I tried all solutions even though I didn't get solution.
I already unchecked offline work in gradle. I added maven also in gradle file and cleaned, rebuilded the project even-though I didn't get solutions.
This is gradle file:
apply plugin: 'com.android.application'
repositories {
maven { url "https://jitpack.io" }
}
android {
compileSdkVersion 28
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "fadila.new_tech.app"
minSdkVersion 16
targetSdkVersion 28
versionCode 6
versionName "1.5"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
}
This is Gradle(PRjoect module)
buildscript {
repositories {
google()
jcenter()
maven {
url 'https://maven.google.com' //put it here
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven {
url 'https://maven.google.com' //put it here
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
See Sdk Manager image I already updated 28 version
enter image description here
enter image description here
You can try to compile the package using plus sign
implementation 'com.android.support:design:28.0.+'
or
implementation 'com.android.support:design:28.+'
However google changed the package name, all packages mapping here
All new Support Library development will occur in the AndroidX library
so you have to use
implementation 'com.google.android.material:material:1.0.0'
instead of
implementation 'com.android.support:design:28.0.+'
Close Your Android studio first and then please goes to "C:/Users/" then deleting .android ,.gradle and .AndroidStudio folders.This will delete all current android settings. After the delete process completion you go and then open the studio, when you open the android studio again it will ask for the download dependencies by automatically.
Once Download complete please build your project. it will work.
For me this happened because for some reasons i activated the offline work.
In order to solve this issue i had to deactivate it by going to
File>Settings and then selecting the Build, Execution, Deployment option from the left side of the Settings window. Now click on the Gradle option and then you can see the Offline Work which you can uncheck if it is checked.
But,above all don't forget to check your internet connexion
You can try upgrading this these dependencies:
implementation 'com.android.support:support-v4:27.0.2'
implementation 'com.android.support:appcompat-v7:27.0.2'
implementation 'com.android.support:design:27.0.2'
to:
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:appcompat-v7:28.0.0'
You are having wrong dependency in your gradle
com.android.support:design:28.0.8
latest version current is
com.android.support:design:28.0.0
The version you have used doesn't exist and thus it is producing errors.
Change your dependency to what I have mentioned earlier i.e to version 28.0.0 clean and build your project, If it does not work invalidate caches and restart your andorid studio.
Just disabling the offline mode resolved the issue for me.
Mind you, at the time I am typing this, the latest design library is 28.0.0.

Retrofit 2.4.0 with Gradle plugin 3.1.2

I have a very simple question. I'm an Android Developer returning back to development after a 6 months break and as usual everything has changed apparently. Here is my question:
Start a new Android project on Android Studio 3.1.2
Default Gradle plugin is 3.1.2
Added retrofit2 dependency to app's build.gradle
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
Started gradle sync
Unable to resolve dependency for ':app#debug/compileClasspath': Could
not resolve com.squareup.retrofit2:retrofit:2.4.0. Open File Show
Details
Unable to resolve dependency for
':app#debugAndroidTest/compileClasspath': Could not resolve
com.squareup.retrofit2:retrofit:2.4.0. Open File Show Details
Unable to resolve dependency for
':app#debugUnitTest/compileClasspath': Could not resolve
com.squareup.retrofit2:retrofit:2.4.0. Open File Show Details
Unable to resolve dependency for ':app#release/compileClasspath':
Could not resolve com.squareup.retrofit2:retrofit:2.4.0. Open File
Show Details
Unable to resolve dependency for
':app#releaseUnitTest/compileClasspath': Could not resolve
com.squareup.retrofit2:retrofit:2.4.0. Open File Show Details
I read the whole article about Gradle plugin 3 migration. It is no help.
Project build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
app level build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
buildToolsVersion "27.0.3"
defaultConfig {
applicationId "com.xyz.xyz"
minSdkVersion 15
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
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:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
if your PC is running on some proxy please add proxy in android studio or check your internet connection.
For Proxy follow below steps:
File -> Settings -> Appearence & Behaviour -> System Setting -> HTTP Proxy
add your Proxy
Otherwise check your internet connection
I run your code run with no errors. Try to Invalidate Caches/Restart from: File -> Invalidate Caches/Restart
what worked me is to trying to add it through the project structure dependency window
follow these steps :
1- File -> Project structure -> depencies
click apply then try to sync again and it worked fine for me.

unable to resolve all dependencies in android studio after updating to 3.0.1

I'm getting these errors:
Error:Unable to resolve dependency for ':app#debug/compileClasspath': Could not resolve com.android.support:appcompat-v7:26.1.0.
Error:Unable to resolve dependency for ':app#debugAndroidTest/compileClasspath': Could not resolve com.android.support.test:runner:1.0.1.
Error:Unable to resolve dependency for ':app#debugAndroidTest/compileClasspath': Could not resolve com.android.support.test.espresso:espresso-core:3.0.1.
Error:Unable to resolve dependency for ':app#debugAndroidTest/compileClasspath': Could not resolve com.android.support.test.espresso:espresso-core:3.0.1.
Error:Unable to resolve dependency for ':app#debugUnitTest/compileClasspath': Could not resolve com.android.support:appcompat-v7:26.1.0.
Error:Unable to resolve dependency for ':app#debugUnitTest/compileClasspath': Could not resolve junit:junit:4.12.
Error:Unable to resolve dependency for ':app#release/compileClasspath': Could not resolve com.android.support:appcompat-v7:26.1.0.
Error:Unable to resolve dependency for ':app#release/compileClasspath': Could not resolve com.android.support:appcompat-v7:26.1.0.
Error:Unable to resolve dependency for ':app#releaseUnitTest/compileClasspath': Could not resolve junit:junit:4.12.
Application build.gradle file (project:MyApplication)
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Application build.gradle file (Module:app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.example.hp_pc.myapplication"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
}
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.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-
core:3.0.1'
}
Try this,
Go to your
gradle.properties
write the below code and Sync your project
android.enableAapt2=false
You have to try like this
Delete your build folder in your project root directory
Delete your build folder inside of your project app folder
this both are cache some intermediate files and some debug-gable file so only its happening...
after delete this both folders then rebuild your project it will work properly.
follow this steps
your project root directory looking like that, here delete this highlighted build folder, then go to inside your app folder in this same window
inside app folder have one more build folder its also delete
then rebuild your project.
Here i tried your gradle, here it is:
what you are getting errors is not getting here.
My solution is:
Try to clear your project.
Go to AndroidStudio > File > Invalidate/Restart, it will help.
If nothing works then delete this project create new one.

How to remove all dependencies on android studio?

I have no internet connection on my machine (because of some reasons) and i want to use Android studio(3) on it with no dependency to the internet.
I Created a very simple (default) App but get lots of errors, I changed the gradle to the local and remove/set offline work option but nothing worked.
Errors:
Error:Unable to resolve dependency for ':app#debug/compileClasspath': Could
not resolve com.android.support:appcompat-v7:26.+.
Open File<br><a
href="Unable to resolve dependency for
':app#debug/compileClasspath': Could not resolve
com.android.support:appcompat-v7:26.+.">Show Details</a>
Error:Unable to resolve dependency for
':app#debugUnitTest/compileClasspath': Could not resolve
com.android.support:appcompat-v7:26.+.
Open File<br><a
href="Unable to resolve dependency for
':app#debugUnitTest/compileClasspath': Could not resolve
com.android.support:appcompat-v7:26.+.">Show Details</a>
Error:Unable to resolve dependency for ':app#release/compileClasspath':
Could not resolve com.android.support:appcompat-v7:26.+.
Open File<br><a
href="Unable to resolve dependency for
':app#release/compileClasspath': Could not resolve
com.android.support:appcompat-v7:26.+.">Show Details</a>
Error:Unable to resolve dependency for
':app#releaseUnitTest/compileClasspath': Could not resolve
com.android.support:appcompat-v7:26.+.
Open File<br><a
href="Unable to resolve dependency for
':app#releaseUnitTest/compileClasspath': Could not resolve
com.android.support:appcompat-v7:26.+.">Show Details</a>
build.gradle(app):
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.example.administrator.myapplication"
minSdkVersion 23
targetSdkVersion 26
versionCode 1
versionName "1.0"
}
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.+'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
}
build.gradle(project):
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
For the first time you need to be connected to the internet so that all your dependencies could be fetched. Once that's done, you no longer need the internet.
But if you try building again, Android Studio (gradle) will still try to connect to internet to refresh the dependencies. If you can't be online then you need to tell Android Studio (i.e, gradle) to work offline.
Go to Android Studio's Preferences -> Build, Execution, Deployment -> Offline Work
Turn this option on and gradle will start to work offline.
Note: com.android.support:appcompat-v7:26.+. won't really work here. You need to mention the specific artifact id and not +.

Categories

Resources