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
Related
I want to initialize firebase at runtime. I convert the JSON file to XML on this site -> https://dandar3.github.io/android/google-services-json-to-xml.html
Then I put string in app/res/strings.xml file.
app/build.gradle file:
apply plugin: 'io.fabric'
.....
dependencies {
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.6'
implementation 'com.google.firebase:firebase-core:16.0.4'
}
build.gradle file:
buildscript {
repositories {
...
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
...
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'io.fabric.tools:gradle:1.26.1'
}
}
I build my project and the error is here:
Crashlytics found an invalid API key: null.
Check the Crashlytics plugin to make sure that the application has been added successfully!
Contact support#fabric.io for assistance.
What is the problem? Firebase says .that you can delete the google_services.json file from your project.
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 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"
}
I have multiple modules and every module uses exact same dependency. Because it is annoying to maintain that dependency in all build.gradle files (version updates etc.) I'd like to have it in project build.gradle. Is that possible please?
I tried to:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
compile 'joda-time:joda-time:2.8.1'
}
}
allprojects {
repositories {
jcenter()
}
}
but that doesn't work as it seems that gradle is not able to find DSL for compile. Is there any other way please?
Thank you
It's called centralize the support libraries dependencies in gradle. Working with multi-modules project, it is very useful to centralize the dependencies, especially the support libraries.
http://gmariotti.blogspot.in/2015/07/how-to-centralize-support-libraries.html
Correct me if i'm wrong but what's inside buildscript are dependencies for build.
When I generate my project build.gradle there is note :
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.1.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
So no, you can't put dependencies for all your module here but maybe there is a plugin for that.
You cannot centralize the dependencies for all (sub-)projects, but is is very easy to centralize the version numbers. In build.gradle in the root add this:
ext {
jodaTimeVersion = '2.8.1'
}
And in build.gradle of the modules that need Joda-Time add this (pay attention to the double quotes):
dependencies {
compile "joda-time:joda-time:${jodaTimeVersion}"
}
I am working on Android Studio and my activities include ViewPagers. For that I had to install packages (Android Support Repository and Android Support Library). Now that I have already installed these, I opened gradle.build and this is what I see:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.13.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
My question:
What should I add and where should I add it in here?
Also, I cant locate SDK in my computer :/ . A little help would be really appreciated.
Android use multi project build setup. Your existing file is MAIN build.gradle file.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.13.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
// this is where you need to put dependencies of your BUILD SCRIPT
}
}
allprojects {
repositories {
jcenter()
}
dependencies {
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.1'
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.1'
// This is where you put dependencies EVERYONE of your modules need.
}
}
In the sub directories of your main build.gradle resides individual build.gradle files.
Module A
dependencies {
// This is where you put dependencies, your module need.
}
Module B
dependencies {
// This is where you put dependencies, your module need.
}
There are more than one gradle files. one of them is located in your project directory. Same name (build.gradle). find it and put your dependencies there.
To find your SDK path: File -> Project Structure -> SDK Location. (Android Studio v0.8.14)