EddyVerbruggen / nativescript-plugin-firebase

:fire: NativeScript plugin for Firebase
https://firebase.google.com
MIT License
1.01k stars 441 forks source link

Android App Not working with NS 8.2. #1873

Open zghotlawala opened 2 years ago

zghotlawala commented 2 years ago

A problem occurred evaluating script. Plugin with id 'com.google.gms.google-services' not found.

Actions taken to resolve:

  1. Created a Native-script Vue project of NS 8.2.1
  2. After creating run the app in android emulator. It works fine.
  3. 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
  4. 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.

SingleMalted commented 2 years ago

Same issue here with vanilla JS.

tujlaky commented 2 years ago

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

SingleMalted commented 2 years ago

Thanks @tujlaky I already have that apply plugin in my app.gradle file. This is driving me crazy.

comporell commented 2 years ago

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.

SingleMalted commented 2 years ago

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.

maddy2get commented 2 years ago

I am also having the same issue. @SingleMalted could you please provide more info, example of .gradle file with it's location?

comporell commented 2 years ago

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
    }
    (...)
SingleMalted commented 2 years ago

@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. `

maddy2get commented 2 years ago

Thanks @SingleMalted and @comporell for the detailed explanation.

pmiguelmartins commented 2 years ago

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.

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

SingleMalted commented 2 years ago

@pmiguelmartins Do you have the google-service.json file in that directory?

https://developers.google.com/android/guides/google-services-plugin

pmiguelmartins commented 2 years ago

@SingleMalted Thanks for the fast response

Yes I have .... this was working ... But know gives this error

Bezlepkin commented 2 years ago

I have same issue : 2022-03-16_22-00-18 (

SingleMalted commented 2 years ago

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.

pmiguelmartins commented 2 years ago

@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.

Execution failed for task ':app:processDebugGoogleServices'. No matching client found for package name 'org.nativescript.exampleapp' `

SingleMalted commented 2 years ago

Excuse me for asking again but you are downloading your google-service.json file from your firebase account correct?

pmiguelmartins commented 2 years ago

@SingleMalted yes And download again to compare but is iqual

SingleMalted commented 2 years ago

@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?

pmiguelmartins commented 2 years ago

@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 ...

SingleMalted commented 2 years ago

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

dlcole commented 2 years ago

@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?

pmiguelmartins commented 2 years ago

@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 `

SingleMalted commented 2 years ago

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.

SingleMalted commented 2 years ago

@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.

pmiguelmartins commented 2 years ago

@SingleMalted Thanks very much

And enjoy the beach ... I'm from Portugal / Algarve ... I know what is beach time !!!!

SingleMalted commented 2 years ago

@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>
comporell commented 2 years ago

@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?

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.

comporell commented 2 years ago

@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">
(...)
tylerablake commented 2 years ago

@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?

comporell commented 2 years ago

Any ideas?

Do you have multiDexEnabled true in App_Resources/Android/app.gradle?

tylerablake commented 2 years ago

Any ideas?

Do you have multiDexEnabled true in App_Resources/Android/app.gradle?

Yeah I do

pmiguelmartins commented 2 years ago

@tylerablake Hi I had the same problem

You have to had this in Manifest (I think its because the script when insert this code in the Manifest does't put the exported)

`

    <service android:name="org.nativescript.plugins.firebase.MyFirebaseMessagingService" android:exported="false">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service>

`

PS - Sorry for my English but I'm Portuguese

tylerablake commented 2 years ago

@pmiguelmartins Thanks for helping out! Yes, I have android:exported="false" for those.

msl2000 commented 2 years ago

@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?

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.

Hi @comporell, I followed your steps and added the content in buildscript.gradle >. I get some new error:

A problem occurred evaluating script. Could not find method compile() for arguments [com.romandanylyk:pageindicatorview:1.0.3] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

Seems the compile() function has been removed in gradle 7.0 and depracated before 4.10. Does anyone know how to specify the gradle version used? Or an idea for a fix for the problem above?

gabrielbiga commented 2 years ago

Hello guys, I found the issue. This patch seems to fix it: Just override your hooks/firebase-build-gradle.js

https://gist.github.com/gabrielbiga/aa4efb87704bc5238efdaa5a9d06fa1d

I will create a PR adding this modified hook to the code. Until then, please test it.

jitendraP-ashutec commented 2 years ago

@gabrielbiga After replacing firebase-build-gradle.js I am got below error:


Plugin with id 'io.fabric' not found.```

Do you have any idea suggestion to resolve this issue ?
Siergiej29 commented 2 years ago

I've tried everything described here but unfortunately nothing works.

Urgent response and error correction is needed!

hateart commented 2 years ago

Hello guys, I found the issue. This patch seems to fix it: Just override your hooks/firebase-build-gradle.js

https://gist.github.com/gabrielbiga/aa4efb87704bc5238efdaa5a9d06fa1d

I will create a PR adding this modified hook to the code. Until then, please test it.

Thank You so much. Works fine for me!

seros00 commented 2 years ago

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. This worked for me.

I also need an after prepare hook script, but I don't know how to create it. Could you add some basic information or guidance on how to create one?

Thanks in advance.

mrzanirato commented 2 years ago

Hello, any news about the fix? unfortunately we have an old NS6 project ... is there some chance that a fix will be released also for the NS6 version ... Thanks Marco

mrzanirato commented 2 years ago

@EddyVerbruggen we have the same problem with NS6, do you have any suggestions? Thanks

calleja23 commented 2 years ago

Solved for me. Thank you very much