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

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

Related

Gradle DSL method not found: 'androidTestImplementation()'

I'm trying to use uiautomator so looked the tutorial here https://developer.android.com/training/testing/ui-testing/uiautomator-testing#java
In the tutorial, it says:
In the build.gradle file of your Android app module, you must set a dependency reference to the UI Automator library:
dependencies {
...
androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
}
So I added that line, so my build.gradle files is like this:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.3.72"
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.0.2"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
// androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
// androidTestImplementation('androidx.test.uiautomator:uiautomator:2.2.0')
// 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
}
And I tried to run the app. But I got an error:
Gradle DSL method not found: 'androidTestImplementation()'
Possible causes:
The project 'My Application' 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 4.0.2 and sync project
The project 'My Application' 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
You are using the wrong build.gradle file and the wrong block.
You have to move the androidTestImplementation from the top-level file to the module/build.gradle file in the dependencies block (not the dependencies in the buildscript block)::
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
android {
//...
}
dependencies {
//...
androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
}
Move your dependency implementations to App level build.gradle file. You have put those in Project level build.gradle file.

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'
}
}

Nativescript gradle project-level

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:+'
}

Cannot resolve symbol "FirebaseAuth"

I still have this error inspite of me adding
compile 'com.google.android.gms:play-services-auth:11.8.0'
compile "com.google.android.gms:play-services-gcm:11.8.0" to the build.gradle(app).Please help me resolve this problem.
First, add rules to your root-level build.gradle file, to include the google-services plugin and the Google's Maven repository:
buildscript {
// ...
dependencies {
// ...
classpath 'com.google.gms:google-services:3.2.0' // google-services
plugin
}
}
allprojects {
// ...
repositories {
// ...
maven {
url "https://maven.google.com" // Google's Maven repository
}
}
}
Then, in your module Gradle file (usually the app/build.gradle), add the
apply plugin line at the bottom of the file to enable the Gradle plugin:
apply plugin: 'com.android.application'
android {
// ...
}
dependencies {
// ...
compile 'com.google.firebase:firebase-core:11.8.0'
// Getting a "Could not find" error? Make sure you have
// added the Google maven respository to your root build.gradle
}
// ADD THIS AT THE BOTTOM
apply plugin: 'com.google.gms.google-services'
You may need to make sure that your activity is importing the Firebase Auth module.
In the .java file for your activity (eg. Login.java):
import com.google.firebase.auth.FirebaseAuth;

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

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"
}

Categories

Resources