尝试“hello world”时,Android studio 3问题

时间:2017-12-04 10:48:48

标签: android android-studio-3.0

我是Android开发的新手。希望有人能帮帮我..

我正在尝试使用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。   要求:       项目:app   无法解析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+中我应该使用存储库部分和依赖项部分修改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。   要求:       项目:app   无法解析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]失败:连接被拒绝:连接   连接被拒绝:连接

我正在使用代理连接,但网络应该没问题。

如果有人能给我一些指导,我很感激。感谢。

Zong

1 个答案:

答案 0 :(得分: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'

来自app / build.gradle文件的这一行然后清理项目 - >重建 这可能会有所帮助

相关问题