可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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
回答1:
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.
回答2:
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.
回答3:
- 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
回答4:
I just figured out how to remove this gradle error, follow the following steps.
1- Go to "File".
2- Click on Invalidate Cache/ Restart.
3- Again click on Invalidate Cache / Restart(On dialoge window).
Let the gradle build without any interruption.
Thank You!
Regards, hope this will help.
回答5:
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
回答6:
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')
回答7:
This can happen if you are using both
'com.android.support:appcompat-v7:28.0.0-alpha3'
'com.android.support:support-v4:28.0.0-alpha3'
Remove the line
implementation 'com.android.support:support-v4:28.0.0-alpha3'
from your build.gradle
file and try again.
回答8:
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
回答9:
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