Could not find method testImplementation() for arguments [junit:junit:4.12]
Asked Answered
T

14

27
dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'android.arch.navigation:navigation-fragment:1.0.0-alpha06'
    implementation 'android.arch.navigation:navigation-ui:1.0.0-alpha06'
    implementation 'android.arch.navigation:navigation-fragment-ktx:1.0.0-alpha06'
    implementation 'android.arch.navigation:navigation-ui-ktx:1.0.0-alpha06'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    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'
}

This is my build.gradle file and I tried many ways but I can't fix this, when I start Android Studio and gradle starts build the project Android Studio throw this error how can I fix it?( I am new in Android)

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

Tuckerbag answered 1/10, 2018 at 11:27 Comment(1)
I encountered the same issue. Have you found a solution for that yet?Abandon
G
45

It is Google's fault.You need to use your countries letters.So use 'İ' instead 'I'.

testİmplementation  'junit:junit:4.12'
androidTestİmplementation  'androidx.test:runner:1.1.1'
androidTestİmplementation  'androidx.test.espresso:espresso-core:3.1.1'
Gentile answered 7/2, 2019 at 13:37 Comment(5)
This answer should be accepted. Thanks for sharing. This problem made me mad.Plasma
Thanks. Works like a charm. Apparently, Turkish İ problem. Everyone gets excited about AI nowadays, but humanity still hasn't solved encoding issues :(Automotive
Does this not make your project incompatible with any other developer around the world? I can't believe that this is the only solution. Also I can't believe we're still having this Java upper/lowercase issue. I use en_us everywhere but obviously I should not have to.Militant
I can't believe we still have this issue in 2020 :/Nobie
I found this line works, if it is put inside the dependencies block inside the build.gradle file like this: dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' testImplementation 'org.springframework.boot:spring-boot-starter-test' }Entail
A
8

Well, I know that's not the nicest solution for this but this is what worked. I simply commented these lines out:

//testImplementation "junit:junit:4.12"
//testImplementation "org.robolectric:robolectric:3.1.2"

Hope it helps =)

Abandon answered 19/10, 2018 at 21:37 Comment(0)
C
3

Even though the documentation says

In your app's top-level build.gradle file, specify the following libraries as dependencies:

... I haven't found an example that works that way.

In fact, this GoogleSamples Android Unit Test example specifies:

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

So, move that line to the module build.gradle, not the top-level build.gradle

Cartography answered 18/1, 2019 at 20:56 Comment(0)
H
2

Can you provide your Gradle version and complete build.gradle ?

Possible issues:

  1. You are missing a plugin definition apply plugin: 'com.android.application'

or any plugin that implicitly uses the Java Plugin ? That's where the testImplementation comes from.

  1. You're using < Gradle 3.x (testImplementation is not available in the previous releases)

Ensure you are using Gradle 3.x+ and that the top level build.gradle has Android Gradle Plugin 3.x+ defined in it : https://developer.android.com/studio/releases/gradle-plugin#updating-plugin

Hypogynous answered 25/10, 2018 at 22:10 Comment(0)
H
1

100% working.

Replace testİmplementation with testImplementation.(İ with I or i)

in your dependencies

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'android.arch.navigation:navigation-fragment:1.0.0-alpha06'
implementation 'android.arch.navigation:navigation-ui:1.0.0-alpha06'
implementation 'android.arch.navigation:navigation-fragment-ktx:1.0.0-alpha06'
implementation 'android.arch.navigation:navigation-ui-ktx:1.0.0-alpha06'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
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'

}

Harmonyharmotome answered 30/5, 2020 at 10:4 Comment(0)
T
0

Syncing only active variant You can disable this experimental feature from File → Settings → Experimental → Gradle → Only sync the active variant

Thirtytwo answered 19/6, 2019 at 15:10 Comment(0)
V
0

build.gradle file in replace :

dependencies {
    classpath 'com.android.tools.build:gradle:3.0.1'
}
Vespers answered 29/6, 2019 at 17:23 Comment(0)
D
0

Before

I didn't know implementation needs to be within dependencies in build.gradle

// build.gradle
dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
}

implementation 'org.springframework.boot:spring-boot-starter-actuator'
gs-spring-boot/initial [master●] » ./gradlew bootRun

FAILURE: Build failed with an exception.

* Where:
Build file '/home/geoff/work/androidStuff/gs-spring-boot/initial/build.gradle' line: 27

* What went wrong:
A problem occurred evaluating root project 'spring-boot'.
> Could not find method implementation() for arguments [org.springframework.boot:spring-boot-starter-actuator] on root project 'spring-boot' of type org.gradle.api.Project.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1s

After

// build.gradle
dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
    implementation 'org.springframework.boot:spring-boot-starter-actuator'
}

gs-spring-boot/initial [master●] » ./gradlew bootRun

> Task :bootRun

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.2.2.RELEASE)
Doleful answered 1/3, 2020 at 22:54 Comment(0)
V
0

The error is caused by gradle daemon start with user's locale (TR). Starting gradle daemon with EN locale will solve the problem. In gradle.properties file set user language by updating the following line

org.gradle.jvmargs=-Xmx1536m -Duser.language=en
Vite answered 14/3, 2022 at 12:1 Comment(0)
H
0

I solved this problem as follows, maybe it will work for you.

before

androidtestImplementation('androidx.test.espresso:espresso-core:3.4.0'

after

testImplementation('androidx.test.espresso:espresso-core:3.4.0'

before

andoidtestImplementation 'junit:junit:4.13.2'

after

testImplementation 'junit:junit:4.13.2'
Hagridden answered 5/11, 2022 at 1:3 Comment(0)
S
0

Maybe you forgot to apply jvm-related plug-ins. The most basic is like the following:

apply  plugin: 'java'

or apply other jvm-related plugin

Shame answered 13/1 at 0:47 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Hutchinson
T
-1

Add Configurations -->template-->gradle--> Define gradle project field gradle project.

enter image description here

Thirtytwo answered 12/2, 2019 at 16:2 Comment(1)
Please add some explanation to that image - why do you think that this solves the problem?Submerse
S
-1

One of these 3 methods will work

1) Project Structure > Project > and change

Gradle Version: 4.6
Android Plugin Version: 3.2.1

2) change it testImplementation --> testİmplementation

 testİmplementation 'junit:junit:4.12'
    androidTestİmplementation 'com.android.support.test:runner:1.0.2'
    androidTestİmplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

3)

    //testImplementation 'junit:junit:4.12'

    //androidTestImplementation 'androidx.test:runner:1.1.2-alpha02'

    //androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0-alpha02'
    

Clean --> Rebuild

or

File --> Sync Project with Gradle Files

Skardol answered 12/3, 2019 at 10:5 Comment(0)
F
-1

Make sure you pay attention to proper Camel Case. TestImplementation not testimplementation. Unless you follow that convention you will receive an error and it will drive you crazy

Florencio answered 1/3, 2020 at 15:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.