nativescript-plugin-firebase
nativescript-plugin-firebase copied to clipboard
Android App Not working with NS 8.2.
A problem occurred evaluating script. Plugin with id 'com.google.gms.google-services' not found.
Actions taken to resolve:
- Created a Native-script Vue project of NS 8.2.1
- After creating run the app in android emulator. It works fine.
- Added npm module @nativescript/firebase and its related google-services.json in App_resources/Android folder. Also bundle id's are same for the firebase json and application.xml
Added
project.ext {
googlePlayServicesVersion = "+"}
in both before-plugins and app gradle. 5. Add android platform executes without any problem 6. Build fails with problem
A problem occurred evaluating script.
Plugin with id 'com.google.gms.google-services' not found.
PS: Same code works for iOS.
My Local environment Information ✔ Getting environment information
No issues were detected. ✔ Your ANDROID_HOME environment variable is set and points to correct directory. ✔ Your adb from the Android SDK is correctly installed. ✔ The Android SDK is installed. ✔ A compatible Android SDK for compilation is found. ✔ Javac is installed and is configured properly. ✔ The Java Development Kit (JDK) is installed and is configured properly. ✔ Xcode is installed and is configured properly. ✔ xcodeproj is installed and is configured properly. ✔ CocoaPods are installed. ✔ CocoaPods update is not required. ✔ CocoaPods are configured properly. ✔ Your current CocoaPods version is newer than 1.0.0. ✔ Python installed and configured correctly. ✔ The Python 'six' package is found. ✔ Xcode version 12.5.1 satisfies minimum required version 10. ✔ Getting NativeScript components versions information... ⚠ Update available for component nativescript. Your current version is 8.2.1 and the latest available version is 8.2.2. ✔ Component @nativescript/core has 8.2.1 version and is up to date. ✖ Component @nativescript/ios is not installed. ✔ Component @nativescript/android has 8.2.2 version and is up to date.
Same issue here with vanilla JS.
For me the following line fixed the issue in the App_Resources/Android/app.gradle file:
// Add the following line:
apply plugin: 'com.google.gms.google-services' // Google Services plugin
android {
https://firebase.google.com/docs/android/setup#manually_add_firebase
Thanks @tujlaky I already have that apply plugin in my app.gradle file. This is driving me crazy.
For me the following line fixed the issue in the App_Resources/Android/app.gradle file:
// Add the following line: apply plugin: 'com.google.gms.google-services' // Google Services plugin android {https://firebase.google.com/docs/android/setup#manually_add_firebase
Sadly, this did not work for me. I am getting the same error mentioned above.
I was able to fix my issue. The classpath com.google.gms:google-services wasn't being copied over to the build.gradle dependencies node.
I am also having the same issue. @SingleMalted could you please provide more info, example of .gradle file with it's location?
I made the following changes and managed to build. I hope this gets fixed in the future in App_Resources\Android\app.gradle
(...)
android {
compileSdkVersion 31 // <-- This
defaultConfig {
(...)
in platforms\android\build.gradle
(...)
dependencies {
(...)
classpath "com.google.gms:google-services:4.3.4" // <-- This
}
(...)
@maddy2get basically what @comporell has posted above.
Your platform/app/build.gradle needs to have apply plugin: "com.google.gms.google-services" and your
platform/build.gradle needs to contain dependencies { classpath "com.google.gms:google-services:4.3.4"}
I use an after-prepare hook script to write these two lines to their respective files. This is necessary for me as I use CI/CD for my builds. If you don't use a CI/CD you can manually update the build files with the lines above.
`
Thanks @SingleMalted and @comporell for the detailed explanation.
I made the changes in platform/app/build.gradle and platform/build.gradle but when I execute : ns debug android
I receive the error
`Gradle build... assets by status 7.77 MiB [cached] 6 assets Entrypoint bundle 7.4 MiB = runtime.js 86.4 KiB vendor.js 6.97 MiB bundle.js 360 KiB cached modules 2.77 MiB (javascript) 24.8 KiB (runtime) [cached] 351 modules webpack 5.70.0 compiled successfully in 176 ms Webpack compilation complete. Watching for file changes. + applying user-defined configuration from /Users/pedromartins/Develop/web/www/prociv/example-app/App_Resources/Android/before-plugins.gradle + setting applicationId + applying user-defined configuration from /Users/pedromartins/Develop/web/www/prociv/example-app/App_Resources/Android/before-plugins.gradle + applying user-defined configuration from /Users/pedromartins/Develop/web/www/prociv/example-app/App_Resources/Android/app.gradle + adding nativescript runtime package dependency: nativescript-optimized-with-inspector + adding aar plugin dependency: /Users/pedromartins/Develop/web/www/prociv/example-app/node_modules/@nativescript/core/platforms/android/core.aar + adding aar plugin dependency: /Users/pedromartins/Develop/web/www/prociv/example-app/node_modules/@nativescript/core/platforms/android/widgets-release.aar + adding aar plugin dependency: /Users/pedromartins/Develop/web/www/prociv/example-app/node_modules/@nativescript/firebase/platforms/android/firebase.aar + adding aar plugin dependency: /Users/pedromartins/Develop/web/www/prociv/example-app/node_modules/@nativescript/firebase/platforms/android/firebase-release.aar
Execution failed for task ':app:processDebugGoogleServices'. No matching client found for package name 'org.nativescript.exampleapp'
Unable to apply changes on device: emulator-5554. Error is: Command ./gradlew failed with exit code 1.`
Can anybody help me
Thanks
@pmiguelmartins Do you have the google-service.json file in that directory?
https://developers.google.com/android/guides/google-services-plugin
@SingleMalted Thanks for the fast response
Yes I have .... this was working ... But know gives this error
I have same issue :
(
The apply plugin: 'com.google.gms.google-services' needs to be called at the beginning of the platform/app/build.gradle and the dependencies { classpath "com.google.gms:google-services:4.3.4"} goes in the root build.gradle.
@SingleMalted
I create a new project and put the code where you mentioned
I still have the error
` Gradle build... assets by status 7.77 MiB [cached] 6 assets Entrypoint bundle 7.4 MiB = runtime.js 86.4 KiB vendor.js 6.97 MiB bundle.js 360 KiB cached modules 2.77 MiB (javascript) 24.8 KiB (runtime) [cached] 351 modules webpack 5.70.0 compiled successfully in 233 ms Webpack compilation complete. Watching for file changes. + applying user-defined configuration from /Users/pedromartins/Develop/web/www/prociv/example-app/App_Resources/Android/before-plugins.gradle + setting applicationId + applying user-defined configuration from /Users/pedromartins/Develop/web/www/prociv/example-app/App_Resources/Android/before-plugins.gradle + applying user-defined configuration from /Users/pedromartins/Develop/web/www/prociv/example-app/App_Resources/Android/app.gradle + adding nativescript runtime package dependency: nativescript-optimized-with-inspector + adding aar plugin dependency: /Users/pedromartins/Develop/web/www/prociv/example-app/node_modules/@nativescript/core/platforms/android/core.aar + adding aar plugin dependency: /Users/pedromartins/Develop/web/www/prociv/example-app/node_modules/@nativescript/core/platforms/android/widgets-release.aar + adding aar plugin dependency: /Users/pedromartins/Develop/web/www/prociv/example-app/node_modules/@nativescript/firebase/platforms/android/firebase.aar + adding aar plugin dependency: /Users/pedromartins/Develop/web/www/prociv/example-app/node_modules/@nativescript/firebase/platforms/android/firebase-release.aar
Execution failed for task ':app:processDebugGoogleServices'. No matching client found for package name 'org.nativescript.exampleapp' `
Excuse me for asking again but you are downloading your google-service.json file from your firebase account correct?
@SingleMalted yes And download again to compare but is iqual
@pmiguelmartins do you have any hook scripts that might be overwriting the gradle.build? It took me a bit of work to get my project working but the best thing I can do at this point is just send you this https://developers.google.com/android/guides/google-services-plugin
run ns doctor and send the results. Also what version of Node/NPM are you using?
@SingleMalted
my ns doctor :
` ~/Develop/web/www/prociv/example-app master !5 ?3 ❯ ns doctor ✘ INT 45m 54s 20:35:02 ✔ Getting environment information
No issues were detected. ✔ Your ANDROID_HOME environment variable is set and points to correct directory. ✔ Your adb from the Android SDK is correctly installed. ✔ The Android SDK is installed. ✔ A compatible Android SDK for compilation is found. ✔ Javac is installed and is configured properly. ✔ The Java Development Kit (JDK) is installed and is configured properly. ✔ Xcode is installed and is configured properly. ✔ xcodeproj is installed and is configured properly. ✔ CocoaPods are installed. ✔ CocoaPods update is not required. ✔ CocoaPods are configured properly. ✔ Your current CocoaPods version is newer than 1.0.0. ✔ Python installed and configured correctly. ✔ The Python 'six' package is found. ✔ Xcode version 13.2.1 satisfies minimum required version 10. ✔ Getting NativeScript components versions information... ✔ Component nativescript has 8.2.2 version and is up to date. ✔ Component @nativescript/core has 8.2.1 version and is up to date. ✖ Component @nativescript/ios is not installed. ✔ Component @nativescript/android has 8.2.2 version and is up to date. `
node version : v16.14.1
I created a new app ( ns create example-app --vue )
and make the changes but the error keeps ...
Oh didn't realize you are using vue, not that it should really matter but I'm using TS/Vanilla JS.
I don't think the node version v16.14.1 is supported however.
I'm running on node v14.15.0
@SingleMalted I've encountered this same problem but I'm confused by your description of the locations. I have a {N} 8.2 JS project, and I don't have (or can't find) a platform/app/build.gradle file. Would that be platforms/android/build.gradle? Nor do I seem to have what you describe as the root build.gradle - maybe App_Resources/Android/app.gradle or perhaps App_resources/Android/before-plugins.gradle? You are talking about a NativeScript project, yes?
@SingleMalted
I create a new project make the changes and now the error is :
/Users/pedromartins/Develop/web/www/prociv/example-app/platforms/android/app/src/main/AndroidManifest.xml:13:9-17:19 Error: android:exported needs to be explicitly specified for element <service#org.nativescript.plugins.firebase.MyFirebaseMessagingService>. Apps targeting Android 12 and higher are required to specify an explicit value forandroid:exportedwhen the corresponding component has an intent filter defined. See https://developer.android.com/guide/topics/manifest/activity-element#exported for details. /Users/pedromartins/Develop/web/www/prociv/example-app/platforms/android/app/src/main/AndroidManifest.xml:18:9-22:19 Error: android:exported needs to be explicitly specified for element <service#org.nativescript.plugins.firebase.MyFirebaseInstanceIDService>. Apps targeting Android 12 and higher are required to specify an explicit value forandroid:exported` when the corresponding component has an intent filter defined. See https://developer.android.com/guide/topics/manifest/activity-element#exported for details.
Execution failed for task ':app:processDebugMainManifest'. Manifest merger failed with multiple errors, see logs `
I'm sure your structure is different than mine since I'm building in vanilla js. I have hook scripts that write to a couple build.gradles.
I would suggest jumping on the NS discord channel and asking someone who is currently using vue.
@pmiguelmartins you're getting closer.
Your android manifest needs an exported="true || false" for every activity.
You also need to add your firebase services. Bare with me I'm on the beach on my phone 😆 I'll get you that code in a few min.
@SingleMalted Thanks very much
And enjoy the beach ... I'm from Portugal / Algarve ... I know what is beach time !!!!
@SingleMalted Thanks very much
And enjoy the beach ... I'm from Portugal / Algarve ... I know what is beach time !!!!
You need to add a service for every firebase component you're using... like so
<service android:name="org.nativescript.plugins.firebase.MyFirebaseInstanceIDService" android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
<service android:name="org.nativescript.plugins.firebase.MyFirebaseMessagingService" android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
@SingleMalted I've encountered this same problem but I'm confused by your description of the locations. I have a {N} 8.2 JS project, and I don't have (or can't find) a
platform/app/build.gradlefile. Would that beplatforms/android/build.gradle? Nor do I seem to have what you describe as the rootbuild.gradle- maybeApp_Resources/Android/app.gradleor perhapsApp_resources/Android/before-plugins.gradle? You are talking about a NativeScript project, yes?
Rather than adding classpath to platforms/android/build.gradle a better method is to create a file named App_Resources/Android/buildscript.gradle
with the content below:
repositories {
google()
jcenter()
}
dependencies {
classpath "com.google.gms:google-services:4.3.4"
}
this way, the gms configuration will be included at the initialization of the build process. Make sure to clean the project and start over.
@SingleMalted
I create a new project make the changes and now the error is :
/Users/pedromartins/Develop/web/www/prociv/example-app/platforms/android/app/src/main/AndroidManifest.xml:13:9-17:19 Error: android:exported needs to be explicitly specified for element <service#org.nativescript.plugins.firebase.MyFirebaseMessagingService>. Apps targeting Android 12 and higher are required to specify an explicit value forandroid:exportedwhen the corresponding component has an intent filter defined. See https://developer.android.com/guide/topics/manifest/activity-element#exported for details. /Users/pedromartins/Develop/web/www/prociv/example-app/platforms/android/app/src/main/AndroidManifest.xml:18:9-22:19 Error: android:exported needs to be explicitly specified for element <service#org.nativescript.plugins.firebase.MyFirebaseInstanceIDService>. Apps targeting Android 12 and higher are required to specify an explicit value forandroid:exported` when the corresponding component has an intent filter defined. See https://developer.android.com/guide/topics/manifest/activity-element#exported for details.Execution failed for task ':app:processDebugMainManifest'. Manifest merger failed with multiple errors, see logs `
As @SingleMalted mentioned, add exported = "true" flag to you activity in App_Resources\Android\src\main\AndroidManifest.xml
(...)
<activity
android:name="com.tns.NativeScriptActivity"
android:label="@string/title_activity_kimera"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|smallestScreenSize|screenLayout|locale|uiMode"
android:theme="@style/LaunchScreenTheme"
android:hardwareAccelerated="true"
android:exported="true"
android:launchMode="singleTask">
(...)
@comporell I added the buildscript.gradle file you suggested as well as having android:exported="true" set in the AndroidManifest but I'm receiving this error:
Unable to create service org.nativescript.plugins.firebase.MyFirebaseMessagingService: java.lang.ClassNotFoundException: Didn't find class "org.nativescript.plugins.firebase.MyFirebaseMessagingService" on path: DexPathList
Any ideas?
Any ideas?
Do you have multiDexEnabled true in App_Resources/Android/app.gradle?