Cannot add Google Play Location Service as dependency to my Android Project - android

I tried to add the Google location Service to my Android Project by referencing the official link.
As the tutorial said I added the following line to the dependencies section in the Project Gradle file.
implementation "com.google.android.gms:play-services-location:11.8.0"
But when i resynced the project i got the following error
Error:(19, 0) Could not find method implementation() for arguments [com.google.android.gms:play-services-location:11.8.0] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
Open File
I am using Android Studio 3.0.1 and Gradle Version 4.1.
How to overcome this error?

please try this
Add in Build.gradel at app lavel
dependencies {
Implementation 'com.google.android.gms:play-services:9.6.0'
}
apply plugin: 'com.google.gms.google-services
// 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:3.0.0'
classpath 'com.google.gms:google-services:3.0.0'
// NOTE: Do not place your application dependencies here; they
belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

I think you have forgot to add maven repository in your app gradle file. Try by doing these steps. Open the build.gradle file for your application. Make sure that the repositories section includes a maven section with the "https://maven.google.com" endpoint. For example: allprojects {repositories {jcenter()maven {url "https://maven.google.com"}}}
Avoid using + in your dependencies as it android studio will try to update dependencies every 24 hours. Also replace compile by implementation for low APK size.
Edit 1:
As you told maven repository did not worked.
Check your project settings by going to Android Studio.
Click on file
click on project structure
There will option of Project in sidebar. Tap on it.
Check for the gradle and andrpid plugin version.
Put these values
Gradle Version - 4.1
Android plugin version - 3.0.1
Android Plugin Repository - jcenter,google()
Default Library Repository - jcenter, 'https://maven.google.com'
Reply me if it works

Related

Trying to add module to project. Gradle DSL method not found: 'versionName()'

