Unable to resolve dependency for ':app#debug/compileClasspath': Could not resolve - android

Newly installed Android studio 3.1.3 is giving strange dependencies error when making a new project and compiling for very first time.
A similar question that didn't help resolve the problem.
Event Logs:
Unable to resolve dependency for ':app#debug/compileClasspath': Could not resolve com.android.support:appcompat-v7:28.0.0-alpha3.
Open File
Show Details
Unable to resolve dependency for ':app#debug/compileClasspath': Could not resolve com.android.support.constraint:constraint-layout:1.1.2.
Open File
Show Details
Unable to resolve dependency for ':app#debugAndroidTest/compileClasspath': Could not resolve com.android.support:appcompat-v7:28.0.0-alpha3.
Open File
Show Details
Unable to resolve dependency for ':app#debugAndroidTest/compileClasspath': Could not resolve com.android.support.constraint:constraint-layout:1.1.2.
Open File
Show Details
Unable to resolve dependency for ':app#debugUnitTest/compileClasspath': Could not resolve com.android.support:appcompat-v7:28.0.0-alpha3.
Open File
Show Details
Unable to resolve dependency for ':app#debugUnitTest/compileClasspath': Could not resolve com.android.support.constraint:constraint-layout:1.1.2.
Open File
Show Details
Unable to resolve dependency for ':app#release/compileClasspath': Could not resolve com.android.support:appcompat-v7:28.0.0-alpha3.
Open File
Show Details
Unable to resolve dependency for ':app#release/compileClasspath': Could not resolve com.android.support.constraint:constraint-layout:1.1.2.
Open File
Show Details
Unable to resolve dependency for ':app#releaseUnitTest/compileClasspath': Could not resolve com.android.support:appcompat-v7:28.0.0-alpha3.
Open File
Show Details
Unable to resolve dependency for ':app#releaseUnitTest/compileClasspath': Could not resolve com.android.support.constraint:constraint-layout:1.1.2.
Open File
Show Details
ScreenShot:
this problem happened to me several times and forcing https or http didn't resolve it either

You might be importing Application instead of Module. Well you can change it in module's gradle also.
Change
apply plugin: 'com.android.application'
to
apply plugin: 'com.android.library'
You also need to remove applicationId from the gradle.

I just figured out how to remove this gradle error, follow the following steps.
Go to "File".
Click on Invalidate Cache/ Restart.
Again click on Invalidate Cache / Restart(On dialoge window).
Let the gradle build without any interruption.
Thank You!
Regards, hope this will help.

I think the problems comes from the following:
The internet connection with u was unavailable so Android Studio asked you to enable the "offline work" and you just enabled it
To fix this:
File
Settings
Build, Execution, Deployment
Gradle
Uncheck offline work
why might unchecking the offline work solves the problem, because in the Gradle sometimes some dependencies need to update (the ones containing '+'), so internet connection is needed.

