Reputation: 305
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.
Upvotes: 27
Views: 42996
Reputation: 430
Solution:
In my case well I was getting same error and solution is below.
initially it was
testCompile 'junit:junit:4.12'
I changed it to
testimplementation 'junit:junit:4.12'
then it was giving me that error so problem was I needed to use "testImplementation" not "testimplementation".
Final Solution
testImplementation 'junit:junit:4.12'
Let me know if you still face the same issue.
Thank you!!!
Upvotes: 0
Reputation: 1
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
Upvotes: 0
Reputation: 1
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'
Upvotes: 0
Reputation: 39
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
Upvotes: 0
Reputation: 414
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'
}
Upvotes: 1
Reputation: 946
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
// 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)
Upvotes: 0
Reputation: 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
Upvotes: -1
Reputation: 116
build.gradle file in replace :
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
}
Upvotes: 0
Reputation: 1
Syncing only active variant You can disable this experimental feature from File → Settings → Experimental → Gradle → Only sync the active variant
Upvotes: 0
Reputation: 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
Upvotes: -1
Reputation: 636
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'
Upvotes: 46
Reputation: 1
Add Configurations -->template-->gradle--> Define gradle project field gradle project.
Upvotes: -1
Reputation: 858
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
Upvotes: 3
Reputation: 116
Can you provide your Gradle version and complete build.gradle ?
Possible issues:
apply plugin: 'com.android.application'
or any plugin that implicitly uses the Java Plugin ? That's where the testImplementation
comes from.
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
Upvotes: 2
Reputation: 1153
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 =)
Upvotes: 8