I have a React Native (0.68.6) application that I want to implement Firebase push notification. I'm using mac and I wanted to implement & test on android first.
I created Firebase account and created new Project. Also added google-service.json to the [project_folder] > android > app
I cannot build app when I try to add Firebase SDK.
On Firebase it says; if you still use buildscript syntax follow next steps;
classpath 'PLUGIN_MAVEN_COORDINATES:PLUGIN_VERSION'
plugins {
id 'com.android.application'
// Add the ID of the plugin
id 'FIREBASE_PLUGIN_ID'
...
}
Values;
PLUGIN_MAVEN_COORDINATES : com.google.gms:google-services
PLUGIN_VERSION : 4.4.0
FIREBASE_PLUGIN_ID: com.google.gms.google-services
The changes I made;
[project_folder] > android > build.gradle
buildscript {
...
dependencies {
...
classpath("com.google.gms:google-services:4.4.0")
}
...
}
[project_folder] > android > app > build.gradle
plugins {
id "com.android.application"
id "com.google.gms.google-services"
}
now I cannot build my app with the configurations and it's gave errors following;
FAILURE: Build failed with an exception.
java.lang.NoClassDefFoundError: com/android/build/api/extension/AndroidComponentsExtension
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
BUILD FAILED in 6s
error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
FAILURE: Build failed with an exception.
java.lang.NoClassDefFoundError: com/android/build/api/extension/AndroidComponentsExtension
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
BUILD FAILED in 6s
at makeError ([project_folder]/node_modules/execa/index.js:174:9)
at [project_folder]/node_modules/execa/index.js:278:16
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async runOnAllDevices ([project_folder]/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:109:5)
at async Command.handleAction ([project_folder]/node_modules/@react-native-community/cli/build/index.js:192:9)
info Run CLI with --verbose flag for more details. error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
I tried different syntax rules when adding dependency and plugin but no luck.
Can anyone help me? Thanks
I solved the issue by using different syntax and version. If you encounter the same issue, you can follow the steps below;
buildscript {
dependencies {
...
classpath 'com.google.gms:google-services:4.4.0'
}
}
plugins {
id 'com.android.application'
id 'com.google.gms.google-services'
}
dependencies {
...
implementation 'com.google.firebase:firebase-messaging:21.1.0'
...
}
these steps solved the isuue.