Gradle Sync failed: Could not find method implementation() - android-studio

Been trying to resolve this error for hours...cant get it solved. I am a newbie to Android Studio
My project level build.gradle file is as follows
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
maven { url "https://maven.google.com" }
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.google.gms:google-services:4.0.1'
}
}
allprojects {
repositories {
jcenter()
maven { url "https://maven.google.com" }
}
}
And my app build.gradle file is as follows
apply plugin: 'com.android.application'
android {
compileSdkVersion 18
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "com.amazonaws.androidtest"
minSdkVersion 8
targetSdkVersion 18
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
aaptOptions {
cruncherEnabled = false
}
dependencies {
implementation 'com.google.firebase:firebase-core:16.0.1'
}
}
apply plugin: 'com.google.gms.google-services'
Getting the following error when trying to sync
Gradle sync failed: Could not find method implementation() for arguments [com.google.firebase:firebase-core:16.0.1] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
I am using Android Studio 2.3
Tried to upgrade Gradle to version 4 but that requires Android Studio 3. Cant install Android Studio 3 for now.
Also added the maven url's as some answers suggested. Still not working.
Any other way to resolve this?

with build-tools 3.1.4, it should become known (read below):
classpath "com.android.tools.build:gradle:3.1.4"
but if you cannot update Android Studio , use compile instead of implementation.
compile "com.google.firebase:firebase-core:16.0.3"

Related

Android Studio cannot sync and build NEW and OLD kotlin projects

When I am creating a new project in Android Studio, and load old projects I got this:
java.lang.NoClassDefFoundError: org/gradle/internal/impldep/com/google/common/collect/Lists
java.lang.ClassNotFoundException: org.gradle.internal.impldep.com.google.common.collect.Lists
ERROR: Unable to load class 'org.gradle.internal.impldep.com.google.common.collect.Lists'.
Possible causes for this unexpected error include:
Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
Re-download dependencies and sync project (requires network)
The state of a Gradle build process (daemon) may be corrupt
Now I am totally stucked with that.
1, I downloaded studio again and installed to an other drive, the probleme still exists.
2, I deleted all of my Android Studios from my computer, I downloaded and installed again. Started a new kotlin project, the same error happened.
3, invalidate/restart not fixed
4, redownload dependencies not fixed
5, update gradle not fixed
6, flutter plugin disabled, not fixed
I was used my old Android Studio for flutter/dart and kotlin too. It looks like I can not build anymore native apps/kotlin.
my gradle wrapper
distributionUrl=https://services.gradle.org/distributions/gradle-5.6.4-all.zip
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.3.61'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// 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
}
build gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "hu.lacas.myapplication"
minSdkVersion 19
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
app build gradle
Any way to fix this?
Thanks
LOL. I found an old project what were built!!!
I copied this strings from that:
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.71"
}
and
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
and finally synced, built!!!
Something is very broken in the new Android Studio, because I got a lot of error/sync failed even if I create a NEW PROJECT

Google services ; com.google.gms:google-services:2.1.2 ; failed to resolve services-measurement

Just trying to update to the latest google play services 9.4.0. If I leave the classpath in the application level gradle to 2.1.2 which seems to be the latest release as of June 03, link, I get the error failed to resolve :
Error:Failed to resolve: com.google.android.gms:play-services-measurement:9.4.0
Install Repository and sync project
I have already my packages updated in SDK manager.
If I leave the classpath as 3.0.0 which was the release of May things seem to be ok. Any idea as to why I get such error with the 2.1.2 version classpath? see below for my gradle files. Android Studio version : 2.1.3. Appreciate any help.
build.gradle Project Level:
buildscript {
repositories {
jcenter()
mavenLocal()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.3'
classpath 'com.google.gms:google-services:2.1.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
mavenLocal()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle app Level:
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.0"
defaultConfig {
applicationId "com.example.main.projectone"
minSdkVersion 18
targetSdkVersion 24
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile('com.facebook.android:facebook-android-sdk:4.7.0') {
exclude module: 'bolts-android'
}
compile 'com.android.support:appcompat-v7:24.0.0'
compile 'com.android.support:design:24.0.0'
compile 'com.parse:parse-android:1.13.0'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.github.bumptech.glide:okhttp3-integration:1.4.0#aar'
compile 'com.squareup.okhttp3:okhttp:3.3.1'
compile 'com.android.support:cardview-v7:24.0.0'
compile 'com.android.support:support-v4:24.0.0'
compile 'com.android.support:multidex:1.0.1'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.8.1'
compile 'de.hdodenhof:circleimageview:2.1.0'
compile 'com.android.support:recyclerview-v7:24.0.0'
compile 'com.firebase:geofire-android:2.0.0'
compile 'com.google.android.gms:play-services:9.4.0'
compile 'com.google.firebase:firebase-auth:9.4.0'
compile 'com.google.firebase:firebase-storage:9.4.0'
}
apply plugin: 'com.google.gms.google-services'
Since you are using the version 9.4.0 you have to use the google play service plugin v 3.0.0:
buildscript {
// ...
dependencies {
// ...
classpath 'com.google.gms:google-services:3.0.0'
}
}
Check the official documentation for the setup.

failed to build tool version android

I tried to open an old project of mine in a freshly installed android studio (today), It gave me this error :
failed to find build tools revision 23.0.0 rc2
install build tools 23.0.0 rc2 and sync project
I looked for it in the internet and I tried to add this in the gradle file :
android {
compileSdkVersion 22
buildToolsVersion "22.0.0"
}
And it gave me another error:
gradle DSL method not found: 'android()'
possible causes:
the project may be using a version of gradle that does not contain the method.
gradle settings.
the build file may be missing a gradle plugin.
apply gradle plugin.
this is my gradle file :
// 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:1.2.3'
}
}
allprojects {
repositories {
jcenter()
}
}
android {
compileSdkVersion 22
buildToolsVersion "22.0.0"
}
Right click on your project > Open Module Settings > Properties Tab, then change :
Compile Sdk Verion to API 23: Android 6.0
Build Tools Version 23.0.0
I checked the build tools version installed in my Android Studio and I have Android SDK Build-Tools rc3, Not rc2.
I changed it in build.gradle (Module App) to
android {
compileSdkVersion 22
buildToolsVersion "23.0.0 rc3"}
After that it works.
Check if you have the same issue.
In your top level build.gradle you have to remove the android block
android {
compileSdkVersion 22
buildToolsVersion "22.0.0"
}
Just use:
// 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:1.2.3'
}
}
allprojects {
repositories {
jcenter()
}
}
You have to use the android block, in the app/build.gradle where you should define something like:
apply plugin: 'com.android.application'
android {
compileSdkVersion XX
buildToolsVersion "XX.X.X"
defaultConfig {
minSdkVersion XX
targetSdkVersion XX
versionCode 1
versionName "1.0"
}
buildTypes {
release {
//......
}
}
}
dependencies {
//......
}
theres 2 gradle files
the one you have to modify is the one under this directory
APPLICATION NAME / APP / BUILD.GRADLE
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "PUT THE CODE YOU WANT HERE EX "23.0.0 r3""
defaultConfig {
applicationId "org.app.appname"
minSdkVersion 10
targetSdkVersion 22
versionCode 9
versionName "1.10.3"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile 'com.google.android.gms:play-services:7.5.0'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.android.support:support-v4:22.2.1'
compile files('libs/volley.jar')
}
not the one which looks like these
// 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:1.3.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
In my case I tried everything and finally I had to do a simple change from this
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "23.0.0 rc2"
}
to this
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "23.0.0" //DELETE rc2 AND SYNC PROJECT
}
It depends on which version of Android SDK Build-tools you have installed, you could check it via the SDK Manager, in my case I haven't the 23.0.0 rc2 installed but the 23.0.1, so you need to edit your app/build.gradle
for me it was then:
android {
compileSdkVersion 22
buildToolsVersion "23.0.1"
}

