1
votes

After applying the update of Gradle to version 3.3.0 in Android Studio an error occurred while syncing Gradle regarding the junit 4.12.

The error is : Could not find method testImplementation() for arguments [junit:junit:4.12] on object of type `org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

There was no error before update. The error occurs when I add the last three dependencies (junit, test runner, test espresso) to the gradle file. I've look at the previous questions but couldn't find a solution yet. Here is my gradle files:

Project Gradle File

buildscript {

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

allprojects {
    repositories {
        google()
        jcenter()
        maven { url "https://jitpack.io" }
    }
}

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

App Gradle File

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.hhs.haberler"
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
    }
    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:28.0.0'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.android.support:support-v4:28.0.0'
    implementation 'com.android.support:cardview-v7:28.0.0'
    implementation 'com.android.support:recyclerview-v7:28.0.0'
    implementation 'com.android.support:customtabs:28.0.0'
    implementation 'com.android.support:preference-v7:28.0.0'

    implementation "android.arch.lifecycle:extensions:1.1.1"
    implementation 'com.android.support:support-vector-drawable:28.0.0'
    annotationProcessor "android.arch.lifecycle:compiler:1.1.1"
    implementation "android.arch.persistence.room:runtime:1.1.1"
    annotationProcessor "android.arch.persistence.room:compiler:1.1.1"

    implementation 'com.google.code.gson:gson:2.8.5'
    implementation 'com.squareup.retrofit2:retrofit:2.4.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
    implementation 'com.squareup.picasso:picasso:2.71828'
    implementation 'com.github.curioustechizen.android-ago:library:1.4.0'
    implementation 'de.hdodenhof:circleimageview:2.2.0'
    implementation 'com.github.bumptech.glide:glide:4.8.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
    implementation 'com.github.chrisbanes:PhotoView:2.1.4'
    implementation 'gr.pantrif:easy-android-splash-screen:0.0.1'

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso- core:3.0.2'
}
1

1 Answers

1
votes

There is a bug for Android Studio. I guess your PC's language is Turkish. If you write "androidTestApi" include "androidTestImplementation" to your gradle file, Android Studio gives WARNING like this:

WARNING: Configuration 'androidTestApi' is obsolete and has been replaced with 'androidTestİmplementation'. It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html Affected Modules: app

Pay attention to the strong text at Warning. There is uppercase İ inside androidTestİmplementation, because of your PC's language is Turkish and Turkish have uppercase İ in their alphabet.

So if you replace androidTestImplementation with androidTestİmplementation, problem will be solved.

Or set your PC language as English :)