I'm trying to use uiautomator so looked the tutorial here https://developer.android.com/training/testing/ui-testing/uiautomator-testing#java
In the tutorial, it says:
In the build.gradle file of your Android app module, you must set a dependency reference to the UI Automator library:
dependencies {
...
androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
}
So I added that line, so my build.gradle files is like this:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.3.72"
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.0.2"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
// androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
// androidTestImplementation('androidx.test.uiautomator:uiautomator:2.2.0')
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
And I tried to run the app. But I got an error:
Gradle DSL method not found: 'androidTestImplementation()'
Possible causes:
The project 'My Application' may be using a version of the Android Gradle plug-in that does not contain the method (e.g. 'testCompile' was added in 1.1.0).
Upgrade plugin to version 4.0.2 and sync project
The project 'My Application' may be using a version of Gradle that does not contain the method.
Open Gradle wrapper file
The build file may be missing a Gradle plugin.
Apply Gradle plugin
You are using the wrong build.gradle file and the wrong block.
You have to move the androidTestImplementation from the top-level file to the module/build.gradle file in the dependencies block (not the dependencies in the buildscript block)::
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
android {
//...
}
dependencies {
//...
androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
}
Move your dependency implementations to App level build.gradle file. You have put those in Project level build.gradle file.
Related
I'm trying to use RecyclerView Helper, but can't get project work with it.
Here is the library that I'm trying to use: https://github.com/nisrulz/recyclerviewhelper
But getting this error:
Could not find method implementation() for arguments [com.android.support:appcompat-v7:{latest version}] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
Please install the Android Support Repository from the Android SDK Manager.
This is my build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.0'
def supportLibVersion="{latest version}"
// Required
implementation "com.android.support:appcompat-v7:${supportLibVersion}"
implementation "com.android.support:recyclerview-v7:${supportLibVersion}"
// RecyclerViewHelper
implementation "com.github.nisrulz:recyclerviewhelper:${supportLibVersion}"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I think the latest version is a placeholder text. The latest version should be replaced with the latest version of SDK you need.
Please use this
def supportLibVersion="27.1.1"
instead of
def supportLibVersion="{latest version}"
Your library documentation also have this line
where {latest version} corresponds to published version in 27.1.1.
This is the project.gradle file ,you import library in wrong gradle file.please import this library on app.gradle file.
Import this on app.gradle
dependencies {
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.github.nisrulz:recyclerviewhelper:27.1.1'
}
Import this on project.gradle
allprojects {
repositories {
google()
jcenter()
}
}
After updating android studio 3.1.2 my existing project gives error at
dataBinding.enabled = true
error is as follows-
Failed to resolve: com.android.databinding:library:3.1.2
Failed to resolve: com.android.databinding:adapters:3.1.2
my gradle dependency are as follows-
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:25.1.0'
implementation 'com.android.support:recyclerview-v7:25.1.0'
implementation 'com.android.support:preference-v7:25.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.0-beta3'
implementation 'com.firebase:firebase-jobdispatcher:0.5.0'
// Instrumentation dependencies use androidTestCompile
// (as opposed to testCompile for local unit tests run in the JVM)
androidTestImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support:support-annotations:25.1.0'
androidTestImplementation 'com.android.support.test:runner:0.5'
androidTestImplementation 'com.android.support.test:rules:0.5'
}
I also tried
android.databinding.enableV2=true
but its also not working
When I tried to update build tool version to 4.4 then I found this error. I f I do not update the build tool version then its working fine.
check it this below code in your project level gradle file ..
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
According to the Android Team answer you had to add
google()
too all repositories
and priority is important. so other repositories must be added after google()
Downgrade to 3.1.0 in project level build.gradle file, then rebuild the project.
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
I hope this helps
I also has the same issue I ensured that I added google() to all repositories and also I downgraded gradle to 3.1.0 from 3.1.4 and my project was successfully build.
Another TIP: We can also add the below code to our build.gradle(project) which takes cares of libraries conflicts with new dependencies
configurations.all {
resolutionStrategy {
force"com.android.support:supportannotations:$androidSupportVersion"
force "com.android.support:support-v4:$androidSupportVersion"
force "com.android.support:appcompat-v7:$androidSupportVersion"
force "com.android.support:design:$androidSupportVersion"
force "com.android.support:recyclerview-v7:$androidSupportVersion"
}
}
And you can keep your libraries in a separate file such as libraries.gradle and include them in build.gradle(project)
buildscript
{
apply from: "./libraries.gradle"
}
I added Data-Binding to my project and the next time I build project, I faced the same issue, more specifically logcat displayed this message:
Failed to resolve: com.android.databinding:library:3.1.2
Failed to resolve: com.android.databinding:adapters:3.1.2
As per accepted answer, I checked my Project Level Gradle File to see whether it was missing google() in its repositories, but it was already there.
Build multiple times, but all in vain.
Then I did what my Android Master once told me to do, just in case when everything fails.
File -> Invalidate Caches/Restart.
Next time the project opened it build successfully.
Hi i am getting the followin error on my build gradle Could not find method implemnetation() for arguments. I tried to clean the gradle cache clean project but nothing works. I have seen similliar posts but i couldnt find the answer.
// Top-level build file where you can add configuration options common to all sub-projects/modules.
apply plugin: 'java-library'
buildscript {
repositories {
mavenCentral()
}
dependencies {
implementation 'org.hibernate:hibernate-core:3.6.7.Final'
api 'com.google.guava:guava:23.0'
testImplementation 'junit:junit:4.+'
implementation 'com.amazonaws:aws-android-sdk-mobile-client:2.6.+#aar'
}
}
allprojects {
repositories {
jcenter()
}
}
Your project and your application module have both a build.gradle file.
Here you are mixing the top level build.gradle, which should be like this:
Project build.gradle (Top Level inside your project's folder)
//the `java-library` plugin is unnecessary here
buildscript {
repositories {
mavenCentral()
google()
}
dependencies {
//the gradle plugin version is the same as Android Studio, here v3.1.1 which is currently the latest stable
classpath 'com.android.tools.build:gradle:3.1.1'
}
}
allprojects {
repositories {
mavenCentral()
google()
}
}
App Module build.gradle (Module Level inside you app module's folder)
apply plugin: 'com.android.application'
android{...}
dependencies {
implementation 'org.hibernate:hibernate-core:3.6.7.Final'
api 'com.google.guava:guava:23.0'
testImplementation 'junit:junit:4.+'
implementation 'com.amazonaws:aws-android-sdk-mobile-client:2.6.+#aar'
}
For more information about these 2 build.gradle files, you can refer to the documentation for the top level and the module level
So I'm new to App Development, and I'm struggling with the Gradle Sync:
Blockquote Error:(10, 0) Gradle DSL method not found: 'compile()'
Possible causes:The project 'MyApplication' may be using a version of the Android Gradle plug-in that does not contain the method (e.g. 'testCompile' was added in 1.1.0).
Upgrade plugin to version 2.3.3 and sync projectThe project 'MyApplication' may be using a version of Gradle that does not contain the method.
Open Gradle wrapper fileThe build file may be missing a Gradle plugin.
Apply Gradle plugin
That is the error message I get.
This is the code I am using
// 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.3.3'
compile 'com.google.code.gson:gson:2.8.0'
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.squareup.picasso:picasso:2.5.2'
apply plugin: 'project-report'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Please help with a way to fix this,
thanks in advance
Regards
There are two build.gradle files in your Android Studio project. The one that you edited is in the project's root directory. That's not the file you should have put those lines in. The other build.gradle is in your module's directory (e.g., app/). Those four compile lines go in a dependencies closure in that build.gradle file.
This is even mentioned in the comment in the file:
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
This sample project (from this book) uses some of those same dependencies. My top-level build.gradle file does not have the compile statements:
// 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.3.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
Instead, they are in the app/build.gradle file:
apply plugin: 'com.android.application'
dependencies {
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.squareup.retrofit:retrofit:1.9.0'
}
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
minSdkVersion 15
targetSdkVersion 25
}
}
I want to use Gson and Retrofit to interact with an API. According to the documentations, I add theses lines into the build.gradle of my project:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
mavenCentral() //this line
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
compile 'com.google.code.gson:gson:2.7' //this line
compile 'com.squareup.retrofit:retrofit:1.9.0' //this line
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
mavenCentral() //and this line
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
but I have these errors :
Error:(10, 0) Gradle DSL method not found: 'compile()' Possible
causes:The project 'TempoEDF' may be using a version of the
Android Gradle plug-in that does not contain the method (e.g.
'testCompile' was added in 1.1.0). Upgrade
plugin to version 2.3.3 and sync projectThe project
'TempoEDF' may be using a version of Gradle that does not contain the
method. Open Gradle wrapper
fileThe build file may be missing a Gradle plugin. Apply Gradle plugin
So I used the Gradle plugin like my IDE wants to:
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
apply plugin: 'gradle'
compile 'com.google.code.gson:gson:2.7'
compile 'com.squareup.retrofit:retrofit:1.9.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
but I have this error :
Error:(10, 0) Plugin with id 'gradle' not found. Open
File
What did I do wrong?
so according to the documentations i add theses lines into the build.gradle of my project
Please note the comments in that file:
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
I do not know what "documentations" that you read that told you to put these things in the project-level build.gradle file. Please consider providing links, so that we can get that material fixed.
To get past this problem, remove the changes that you made to this file. Then, add those dependencies to the module's build.gradle file (e.g., app/build.gradle in a typical Android Studio project).