I am trying to add a epub reader library to a project I have already created. The library I am trying to add to my project as a moduel is the Folio Reader Library (https://github.com/FolioReader/FolioReader-Android). I have downloaded this library on my computer and have tried adding it through File -> New -> Import Module. However, during the process I received countless errors. My current one is this:
Gradle DSL method not found: 'versionName()'
Possible causes:
The project 'FolioReader-Android-master' 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 3.4.1 and sync project
The project 'FolioReader-Android-master' 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
This file is the file where the dependencies are declared for the Library.
FolioReader-Android-master:
build.gradle file:
// Top-level build file where you can add configuration options common to
all sub-projects/modules.
buildscript {
apply from: 'versions.gradle'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
//moj
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.11"
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
}
}
allprojects {
configurations.all {
resolutionStrategy {
cacheChangingModulesFor 0, 'seconds'
}
}
repositories {
mavenLocal()
google()
jcenter()
maven { url "https://jitpack.io" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
The error itself states that the problem arises because the project is using a version of the Gradle plug-in may not contain the method. I have updated the version to the newest one, however I still receive this error. Any suggestions on how I can solve this problem?
Problem solved by replacing
versionName 1
with
versionName "1.1"
in the Module level build.gradle file.

Could not find com.android.tools.build:gradle:5.4.1

I just turned on an old computer and am trying to access some code. After updating all of my Android Studio, JDK, and Downloading the latest Gradle I am having trouble building the project. I get this error ;
ERROR: Could not find com.android.tools.build:gradle:5.4.1.
Searched in the following locations:
- https://jcenter.bintray.com/com/android/tools/build/gradle/5.4.1/gradle-5.4.1.pom
- https://jcenter.bintray.com/com/android/tools/build/gradle/5.4.1/gradle-5.4.1.jar
Required by:
project :
Add Google Maven repository and sync project
Open File
I have dont this and this
Below is the content of build.gradle file
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:5.4.1'
}
}
Below is the content of wrapper file
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
in my settings I have toggled between default and setting my path manually. I have also attemted to add google() and MavenCentral() to the repositories
I just ant to build and run my app but it is saying no! haha help
Don't confuse gradle with the Android Gradle plugin.
classpath 'com.android.tools.build:gradle:5.4.1'
It is the Android Gradle plugin and 5.4.1 doesn't exist.
Use the latest stable release:
classpath 'com.android.tools.build:gradle:3.4.1'
Check the release notes for other versions.
If you open URL https://jcenter.bintray.com/com/android/tools/build/gradle, there is no 5.4.1.
For gradle version meanings, please check What is real Android Studio Gradle Version?.
For your case, you need to add google() repo in your buildscript closure and modify the android-gradle-plugin version to be 3.4.1
buildscript {
repositories {
google()// <-- add this.
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
}
And, also, probably, you need to update your allprojects closure as below:
allprojects {
repositories {
google()// <-- add this.
jcenter()
}
}
Edit #1
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
This is the wrapper configuration telling which gradle version to use for your android gradle plugin. It is NOT the plugin version.

Failed to resolve: play-services-tasks

I have been tryong to add FCM to my android application for almost 48 hours now. I am keep on failing with these two errors on Android Studio. I have tried all the solutions in this post. Still I couldn't fix it.
I want firebase cloud messaging to be integrated in my app. So I did the followings.
Created an app in the firebase console
Included the .json config file
Added the SDK
implementation 'com.google.firebase:firebase-messaging:17.0.0'
(In the app level gradle)
apply plugin: 'com.google.gms.google-services' (In the app level gradle file last
line)
classpath 'com.google.gms:google-services:4.0.1'
(In the project level gradle)
Added the repository
google() (In the project level gradle)
I have tried syncing many times and I keep on getting the error
Failed to resolve: play-services-tasks Open File
Failed to resolve: play-services-basement Open File
On a side note, I am using the gradle plugin 3.1.3
classpath 'com.android.tools.build:gradle:3.1.3'
Can someone please give me a hand here please.
In gradle (project),
just change the position of google() before jcenter(),
and the error is gone.
repositories {
google()
jcenter()
}
jcenter() sometimes act as a mirror repository for some Google dependencies. During Gradle building process, it looks for dependencies in the first entry listed in your repositories {...} block. So if this repository is broken or something bad occurs with any dependency the process will fail.
Here there is a recommended order for repository list
repositories {
google()
maven {
url 'https://maven.google.com/'
}
jcenter()
}
Put google() repository at the very first line of dependencies. It will work.
Add in your app.gradle
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
and upgrade your dependencies version.
I had this occurring due to outdated build tools version. Updating from 28.0.2 to 28.0.3 resolved it.
buildToolsVersion '28.0.2'
to:
buildToolsVersion '28.0.3'
in build.gradle file.

Android Gradle 4.1-rc-1 Not Found

In Android Studio 3.0 Beta 1, I'm required to use Gradle 4.1-rc-1. AS offered to do the update for me (why not) but when the project tries to build, I get an error saying the pom and jar for gradle-4.1-rc-1. It's apparently not in the jcenter or google repos. On Google's AS release page, they mention this is a known bug and that a clean and sync should fix it, but it did not work for me.
Here is my build file:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.1.3-2'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1-rc-1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
google()
jcenter()
maven { url 'https://jitpack.io' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Which repository holds the correct gradle files? Should they have downloaded to my machine already?
Maybe you should update your gradle/wrapper/gradle-wrapper.properties file of your project, instead of build.gradle.
Here is my content of gradle-wrapper.properties:
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-rc-1-all.zip. Content of build.gradle : classpath 'com.android.tools.build:gradle:3.0.0-beta1'.
I got it working although I'm not exactly sure what did it. However, here are some things I did and some extra information if anyone else is running into this issue as well.
Project Settings (⌘;)
Gradle Version: 4.1
Android Plugin Version: 3.0.0-beta1
Android Plugin Repository: google(), jcenter
Default Library Repository: google(), jcenter, 'https://jitpack.io'
With these settings, upon trying to sync, I would be asked to update my Gradle to 4.1-rc-1. I pressed the "do it manually" option. Then I went to my project in the terminal and did what google suggested:
gradlew clean
gradlew assemble

android Error:(44, 13) Failed to resolve com.esri.arcgis.android:arcgis-android:10.2.7

Every time I build my android project it gives me this Error
android Error:(44, 13) Failed to resolve com.esri.arcgis.android:arcgis-android:10.2.7
Can anyone help me regarding this ?
The problem is solved like that
1.
add the following lines
// Add the following ArcGIS repository
maven {
url 'https://esri.bintray.com/arcgis'
}
in the build.gradle of the project module
to be like that
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
//**Added .. for ArcGIS
maven {
url 'https://esri.bintray.com/arcgis'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
// Add the following ArcGIS repository
maven {
url 'https://esri.bintray.com/arcgis'
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Also , I edited the version of arcgis dependency in the app module build.gradle to be like that
compile 'com.esri.arcgis.android:arcgis-android:10.2.8'
May be needful.
In the app module build.gradle file, within the dependencies block, add a directive to include the ArcGIS Runtime SDK for Android dependency to your app.
App module build.gradle file
Fallow all the steps from here
dependencies {
// Add ArcGIS Runtime SDK for Android dependency
compile 'com.esri.arcgis.android:arcgis-android:10.2.7'
}
This may be due to version mis-match of Android Studio. So, try giving latest dependencies in app level build.gradle. In my case I changed it from 10.2.6 to 10.2.8
compile 'com.esri.arcgis.android:arcgis-android:10.2.8'

Categories

Resources