0

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

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

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

allprojects {
    repositories {
        jcenter()
    }
}

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

module level gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.0"
    defaultConfig {
        applicationId "in.co.persistent.gamedisappear"
        minSdkVersion 16
        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(dir: 'libs', include: ['*.jar'])
    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.0.1'
    testCompile 'junit:junit:4.12'
}

` The error I getI know this question is asked many times.But I have tried various things like invalidate/restart cache.Also tried restarting android and building new project.Plus added the required dependencies (compile 'com.android.support:appcompat-v7:25.0.1') Nothing works!

Delfin
  • 607
  • 7
  • 18

2 Answers2

1

From the gradle build error screenshot it is clear that problem is Could no resolve junit:junit:4.12
Solution- If you do not need to run unit test cases then you comment following line testCompile 'junit:junit:4.12' and check
but if you need it then please add following codes in module level build.gradle file

repositories {
      jcenter()
      maven { url 'http://repo1.maven.org/maven2' }
    }

EDIT- Reason based on question asked in comment.
Why we get error? Sometimes it might happen that required dependency/used version might not be present/path changed in the repository. For more information you need to understand how gradle works

Shadow Droid
  • 1,696
  • 1
  • 12
  • 26
  • Yes I had done the same and it worked, but why the error they are just dependencies after all. – Delfin Nov 15 '16 at 07:02
0

I changed my dependencies to below in build.gradle and it worked... Though don't know the reason behind this.

  dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:25.0.1'
}
Delfin
  • 607
  • 7
  • 18
  • Maybe you need to add `com.android.support:support-compat:25.0.1` to your previous dependencies. Because in [documentation](https://developer.android.com/topic/libraries/support-library/features.html) it says `This library depends on the v4 Support Library.` – ישו אוהב אותך Nov 15 '16 at 06:58