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
Related
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.
I want to use Segment (with Firebase) into my NativeScript app. So I must follow this instructions : https://segment.com/docs/destinations/firebase but I must modify two files : the Module-level build.gradle :
buildscript {
dependencies {
// Add these lines
compile 'com.segment.analytics.android:analytics:4.+'
compile 'com.segment.analytics.android.integrations:firebase:+'
}
}
// Add to the bottom of the file
apply plugin: 'com.google.gms.google-services'
and the Project-level build.gradle :
buildscript {
dependencies {
// Add this line
classpath 'com.google.gms:google-services:3.1.0'
}
}
allprojects {
repositories {
// Add this line
maven { url 'https://maven.google.com' }
}
}
But with NativeScript I have only one build.gradle. So, how can I implement this lines in gradle ?
Thanks !
I know this question is old but they may help someone in the future. Nativescript Docs aren't the best and this worked for me so it MAY not work for you.
This applies for Plugins and Regular Apps.
Buildscript Gradle.
App_Resources/Android/buildscript.gradle
PLUGINS buildscript.gradle
repositories {
// Add this line
maven { url 'https://maven.google.com' }
}
dependencies {
classpath 'com.google.gms:google-services:3.1.0'
}
App Grade
PLUGINS include.gradle
App_Resources/Android/app.gradle
dependencies {
compile 'com.segment.analytics.android:analytics:4.+'
compile 'com.segment.analytics.android.integrations:firebase:+'
}
apply plugin: 'com.google.gms.google-services'
HOWEVER
The compile configuration still exists but should not be used as it will not offer the guarantees that the api and implementation configurations provide.https://docs.gradle.org/current/userguide/java_library_plugin.html
You can also write this as
App Grade
PLUGINS include.gradle
App_Resources/Android/app.gradle
dependencies {
implementation 'com.segment.analytics.android:analytics:4.+'
implementation 'com.segment.analytics.android.integrations:firebase:+'
}
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()
}
}
i've been working with firebase to access an activity on my project. Everything works fine, no compilation errors. However after i go to tools > firebase i can connect to my app easily, however when i try to click Add Real time database it shows me this:
build.gradle will include these new dependencies:
compile 'com.google.firebase:firebase-database:16.0.1:15.0.0'
Since compile is deprecated i use implementation, and when i do
Implementation 'com.google.firebase:firebase-database:16.0.1:15.0.0'
i get the following error Failed to resolve: firebase-database-15.0.0
and my sync fails.
Change Root Gradle to
buildscript {
// ...
dependencies {
// ...
classpath 'com.google.gms:google-services:4.0.1' // google-services plugin
}
}
allprojects {
// ...
repositories {
// ...
google() // Google's Maven repository
}
}
And App Gradle To
apply plugin: 'com.android.application'
android {
// ...
}
dependencies {
// ...
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.google.firebase:firebase-database:16.0.1'
// Getting a "Could not find" error? Make sure you have
// added the Google maven respository to your root build.gradle
}
// ADD THIS AT THE BOTTOM
apply plugin: 'com.google.gms.google-services'
Hope This May Help You
add jcenter() in your project-level gradle.
allprojects {
repositories {
google()
jcenter()
}
}
and keep remaining as #Tomin B said.
I've tried to included cards library in my project using the below code in my build.gradle file.
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
dependencies {
//Core card library
compile 'com.github.gabrielemariotti.cards:cardslib-core:2.0.1'
//Optional for built-in cards
compile 'com.github.gabrielemariotti.cards:cardslib-cards:2.0.1'
//Optional for RecyclerView
compile 'com.github.gabrielemariotti.cards:cardslib-recyclerview:2.0.1'
//Optional for staggered grid view support
compile 'com.github.gabrielemariotti.cards:cardslib-extra-staggeredgrid:2.0.1'
//Optional for drag and drop support
compile 'com.github.gabrielemariotti.cards:cardslib-extra-dragdrop:2.0.1'
//Optional for twowayview support (coming soon)
//compile 'com.github.gabrielemariotti.cards:cardslib-extra-twoway:2.0.1'
}
}
allprojects {
repositories {
jcenter()
mavenCentral()
}
}
But when compiling, android studio is throwing up errors as below.
Error:(23, 0) Gradle DSL method not found: 'compile()'
Possible causes:The project 'cardslib_1' 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
I'm guessing the reason to be gradle version, which is lower in libraries I'm including.
How to know the gradle version my dependencies are using and how to adjust them to my project.
When I thought to add the libraries, maven has repositories in aar file which I don't think will let you know the gradle version.
Thanks for any help in this regards.
You're adding the dependencies in the wrong place. They should be outside of the buildscript section and in the modules/applications build.gradle.
Parent build.gradle. This should be in the root directory of your project
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
}
}
allprojects {
repositories {
jcenter()
mavenCentral()
}
}
Module build.gradle. This should be in the folder of the module you're trying to add the dependencies to.
apply plugin: 'com.android.application'
android {
// Android related settings go here
}
dependencies {
compile 'com.github.gabrielemariotti.cards:cardslib-core:2.0.1'
compile 'com.github.gabrielemariotti.cards:cardslib-cards:2.0.1'
compile 'com.github.gabrielemariotti.cards:cardslib-recyclerview:2.0.1'
compile 'com.github.gabrielemariotti.cards:cardslib-extra-staggeredgrid:2.0.1'
compile 'com.github.gabrielemariotti.cards:cardslib-extra-dragdrop:2.0.1'
}
This assumes that the structure of your project is something like
Project
|___build.gradle
|___Module
|____build.gradle