【发布时间】:2018-05-17 19:33:03
【问题描述】:
我是安卓开发新手。希望有人能帮帮我..
我正在尝试 Android Studio 3.0.1,并尝试将项目创建为“Hello world”。所有步骤都按照默认设置。
但是在构建项目时失败了。错误消息说:
无法解析 ':app@debug/compileClasspath' 的依赖关系:无法解析 com.android.support:appcompat-v7:26.1.0。
无法解析 com.android.support:appcompat-v7:26.1.0。 要求: 项目:应用程序 无法解析 com.android.support:appcompat-v7:26.1.0。 无法获取资源“https://dl.google.com/dl/android/maven2/com/android/support/appcompat-v7/26.1.0/appcompat-v7-26.1.0.pom”。 无法获取“https://dl.google.com/dl/android/maven2/com/android/support/appcompat-v7/26.1.0/appcompat-v7-26.1.0.pom”。 连接到 dl.google.com:443 [dl.google.com/127.0.1.4] 失败:连接被拒绝:连接 连接被拒绝:连接
我在 google 和 stackoverflow 中进行了搜索。有一些提示说,在 Android Studio 3.0+ 中,我应该使用 repositories 部分和 dependencies 部分修改 build.gradle 文件:https://developer.android.com/topic/libraries/support-library/setup.html
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
我做到了。
这是我的顶级 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.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
这是我的 app/build.gradle 文件:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.example.android.happybirthday"
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'
implementation 'com.android.support:design:26.1.0'
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'
compile 'com.android.support:appcompat-v7:26.1.0'
}
然后我收到错误消息:
无法解析 ':app@debug/compileClasspath' 的依赖关系:无法解析 com.android.support:appcompat-v7:26.1.0。
无法解析 com.android.support:appcompat-v7:26.1.0。 要求: 项目:应用程序 无法解析 com.android.support:appcompat-v7:26.1.0。 无法获取资源“https://jcenter.bintray.com/com/android/support/appcompat-v7/26.1.0/appcompat-v7-26.1.0.pom”。 无法获取“https://jcenter.bintray.com/com/android/support/appcompat-v7/26.1.0/appcompat-v7-26.1.0.pom”。 连接到 jcenter.bintray.com:443 [jcenter.bintray.com/127.0.1.2] 失败:连接被拒绝:连接 连接被拒绝:连接
我正在使用代理连接,但网络应该没问题。
如果有人能给我一些指导,我将不胜感激。谢谢。
宗
【问题讨论】:
-
更新 SDK 工具
-
怎么做?
-
工具--->android--->sdk管理器
-
在那里检查,我已经安装了 26/27
标签: android android-studio-3.0