Try "File"->"Invalidate Caches / Restart ..."
Try to clean up your .gradle and .idea directory under your project root directory.
Try to add Google Maven repository and sync project
buildscript {
repositories {
jcenter()
google()
maven {
url "https://maven.google.com"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
}
}
allprojects {
repositories {
google()
jcenter()
maven {
url "https://maven.google.com"
}
}
}
If you are using Android Gradle Plugin 3.1.3, you should be sure that your gradle wrapper version is 4.4. Under the root directory of your project, find gradle-wrapper.properties and modify it as below.
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

I know its very late but I think it may help someone in resolving his issue.
In my case It was occurring because compileSdkVersion and targetSdkVersion was set to 29 while when I check my SDK Manager, It was showing that package is partially installed. Whereas SDK version 28 was completely installed. I changed my compileSdkVersion and targetSdkVersion to 28 along with support libraries.
Earlier:
compileSdkVersion 29
targetSdkVersion 29
implementation 'com.android.support:appcompat-v7:29.+'
implementation 'com.android.support:design:29.+'
After Modification:
compileSdkVersion 28
targetSdkVersion 28
implementation 'com.android.support:appcompat-v7:28.+'
implementation 'com.android.support:design:28.+'
It worked like a charm after applying these changes.

I had this issue with offline mode enable. I disabled offline mode and synced.
Open the Preferences, by clicking File > Settings.
In the left pane, click Build, Execution, Deployment > Gradle.
Uncheck the Offline work.
Apply changes and sync project again.

#shizhen answer not worked my case.
Spend more than one day and finally got a working solution.
I Was in office environment so by trying different methods my gradle file get corrupted.
So I removed all proxy and port info form from following file and things got worked.
User -> .gradle -> gradle.properties
Additionally I enabled "Auto-detect proxy settings" under Android studio -> preferences -> HTTP proxy for network and studio will auto detect network config.
Special credit

I'm just sharing this answer because I had similar problem.
In the end, error was caused because I inadvertently changed the fileTree. In my case, I fixed by changing:
// implementation or compile
implementation fileTree(include: ['*.jar'])
to
// implementation or compile
implementation fileTree(include: ['*.jar'], dir: 'libs')

As #Ebin Joy said, If your gradle file get corrupted then there is one simple solution for that. Manually give the proxy details like shown in image. then you're good to go. This solution only works if you using any closed networks like office network etc.

I have resolved this Gradle caching issue like below.
In case anyone using MacBook then below is the steps I used to resolve this issue.
There is a hidden Gradle folder. By using the below command we can open the hidden Gradle folder and remove the file called gradle.properties
shortcut (⌘ + shift + G) then enter this inside popup window ~/.gradle/ press enter
file to be removed -> gradle.properties
Then go back to the android studio and sync your project with Gradle files.

One possibility I have not seen mentioned. If the project you are importing uses android product flavors, you may have a mistake in your missingDimenstionStrategy.
In your :app build.gradle (the one code that is failing to resolve the dependency), ensure you have correctly set the specific flavor of the product that you are depending on. This allows all your later dependency code (e..g implementation, api, etc) to know which precise build it depends on
defaultConfig {
...<snip unrelated>...
// Ensure you specify the flavor you depend on!!
// If dep has multiple flavor dimensions, you need to specify them all
missingDimensionStrategy 'classpath', 'gms17'
}

FOR ANYONE GETTING THIS WHEN TRYING TO IMPORT THEIR OWN CREATED LIBRARIES
I have been playing with Kotlin Multiplatform libraries and was trying to publish my libraries using jitpack and then pulling them into other projects. I'm new to most of this and didn't know I needed to add publishLibraryVariants to my android configuration in gradle. I followed other tutorials that didn't require this, so I'm not sure what it is about Kotlin MPP that makes you need it. This is the code though. You could likely publish other variants that met your needs, but these appear to be the standard requirements to build with a basic project. The () after android aren't absolutely necessary, but the default script comes with them so I left it. The code is essentially the same for Kotlin or Groovy DSL.
In the gradle script for the library being published
kotlin {
android() {
publishLibraryVariants("release", "debug")
…
}
…
}

Below solution may help to someone.
I faced this issue, when I use implementation project(':my_project_other_modules') in the new module.
I discussed with my teammates and I finally I got the solution from one of the person,
I have to use flavorDimensions & productFlavors. Because the app/build.gradle used flavorDimensions & productFlavors. When I add these in new module, the error didn't occur.

In my case, there was a typo in the code. Therefore beware to check that first before trying anything else.

I was unable to find the root cause of the issue but got a workaround. I started by setting my the java home variable as such.
vi ~/.bash_profile (this is for macs only. bash profiles are different on linux)
type the letter i for insert and then set the JAVA_HOME variable as such
export JAVA_HOME=/Applications/Android\Studio.app/Contents/jre/jdk/Contents/Home/
quit the vi editor with esc then type :wq
Restart the computer
Voila! Your android studio projects should build without any qualms

In my case :
When I setup AS, my windows was configured with proxy.
Later, I disconnect proxy and disable proxy in AS settings, But, in file
.gradle\gradle.properties - proxy - present
Just, in text editor clear proxy settings from this file

I had your issue, i fixed it . this error comes when your target api level is not completely downloaded . you have two ways: go to your SDK menu and download all of the android 9 components or the better way is go to your build.gradle(Module app) and change it like this:But remember, before applying these changes, make sure you have fully downloaded api lvl 8

In my case I used google play services...I increase library service it solved
implementation 'com.google.android.gms:play-services-auth:16.0.0'
Google play service must be same in library and app modules
Reference

Question still relevant as of Android Studio 3.5.2 for Windows.
In my specific use case, I was trying to add Gander (https://github.com/Ashok-Varma/Gander) to my list of dependencies when I keep getting this particular headache.
It turns out that I have yet to get JCenter Certificate approved in my cacerts file. I'm going through a company firewall and i had to do this with dependencies that I attempt to import. Thus, to do so:
Ensure that your Android Studio does not need to go through any
proxy.
Export the certificate where you get your dependency (usually
just JCenter)
Add the certificate to your cacerts file:
keytool -import -alias [your-certificate-name] -keystore 'C:\Program Files\Java\jdk[version]\jre\lib\security\cacerts' -file [absolute\path\to\your\certificate].cer
Restart Android Studio
Try syncing again.
Answer is based on this one: https://stackoverflow.com/a/26183328/4972380

If you have ever used a proxy, VPN, etc(or may not, I am not sure).....Then the solution below may help you...I don't know why (and if anybody can tell me why, I will appreciate that), but it works, pefectly. Have a try when you totally feel desperate about that issue.
Come to your project, and open gradle-wrapper.properties or gradle.properties, comment out these codes about proxy:
#systemProp.http.nonProxyHosts=118.89.144.241|47.112.105.125
#systemProp.http.proxyHost=127.0.0.1
#systemProp.http.proxyPort=1081
#systemProp.https.nonProxyHosts=118.89.144.241|47.112.105.125
#systemProp.https.proxyHost=127.0.0.1
#systemProp.https.proxyPort=1081
Then, it might work.
PS: I met this problem when I try to use dataBinding library, and when I added the code
buildFeatures {
dataBinding true
}
into gradle as the guide told me and Syns the project, I got such an error:"Unable to resolve dependency for ':app#debug/compileClasspath': Could not resolve ......". Finally I did what I described above, and I successed. What I experience may give you a hint, so I post the solution here and hope it might help.

Try to add type of configuration in dependency line. For example:
implementation project(path: ':some_module', **configuration: 'default'**)`

People answering about offline work is active is right. But it was located in different place in my case. To find it in the top bar menu select
View/Tool Windows/ Graddle
Toogle the offline button if active. It is a small rectangle with two centered slashes
In adittion you can clic the help menu in the top bar menu and write "gradle" and it suggest the locations.

It's neither a cache problem nor an application versus library issue. This is a certificate problem. If you try to run your project instead of gradle build, you'll see it struggles to download certificates. To solve this issue, just add the certificates that google changes each other month.
Here is my command line, please edit it accordingly with your own paths. The password to keystore is changeit.
keytool -import -alias google_10 -keystore /Library/Java/JavaVirtualMachines/adoptopenjdk-9.jdk/Contents/Home/lib/security/cacerts -file ~/Desktop/GTS\ CA\ 1C3.cer

Related

Kotlin Not Configured : Android studio

I am able to run the project successfully. but unable to resolve this issue which is showing "kotlin Not Configured". I tried every solution for that but its always showing in the currently active file.
Please help.
Delete the .gradle and .idea file and restart the project. This seem to work for me.
Click on Tools -> Kotlin -> Configure Kotlin in Project
then choose the configurator, any one from:
Java with Gradle
Android with Gradle
try to upgrade the kotlin version in build.gradle file
ext.kotlin_version = '1.3.72'
also in the build.gradle app module file make sure implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
in the dependencies section ,
if you see at any time update the gradle option , do so
Furthermore, if you find a line
implementation "androidx.core:core-ktx:+"
in your build.gradle, you may see the warning message:
Avoid using + in version numbers, can lead to unpredictable and anrepeatable builds.
Click on "Replace with specific version", then the current installed version replaces the "+". (For example, "1.3.2")
In my case the "kotlin not configured" message and a lot of "errors" in the kotlin file disappeared.
Simply hitting "Sync Project with Gradle Files" did the job for me.
In my case, it can fix by keep the version of kotlin-gradle-plugin up to date. Check the version here: https://kotlinlang.org/docs/gradle.html#plugin-and-versions
File for configuration Location
Project -> build.gradle
//example: update this dependence:
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.10"
}
I faced the same issue after updating to latest android electric eel. So those of you who had a kotlin project which working fine and after update failed to sync gradle files or build projects with error
"Kotlin not configured".
I think this answer might help. I'm not sure if this is the right way to do but this was a life saver for me since I was working with an old project with older dependencies and kotlin version
Just click on the gradle offline toggle and try syncing the project and building it in offline mode. That's it !!!
No need to change any version or other changes. I hope this helps and save your time.

Android Studio: I am receiving an error when trying to implement OKHTTP3 into the build.gradle

I'm getting the following error in android studio when I add OKHTTP3 to the app level build.gradle and attempt to sync the build.gradle:
ERROR: Unable to resolve dependency for ':app#debug/compileClasspath': Could not resolve com.squareup.okhttp3:okhttp:4.4.0.
My code for implementing the dependency looks like this:
dependencies {
...
implementation 'com.squareup.okhttp3:okhttp:4.4.0'
...
}
This is the latest version of OKHTTP3 that I took from https://search.maven.org/artifact/com.squareup.okhttp3/okhttp/4.4.0/jar so this should work fine.
In the project level build.gradle I have jcenter() included within the repositories at both the buildscript and allprojects levels so I am unsure why I am receiving the above error as, from other stackoverflow questions, I can see that jcenter() is the maven central repository which this library comes from.
I have looked at all other stackoverflow questions on this matter but none of their solutions are working for me and I am receiving the same error regardless of any attempts.
I appreciate any suggestion anyone may have. Thank you in advance.
For anyone who runs into the above problem. This is what worked for me:
I did some research into the new Android Studio version as I figured out that I had done everything else correctly and the error was most likely to do with the recent Android Studio update. To fix the above solution, I toggled the build.gradle offline mode to off which resolved the entire problem.
To perform the same steps, this is taken from Android Studio's 3.6 blog post:
New location to toggle Gradle's offline mode To enable or disable Gradle's offline mode, first select View > Tool Windows > Gradle from the menu bar. Then, near the top of the Gradle window, click Toggle Offline Mode Gradle offline button in the Gradle panel..
This post can be found here https://developer.android.com/studio/preview/features#gradle-offline-ui

Gradle unable to resolve dependency

I am trying to develop an Android app using Pubnub's realtime API facilities. As per the documentation we need to add a gradle dependency line below within the build.gradle file:
compile 'com.pubnub:pubnub:4.1.0'
Strangely enough, Gradle is not able to satisfy this dependency. My repository configuration within the Gradle build script is as follows:
repositories {
jcenter()
}
I tried adding mavenCentral() instead of jcenter() but still no luck. Any help would be greatly appreciated.
Please note: I am adding only the relevant sections of the build.gradle file since I do not have the authority to paste the whole build script.
Also, this is my first time with the Android ecosystem - hence any help in pointing out obvious newbie errors would be great.
Did you right click on app, go to Open module settings, click on the Dependencies tab, click on the +, choose add module dependency and then ok?

Could not find junit:junit:4.12 in Android Studio

Im new to testing in android studio, im was trying to setup the gradle for adding dependencies for Junit4.
However, the gradle console informs me "Could not find junit:junit:4.12."
It seems like gradle search the dependency in local folder instead of via internet, please inform how I should setup the gradle file for adding the dependecy for Junit.
You need internet connection -at least first time- to build project first time correctly (i really don't know why) !!!
so, to avoid that you may try download JUnit (required library) from here and add it manually to your application into ~[YourAppFolder]\app\libs
then rebuild your app.
Try commenting out //testCompile 'junit:junit:4.12'.
This will solve the problem if you don't have internet access as you run app after installing Android Studio. As soon as you have internet access, uncomment and run your app, there after everything remains fixed won't be needing internet access again.
I'm sure it works. Not sure why, anyway.
You have in your build.gradle:
buildscript {
repositories {
mavenCentral()
}
}
The above will fetch the plugin com.android.application. That's all it will do.
You should have the below to fetch all your dependencies:
repositories {
mavenCentral()
}

Can't add LocalBroadcastManager to project in Android Studio

I think I've tried everything now...
I've been all over stack overflow, I've even consulted the android doc
Most of the posts here show how to add the .jar file in Eclipse "android tools -> add support library" or something
So I've tried to do it how the doc tells me, by going to build.gradle, and adding compile 'com.android.support:support-v4:19.0.0' to the dependencies
but even if I add it, and rebuild the project, I still can't import android.support.v4.content.LocalBroadcastManager... it doesn't even know what android.support is...
So is there anyone who can help me with this? the issue is getting very annoying, and it's slowed me down by hours...
Edit: I have updated the Android SDK, and made sure that the library exists in the sdk folder, so I know it's there... I just can't make android studio add it for some reason...
Edit 2: Only by navigating to the exact file path, manually, and then copying said path I was able to access the file... Still, I'd very much like to know what I can do to make this a more painless process...
Make sure your library got added successfully.
Check the following things.
1.Your build.gradle should be like
dependencies {
compile 'com.android.support:support-v4:19.0.+'
}
2.File > Project Structure > Modules >Dependency Tab
There should not be any red mark in dialog showing error if they are fix them.
3.Check your Module_Name.iml file
It should have this entry in last section
<orderEntry type="library" exported="" name="support-v4-19.0.0" level="project"/>
If its there with no entry close you studio delete .iml file and open studio again wait for gradle sync to be complete.You .iml file will be created again check for entry.
If every thing is fine do sync Your project with gradle again using this lovely tiny gradle button in toolbar.
Try adding one of those dependencies to your app level build.gradle :
AndroidX
implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0'
Support Library
implementation 'com.android.support:localbroadcastmanager:28.0.0'
Then sync project with Gradle files.
After lot of searching and R&D i found some solution. This is working for me i hope this is helping you.
implementation 'androidx.legacy:legacy-support-core-utils:1.0.0'
If you not use Androidx please add this line
implementation 'android.legacy:legacy-support-core-utils:1.0.0'

Categories

Resources