How to add dependencies to project's top-level build.gradle file? - android

I'm trying a sample code which implements Google Cloud Messaging (GCM) and that is provided by google itself, GCM Demo.
I don't know how exactly I can add the dependencies
List item
Add the dependency to your project's top-level build.gradle:
When I go to Project Structure > Modules > Add and then select Module Dependency then a pop up screen appears for no module found to depend on.
If there is another way I can add the dependencies then a help would be appreciated.I have attached an image regarding the same.

As described in the link.
Add the dependency to your project's top-level build.gradle: (just edit the file)
classpath 'com.google.gms:google-services:1.3.0-beta1'
You should have somenthing like this:
// 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'
classpath 'com.google.gms:google-services:1.3.0-beta1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
Then add the plugin to your app-level build.gradle (just edit the file):
apply plugin: 'com.google.gms.google-services'
You should have somenthing like this:
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
//..
}
Finally add the dependency in your app-level build.gradle
dependencies {
compile "com.google.android.gms:play-services:7.5.0"
}

Related

Is there any way to remove "classpath 'com.google.gms:google-services:4.2.0' dependency from top level project gradle

For firebase setup now my project gradle has classpath 'com.google.gms:google-services:4.2.0'.
app gradle contains apply plugin: 'com.google.gms.google-services'
I want to move firebase related code to the dynamic module
So I moved apply plugin: 'com.google.gms.google-services' from app Gradle to module Gradle
but classpath 'com.google.gms:google-services:4.2.0' is still related to full project.
Is there any way to remove this dependency from top-level project Gradle?
Just add the buildscript block inside the module/build.gradle file:
buildscript {
repositories {
//...
}
dependencies {
//..
classpath 'com.google.gms:google-services:4.2.0'
}
}

how to find in ionic project (<android>/<app>/build.gradle)

I'm trying to add Firebase to my android app builded with ionic, the firebase's documentation https://firebase.google.com/docs/android/setup says to add this line on my root-level build.gradle.
Here's my Project-level build.gradle (/build.gradle):
buildscript {
dependencies {
// Add this line
classpath 'com.google.gms:google-services:4.0.1'
}
}
App-level build.gradle (//build.gradle):
dependencies {
// Add this line
implementation 'com.google.firebase:firebase-core:16.0.1'
}
...
// Add to the bottom of the file
apply plugin: 'com.google.gms.google-services'
You can find both gradle files in platforms folder,
Project-level build.gradle (/build.gradle): At platforms/android/build.gradle
App-level build.gradle (//build.gradle): At platforms/android/app/build.gradle

Plugin with id 'com.google.gms.google-services' not found

I am using google services at the very first time in my app(ionic platform). I am following this doc. While building my app, I got the following error message. Please help out. Thank you.
A problem occurred evaluating script.
Plugin with id 'com.google.gms.google-services' not found.
Please add the plugin to your project by updating your top-level build.gradle and your app-level build.gradle files as follows:
Add the dependency to your project-level build.gradle:
classpath 'com.google.gms:google-services:3.0.0'
Add the plugin to your app-level build.gradle:
apply plugin: 'com.google.gms.google-services'
More information regarding this can be found in GCM - Set up a GCM Client App on Android.
And, in addition to that, the guide or workaround given in GitHub - GCMPushPlugin might also help.
Add classpath com.google.gms:google-services:3.0.0 dependencies at project level build.gradle
Refer the sample block from project level build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
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
}
}

com.android.library not find

I use gradle build my android code ,here is my build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle-experimental:0.2.1'
}
}
so I can apply
plugin:com.android.model.application ,but when I want to depend a module , I got a error:
error:plugin with com.android.library not find
which is my
android library module's build.gradle begin with
apply plugin: 'com.android.library
if I write build.gradle like this:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
}
}
I cannnot find
plugin: 'com.android.model.application' my question is what should I do to depend my library successfully
Hey you have to update the plugin to match the plugins available in the experimental build:
IE. change "com.android.library" to "com.android.model.library"
You can read more about it here on the experimental gradle build documentation.
Search for "com.android.model.library" and you'll go right to it.
Be sure to read the other stuff in the doc; there are other differences you will have to add to your old library-model build.gradle file also. (eg. "targetSdkVersion 23" changes to "targetSdkVersion.apiLevel 23"

plugin with id not working studio

I am trying to add google play services library in Android studio.I have added the google play services in build.gradle.
But it is now working for me.I have referred many SO Post regarding to this.But it doesn't solved my problem.
Below I am posted the build.gradle code where I have added the google play services.
build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
apply plugin : 'android'
dependencies {
compile 'com.google.android.gms:play-services:4.0.30'
}
allprojects {
repositories {
jcenter()
}
}
}
While adding the google play services in dependencies at gradle compile com.google.android.gms:play-services:4.0.30. I am getting an error:plugin with id not working.
Anyone can help me with this.Thank you.
The build.gradle you have posted seems to be the project configuration. The global project build.gradle has the buildscript tag and also the comment about not adding application dependencies as can be seen in your question.
There should be another build.gradle inside your app module where you should also find something similar to this depending on your version of Android Studio and Gradle,
apply plugin: 'com.android.application'
android {
...
}
dependencies {
...
}
Place your compile 'com.google.android.gms:play-services:4.0.30' inside the app module's build.gradle depedencies
Use latest version of play services:
compile 'com.google.android.gms:play-services:7.5.0'
Update:
Think you using wrong gradle file. You must add the above code in the gardle file under app folder.
Please add your library dependencies in the build.gradle file the resides inside your app module
apply plugin: 'com.android.application'
repositories {
maven { url "http://dl.bintray.com/populov/maven" }
mavenCentral()
}
android {
...............
}
dependencies {
compile 'com.google.android.gms:play-services:4.0.30'
}
You should not add these dependencies inside build.gradle file for the root folder
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
}
}
Do not place your application dependencies inside the outer build.gradle file they belongin the individual module build.gradle files

Categories

Resources