无法在Android工作室中运行hello world

时间:2016-12-23 10:21:48

标签: android android-studio android-studio-2.0

我安装了一个Android工作室并创建了一个新的Hello World应用程序。我尝试使用我设置的模拟器运行,但是gradle sync给出了错误,如下所示。我是android开发的新手。任何帮助都会很棒。

我的build.gradle是:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.3'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        mavenCentral()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

我的build.gradle(模块应用)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "com.example.rohit_mourya.helloworld"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.1.0'
    androidTestCompile 'junit:junit:4.12'
    compile 'javax.inject:javax.inject:1'
    compile 'javax.annotation:jsr250-api:1.0-20050927.133100'
}

当我尝试运行我的应用程序时,它会给我以下错误:

C:\Users\rohit_mourya\AndroidStudioProjects\HelloWorld\app\build.gradle
    Error:Error:line (27)Failed to resolve: junit:junit:4.12
<a href="openFile:C:/Users/rohit_mourya/AndroidStudioProjects/HelloWorld/app/build.gradle">Show in File</a><br><a href="open.dependency.in.project.structure">Show in Project Structure dialog</a>
    Error:Error:line (28)Failed to resolve: javax.inject:javax.inject:1
<a href="openFile:C:/Users/rohit_mourya/AndroidStudioProjects/HelloWorld/app/build.gradle">Show in File</a><br><a href="open.dependency.in.project.structure">Show in Project Structure dialog</a>
    Error:Error:Failed to resolve: javax.annotation:javax.annotation-api:1.2
<a href="openFile:C:/Users/rohit_mourya/AndroidStudioProjects/HelloWorld/app/build.gradle">Open File</a><br><a href="open.dependency.in.project.structure">Show in Project Structure dialog</a>
    Error:Error:Failed to resolve: com.google.code.findbugs:jsr305:2.0.1
<a href="openFile:C:/Users/rohit_mourya/AndroidStudioProjects/HelloWorld/app/build.gradle">Open File</a><br><a href="open.dependency.in.project.structure">Show in Project Structure dialog</a>
    Error:Error:Failed to resolve: org.hamcrest:hamcrest-library:1.3
<a href="openFile:C:/Users/rohit_mourya/AndroidStudioProjects/HelloWorld/app/build.gradle">Open File</a><br><a href="open.dependency.in.project.structure">Show in Project Structure dialog</a>
    Error:Error:Failed to resolve: org.hamcrest:hamcrest-integration:1.3
<a href="openFile:C:/Users/rohit_mourya/AndroidStudioProjects/HelloWorld/app/build.gradle">Open File</a><br><a href="open.dependency.in.project.structure">Show in Project Structure dialog</a>
    Error:Error:line (29)Failed to resolve: javax.annotation:jsr250-api:1.0-20050927.133100
<a href="openFile:C:/Users/rohit_mourya/AndroidStudioProjects/HelloWorld/app/build.gradle">Show in File</a><br><a href="open.dependency.in.project.structure">Show in Project Structure dialog</a>
    Error:Error:Failed to resolve: com.squareup:javawriter:2.1.1
<a href="openFile:C:/Users/rohit_mourya/AndroidStudioProjects/HelloWorld/app/build.gradle">Open File</a><br><a href="open.dependency.in.project.structure">Show in Project Structure dialog</a>

虽然我已在项目的模块设置中配置了这些依赖项。提前谢谢

1 个答案:

答案 0 :(得分:1)

在build.gradle中使用它

    apply plugin: 'com.android.application'

    android {
        compileSdkVersion 25
        buildToolsVersion "25.0.2"
        sourceSets.main {

            jniLibs.srcDir 'src/main/libs'
            //hide the ‘jni’ folder so that the automatic gradle build doesn’t try to run

            //it’s own ndk-build process

            jni.srcDirs = [];
        }
        defaultConfig {
            applicationId 'com.example.rohit_mourya.helloworld'
            minSdkVersion 15
            targetSdkVersion 25
            versionCode 1
            versionName "1.0"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }

        productFlavors {
        }
    }

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile 'com.android.support:appcompat-v7:25.1.0'
    }