Gradle DSL method not found: complie()

Error:(17, 0) Gradle DSL method not found: 'compile()'
Possible causes:The project 'WizardPagerrr_production_server' may be using a version of Gradle that does not contain the method.
Gradle settingsThe build file may be missing a Gradle plugin.
Apply Gradle plugin
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
}
}
allprojects {
repositories {
jcenter()
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.android.gms:play-services:6.5.87'
compile 'com.android.support:support-v4:21.0.3'
}
android {
compileSdkVersion 21
buildToolsVersion '17.0.0'
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
This error message is telling you what's wrong:
The build file may be missing a Gradle plugin. Apply Gradle plugin
You need an apply plugin statement in your build file to tell Gradle how to build the module. If this module is an Android Application module that will output an APK, use:
apply plugin: 'com.android.application'
If it's a library module that will output an AAR, use:
apply plugin: 'com.android.library'
The deeper meaning of the error message is that in this context Gradle doesn't have a definition for the compile dependency directive (i.e it's not built in to Gradle). It needs the Android Gradle plugin to set that up.

Android Studio Google Maps API v2

i'm trying to use Google Maps API v2 in my project.
This is my environment:
OSX 10.9
Android Studio 0.3.2
min SKD 9 and compile SDK 14
Java 1.7.0_17
Testing on Nexus 7 4.3 with GooglePlayService 4.0.30
I get the following errors on the device. Android Studio don‘t note any errors:
11-05 07:44:33.888 2386-2386/myproject E/dalvikvm﹕ Could not find
class 'com.google.android.gms.maps.SupportMapFragment', referenced from method
myproject.activities.Maps.initMaps
11-05 07:44:34.052 2386-2386/myproject E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: com.google.android.gms.common.GooglePlayServicesUtil
at myproject.activities.Maps.onResume(Maps.java:36)
The error point is clear: There are missing class files.
Here are the dependencies of my project:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 14
buildToolsVersion "18.1.1"
defaultConfig {
minSdkVersion 9
targetSdkVersion 10
}
}
dependencies {
compile 'com.android.support:appcompat-v7:18.0.+'
compile 'com.android.support:gridlayout-v7:18.0.+'
compile 'com.android.support:support-v4:19.0.+'
compile 'com.android.support:support-v13:19.0.+'
compile 'com.google.android.gms:play-services:4.0.30'
}
In my opinion should be compile 'com.google.android.gms:play-services:4.0.30' enough.
So any suggestions what's missing ?
Greetz,
Moddus
I had the same problem.
When I changed the version to 'com.google.android.gms:play-services:3.1.36' my app started normally without any errors but the map was white.
Tried several diferent api keys and still don't know where the problem is...
edit: Finally I made my app to shows up the map by changing the classpath of the buildsctipt. I'm using Android Studio v.0.4 which comes with gradle:0.7 and I gess it has a problems for now with google play services. Here is my build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 10
targetSdkVersion 19
}
}
dependencies {
compile 'com.google.android.gms:play-services:3.1.36'
compile 'com.android.support:appcompat-v7:+'
}

Resources