How to correctly apply the google services plugin? - android

I am working on a project, and I need to apply the google services plugin to my code. I have done so in the build.gradle project and module, but I keep receiving the following warning every time I run my app.
Please apply google-services plugin at the bottom of the build file.
Any help would be great!
Also, I am a beginner to coding, and it may be important to note that my app doesn't work. I get a runtime error in the emulator when I try to run it:
________ keeps stopping
app info
close app
Here is my build.gradle Module:app
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "edmt.dev.androidgeofire"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
androidTestImplementation
('com.android.support.test.espresso:espresso-core:3.0.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'com.h6ah4i.android.widget.verticalseekbar:verticalseekbar:0.7.2'
implementation 'com.firebase:geofire-android:2.3.1'
implementation 'com.google.firebase:firebase-database:16.1.0'
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.google.android.gms:play-services-maps:16.1.0'
testImplementation 'junit:junit:4.12'
implementation 'com.google.android.gms:play-services-base:16.1.0'
implementation 'com.google.android.gms:play-services-location:16.0.0'
}
apply plugin: 'com.google.gms.google-services'
I'm not sure what else I would need to include to help anyone understand, so if anyone needs anything else I would be happy to add it.

Try changing your build.gradle(project) like this
buildscript {
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
classpath 'com.google.gms:google-services:4.2.0'
}
}
Don't forget to change
classpath 'com.android.tools.build:gradle:3.3.2'
to your actual classpath of gradle

Related

Unable to resolve dependency firebase and google play service

I am trying to connect my android project to firebase. It was working also properly in starting. I don't know what happened all by sudden i am got series of Unresolved dependencies.
I have done almost all steps which I found over web. Like disable offline work, Invalidate chache/restart. Even when I am creating new project I am facing same problem. Earlier this all things were not happening.
My application gradle code is :
// 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.2.1'
classpath 'com.google.gms:google-services:4.0.1'
}
}
allprojects {
repositories {
google()
maven { url "http://jcenter.bintray.com"}
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle for module
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.aabsys.metasensing"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "2.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7: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'
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.google.firebase:firebase-messaging:17.3.0'
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
}
apply plugin: 'com.google.gms.google-services'
Thanks in advance.Please find image
Try adding the following dependency in your code:-
implementation 'com.google.android.gms:play-services:12.0.1'
If it still does not resolve your issue, try updating Google play services and Google repository.
Try to change the class path
classpath 'com.google.gms:google-services:4.2.0'
I solved my issue by reducing google service version to :
classpath 'com.google.gms:google-services:4.0.0'
And removing
implementation 'com.google.firebase:firebase-core:16.0.1'

OSM Android dependecies failed to resolve

I'm currently trying to implement OSMDroid in to my project, but doing it has shown in the OSMDroid tutorial (http://osmdroid.github.io/osmdroid/index.html) does not seem to be working.
When I try to sync the Gradle project I get the following message:
Failed to resolve: osmdroid-android
And I have here the full build.gradle(Module: app):
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.massas.emergency_numbers_pi"
minSdkVersion 23
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation 'org.osmdroid:osmdroid-android:6.0.0-SNAPSHOT'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7: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'
}
Am I doing something wrong or is the dependencie just outdated? Should I insert the dependencies in the project build.gradle?
I'm new to android dev, so please bear with me! Thanks
1) Make sure you have added the repository. You need maven central for stable releases and sonatype for snapshot. Instructions for that are included in the documentation but for the sake of this response:
Current stable:
repositories {
mavenCentral()
}
dependencies {
implementation 'org.osmdroid:osmdroid-android:6.0.1'
}
Current snapshot:
repositories {
mavenCentral()
maven{
url 'https://oss.sonatype.org/content/repositories/snapshots/'
name 'OSS-Sonatype'
}
}
dependencies {
implementation 'org.osmdroid:osmdroid-android:6.0.2-SNAPSHOT'
}
Note: you can also add repositories to your root gradle file to the allprojects section.
2) You should use the stable version (6.0.1 at the time of writing) uless you have a specific reason to use snapshot.

dex is not merged for android studio. Have gone through a lot of answers. Still don't get the solution

apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.example.souravsaikia.chattingapp"
minSdkVersion 23
targetSdkVersion 26
multiDexEnabled true
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile 'com.android.support:multidex:1.0.3'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.google.firebase:firebase-auth:16.0.1'
implementation 'com.google.firebase:firebase-database:16.0.1'
implementation 'com.google.firebase:firebase-storage:16.0.1'
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'
implementation 'com.android.support:design:26.1.0'
implementation 'de.hdodenhof:circleimageview:2.2.0'
api 'com.theartofdev.edmodo:android-image-cropper:2.5.1'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.firebaseui:firebase-ui-database:4.2.1'
implementation 'com.android.support:recyclerview-v7:26.1.0'
compile 'com.google.android.gms:play-services-auth:16.0.1'
}
apply plugin: 'com.google.gms.google-services'
This is the app level gradle file.
Also here is the code for project level gradle.
buildscript {
repositories {
apply plugin: 'announce'
google()
jcenter()
maven {
url "https://maven.google.com"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:3.1.0'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Sorry to repeat the same question. But I have gone through most of the answers here. But still could not find the appropriate solution for the problem. I have been stuck in this problem for two days. So help would be appreciated.
Error log:
Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
I changed compileSdkVersion to 27 and targetSdkVersion to 27. Also the appcompat,design and recyclerView dependencies to 27.1.1. It worked for me.

Getting error try to connect firebase

Hellow all,
I try to connect firebase to my android app but I'm getting this error
that was triggered I'm tried to sign in to firebase using the assistant tool. I'm tried several solutions here in StackOverflow. but It does not work for me.
this the gradle build project
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
And here is Gradle build Module
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.gpacalc.shannirmala.gpacalculator"
minSdkVersion 15
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
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'
testCompile 'junit:junit:4.12'
compile 'com.android.support:design:27.1.1'
}
If you are referring firebase the first time then follow the manual setup because its increase your knowledge second time you can use the assistant tool.
Add Following dependency in Project level build.gradle file like bellow
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
classpath 'com.google.gms:google-services:3.2.0' // google-services plugin
}
Then after apply plugin in your app level build.gradle at bottom of your dependency section and also add firebase dependency in dependency section like bellow.
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:26.+'
implementation 'com.android.support:design:26.+'
implementation 'com.android.support:cardview-v7:26.+'
implementation 'com.android.support.constraint:constraint-layout:1.1.0-beta1'
implementation 'com.android.support:support-vector-drawable:26.1.0'
compile 'com.android.support:support-v4:26.+'
compile 'com.google.firebase:firebase-core:12.0.0'
compile 'com.google.firebase:firebase-auth:12.0.0'
}
apply plugin: 'com.google.gms.google-services'
And Finally, put google-services.json file in app directory which downloaded from your firebase console after creating firebase project for your application.
How to create Firebase Project on console?

Gradle cannot find google services plugin

I've seen a lot of other questions on SO about this topic, but they're all dealing with things I don't think are relevant to my situation, so I'm making a new question.
In my android app, I am hoping to utilize firebase as my database. However, after copying the google services json file into my 'app' folder, and adding the necessary dependencies in my 'build.gradle' file, it's giving an error, saying 'plugin with id "com.google.gms.google-services" not found'. I'll include the code for my build.gradle, please let me know if I made a mistake somewhere!
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 24
buildToolsVersion "24.0.1"
defaultConfig {
applicationId "com.xlr8.jackson.doctrineoropinion"
minSdkVersion 15
targetSdkVersion 24
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso- core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:24.2.1'
testCompile 'junit:junit:4.12'
classpath 'com.google.gms:google-services:3.0.0'
}
buildscript {
dependencies {
}
}
Notes:
I have tried several options such as:
move classpath 'com.google.gms:google-services:3.0.0' to the bottom in buildscript/dependencies
Change classpath 'com.google.gms:google-services:3.0.0' to classpath 'com.google.gms:google-services:1.3.0-beta1'
Thanks in advance!
First you doing it wrong way its not way to add google play services.You need to compile google play service in project level build gradle first like this
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
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
}
}
and then add libraries you need in app level build.gradle like this
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.android.support:support-v4:23.4.0'
compile 'com.google.firebase:firebase-messaging:9.6.0'

Categories

Resources