'Could not find method testImplementation() for arguments [junit:junit:4.12]
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.
Solution 1:[1]
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'
Solution 2:[2]
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 =)
Solution 3:[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
Solution 4:[4]
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'
}
Solution 5:[5]
Can you provide your Gradle version and complete build.gradle ?
Possible issues:
- 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.
- 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
Solution 6:[6]
Syncing only active variant You can disable this experimental feature from File ? Settings ? Experimental ? Gradle ? Only sync the active variant
Solution 7:[7]
build.gradle file in replace :
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
}
Solution 8:[8]
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)
Solution 9:[9]
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
Solution 10:[10]
Add Configurations -->template-->gradle--> Define gradle project field gradle project.

Solution 11:[11]
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
Solution 12:[12]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
