Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Can we use GradleTemplate instead of AndroidManifest with FirebaseCloudMessaging ? #1072

Closed
Cova8bitdots opened this issue Jun 8, 2021 · 5 comments
Labels
api: messaging closed-by-bot needs-info Need information for the developer stale Don't have recent activity type: question

Comments

@Cova8bitdots
Copy link

[REQUIRED] Please fill in the following fields:

  • Unity editor version: Unity2020.3.10f1
  • Firebase Unity SDK version: 6.15.2 and 7.2.0
  • Source you installed the SDK: Unity Package Manager
  • Problematic Firebase Component: CloudMessaging
  • Other Firebase Components in use: Auth, Crashlytics,
  • Additional SDKs you are using: FaceBook, Adjust,
  • Platform you are using the Unity editor on: Mac
  • Platform you are targeting: iOS, Android
  • Scripting Runtime: IL2CPP

[REQUIRED] Please describe the question here:

When we try to update Unity version from 2019LTS to 2020LTS (2020.3.10.f1), The error message "Failed to read Firebase options from the app's resources. Either make sure google-services.json is included in your build or specify options explicitly." has happened and failed to Initialize Firebase SDK on runtime application like this issue
( #677 )
And we know that we have to use gradle template instead of Android Manifest for edit BuildSettings.

However, we cannot turn off Custom Main Manifest because of Firebase Cloud Message SDK.
Script in FCM SDK force to make it TURN ON
( we try to switch platform to iOS , then we can turn off this check box.
However when we switch platform to Android, that script works to force turning on Custom Main Manifest.
MoreOver, when we remove FCM package, we can turn off this checkbox :(
)
スクリーンショット 2021-06-08 15 28 48

So, are there any plan to enable use gradle template with FirebaseSDK including FCM ?
or, Are there anyway to avoid this error message without using GradleTemplate ?

@paulinon paulinon added needs-info Need information for the developer type: feature request and removed new New issue. needs-info Need information for the developer type: question labels Jun 8, 2021
@chkuang-g
Copy link
Contributor

chkuang-g commented Jun 24, 2021

Hi @Cova8bitdots

I think the Custom Main Manifest is ON just because Assets/Plugins/Android/AndroidManifest.xm exists. There is actually no flag from Unity API to turn it ON or OFF.

Also, you are correct. Assets/Firebase/Editor/Firebase.Messaging.Editor.dll automatically generate this file because we have custom implementation to forward message from Android service to Android activity (see this code).

Is there a reason why you have to eliminate this file? Are you trying to do so to avoid the error you saw? I think that error is an unrelated issue.

About the error message you mentioned:

Failed to read Firebase options from the app's resources. Either make sure google-services.json is included in your build or specify options explicitly.

This occurs when Firebase SDK was not able to locate google-services.json. Quick question: does this occurs to you on Android only or on iOS as well?

For Android, Firebase.Editor.dll would generated an Android resource google-services.xml from google-services.json under Assets/Plugins/Android/FirebaseApp.androidlib. Please check if that folder exists.

Lastly, could you confirm if the same issue is reproducible using Firebase quickstart?

Please let us know.
Shawn

@chkuang-g chkuang-g added needs-info Need information for the developer and removed needs-attention Need Googler's attention labels Jun 24, 2021
@Cova8bitdots
Copy link
Author

I think the Custom Main Manifest is ON just because Assets/Plugins/Android/AndroidManifest.xml exists. There is actually no flag from Unity API to turn it ON or OFF.

I have few question.

  1. Did your editor script call reflection method to force turning Custom Main Manifest ON ?
  2. on Unity2020.3 (Unity2020LTS), it requires customGradleTemplate to build with other firebase plugins ( details are written in description, please check it). I want to know why FCM is only not support using custom GradleTemplate officially ?
  3. Have you already confirmed working plugin build with Unity2020.3 ?

Is there a reason why you have to eliminate this file? Are you trying to do so to avoid the error you saw? I think that error is an unrelated issue.

Because we try to upgrade Unity Version from 2019.4 to 2020.3.
From 2020.3 other firebase plugins need to use customGradleTemplate for build Android app, however FCM use AndroidManifest, so we cant migrate CustomAndroidManifest to custom gradle template.

This occurs when Firebase SDK was not able to locate google-services.json. Quick question: does this occurs to you on Android only or on iOS as well?

This happens on Android device.

For Android, Firebase.Editor.dll would generated an Android resource google-services.xml from google-services.json under Assets/Plugins/Android/FirebaseApp.androidlib. Please check if that folder exists.

I know latest version changed folder name from Assets/Plugins/Android/FirebaseApp.android to Assets/Plugins/Android/FirebaseApp.androidlib.
However, with plugin v6.15.2, it does NOT generate folder Assets/Plugins/Android/FirebaseApp.androidlib but Assets/Plugins/Android/FirebaseApp.android.
We can rename folder temporally, but if UnityEditor try to re-import assets, Assets/Plugins/Android/FirebaseApp.android folder will re-generated.

Lastly, could you confirm if the same issue is reproducible using Firebase quickstart?
I have not enough time to check sample. so it takes long time to check sample again.

What I want to tell you is FCM with other firebase plugins on Unity2019LTS, Android build using CustomAndroidManifest works well, but FCM with other firebase plugins on Unity2020LTS, Android build using custom gradleTemplate does NOT work.

@google-oss-bot google-oss-bot added needs-attention Need Googler's attention and removed needs-info Need information for the developer labels Jun 28, 2021
@chkuang-g
Copy link
Contributor

chkuang-g commented Jul 21, 2021

  1. Did your editor script call reflection method to force turning Custom Main Manifest ON ?

Firebase.Messaging.Editor.dll generates Assets/Plugins/Android/AndroidManifest.xml. When the file exists, you will see Custom Main Manifest be turned on. There is actually no Unity API to flip the switch AFAIK.
However, if Assets/Plugins/Android/AndroidManifest.xml exists in your project before you import Firebase SDK, Firebase.Messaging.Editor.dll will NOT override it. That means you will need to add com.google.firebase.MessagingUnityPlayerActivity activity yourself. We do not have a good way to merge it for you yet. One possible way is to delete this AndroidManifest.xml from your project, let Firebase.Messaging.Editor.dll to generate one and use version-control diff tool to merge the change.

  1. on Unity2020.3 (Unity2020LTS), it requires customGradleTemplate to build with other firebase plugins ( details are written in description, please check it). I want to know why FCM is only not support using custom GradleTemplate officially ?

By customGradleTemplate, do you mean Custom Main Gradle Template, which generates Assets/Plugins/Android/mainTemplate.gradle? If so, FCM should support this with no issue. However, since Unity changed Gradle project structure, you will need to enable Custom Gradle Properties Template as well in order to enable Jetifier. If this is not enabled, you should see a log started with Resolution Failed with this piece of detail in it.

Screen Shot 2021-07-21 at 10 57 36 AM

  1. Have you already confirmed working plugin build with Unity2020.3 ?

Yes. As a matter of fact, I just built FCM quickstart with Firebase Unity SDK 8.0.0 and Unity 2020.3.14f1, installed to my own phone and sent a message from Firebase console. It worked as intended.

You might encounter some obstacles to build it though.

  1. As mentioned, you need to turn on Custom Gradle Properties Template if you want to use Custom Main Gradle Template.
  2. You need to turn on Minify. Unfortunately Unity did not update their doc to explain the new options. Basically you need to check Release and/or Debug under Minify section. By default, Unity uses their in-house minification or Proguard (unfortunately this is not explained anywhere in public doc). If you want to use R8, developed by Google, check Use R8 as well. Either option should work as I tested.

Here is my Player Settings
Screen Shot 2021-07-21 at 11 35 09 AM

Note that the generated Assets/Plugins/Android/AndroidManifest.xml is required to forward Intent from Android service to Android activity to make FirebaseMessaging.MessageReceived event works properly. You can definitely implement your own way to handle Intent. More details here.

Also, I would recommend you to upgrade to the latest Firebase SDK. We fixed a couple of issues for the breaking changes from Unity, ex. Assets/Plugins/Android/FirebaseApp without .androidlib simply won't work in Unity 2020.

I recommend you to try FCM quickstart and see if you can reproduce the issue with it.

If not, please provide a minimum-viable-project to us for debugging, since we were not able to reproduce it from our end.

@chkuang-g chkuang-g added needs-info Need information for the developer and removed needs-attention Need Googler's attention labels Jul 21, 2021
@google-oss-bot google-oss-bot added the stale Don't have recent activity label Jul 28, 2021
@google-oss-bot
Copy link

Hey @Cova8bitdots. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

@google-oss-bot
Copy link

Since there haven't been any recent updates here, I am going to close this issue.

@Cova8bitdots if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.

@firebase firebase locked and limited conversation to collaborators Sep 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api: messaging closed-by-bot needs-info Need information for the developer stale Don't have recent activity type: question
Projects
None yet
Development

No branches or pull requests

4 participants