1

I installed a Android studio and created a new Hello World application. I tried to run using the emulator which I've set up but gradle sync gives me error which is below. I'm new to android development. Any help would be great.

My build.gradle is:

// 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
}

My build.gradle for (Module app)

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'
}

And when I try to run my application it gives me following error:

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>

Though I've configured these dependencies in Module settings of my project. Thank you in advance

Rohit Mourya
  • 285
  • 5
  • 17
  • http://stackoverflow.com/questions/32519219/error23-17-failed-to-resolve-junitjunit4-12 – IntelliJ Amiya Dec 23 '16 at 10:23
  • Thanks for your reply: `repositories{ maven { url 'http://repo1.maven.org/maven2' }` but I;m getting this error: `Gradle sync failed: Could not find jsr250-api.jar (javax.annotation:jsr250-api:1.0-20050927.133100). Searched in the following locations: http://repo1.maven.org/maven2/javax/annotation/jsr250-api/1.0-20050927.133100/jsr250-api-1.0-20050927.133100.jar Consult IDE log for more details (Help | Show Log)` – Rohit Mourya Dec 23 '16 at 10:27
  • call `testCompile 'junit:junit:4.12'` – IntelliJ Amiya Dec 23 '16 at 10:31

1 Answers1

2

Use this in your 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'
    }
Kush Patel
  • 1,228
  • 1
  • 13
  • 34
  • Thanks buddy, That error is gone but Now when I run my application it gives me following error: `Error:Execution failed for task ':app:ndkBuild'. > A problem occurred starting process 'command 'C:\Users\rohit_mourya\AppData\Local\Android\android-ndk\ndk-build.cmd''` I guess the path which you gave me `commandLine "C:\\Users\\rohit_mourya\\AppData\\Local\\Android\\android-ndk\\ndk-build.cmd", '-C', file('src/main').absolutePath` is wrong – Rohit Mourya Dec 23 '16 at 10:33
  • Thanks buddy. It worked finally. Can you tell me what was wrong in my file and the solution which you gave me. And if I'm creating new application then am I supposed to copy that file contents again (the one which you gave me)? – Rohit Mourya Dec 23 '16 at 10:42
  • @RohitMourya Yes you can copy this file content to other simple android application. Just change the value of applicationId 'your package name'. And if this answer is useful not forget to upvote it. – Kush Patel Dec 23 '16 at 10:50
  • Ok. Thanks. And my reputation is below 15 so can't upvote answer – Rohit Mourya Dec 23 '16 at 10:55
  • @RohitMourya okay np. But i think you can accept the answer. – Kush Patel Dec 23 '16 at 10:58