google / play-unity-plugins

The Google Play Plugins for Unity provide C# APIs for accessing various Play services
Other
432 stars 110 forks source link

Instantly crash when opening the app. "java.lang.ClassNotFoundException" for Firebase Messaging. #136

Open CloudAktsk opened 3 years ago

CloudAktsk commented 3 years ago

I enable the AssetDeliveryConfig.SplitBaseModuleAssets = true (which equals to toggle on the "Separate Base APK Asset" in Editor UI) and build the AAB file, install it to my device. The app will instantly crash showing this screen: image

I use adb logcat to see the logs, looks like here is the error java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/firebase/iid/zzao java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.MessagingUnityPlayerActivity"

Firebase works well in my project before I import google play-unity-plugins and enable the "Separate Base APK Asset". What went wrong between Firebase and this plugins?

I've tried this https://github.com/google/play-unity-plugins/issues/127#issuecomment-884590146. I created a folder under "assets/bin/Data/Managed" but it still not work.

Unity Version: 2019.4.21.f1 Plugin Version: v1.5.0

jamcohen commented 3 years ago

Hi @CloudAktsk,

Thanks for reaching out.

A couple clarifying questions:

To diagnose the missing class error you could open the AAR in Android Studio to inspect the base/dex/classes.dex file. In there you can see all the java classes/methods that were included in your build: Screen Shot 2021-08-13 at 1 22 19 PM

CloudAktsk commented 3 years ago

Hi, @jamcohen. Thanks for your reply.

If you build with Mono instead of IL2CPP, do you get the same issue?

Yes, Mono didn't change the result.

If you build with "Separate Base APK Asset" unchecked, do you get the same issue?

NO! If "Separate Base APK Asset" is unchecked, everything works fine as usual. But my APK will exceeds the 150 MB limit. 😞

When you use the fix in #127, do you still get the "Unable to initialize the Unity Engine" error, or just the "Didn't find class" error?

Both of them! the fix in #127 didn't change any result.

I've tried to inspect the class from my AAB in the dex file. Looks like the "Lcom/google/firebase/iid/zzao" class is exist. So I have no idea what cause the "Didn't find class" error. aab-1

By the way, I compared it with the AAB which "Separate Base APK Asset" is unchecked and workable, It looks identical except the base/assets & base_assets/assets separate part. aab-2

I've fought for this for 3 days and still can't get any progress, any suggestion would be appreciated.

jamcohen commented 3 years ago

I tried to repro on my end and I was briefly able to reproduce a similar issue (java.lang.NoClassDefFoundError). I solved it by running Assets -> External Dependency Manager -> Android Resolver -> Force Resolve.

I doubt that will solve your issue though because I was getting the error even when "Separate Base APK Asset" was unchecked.

If you had a sample project that reproduced the issue, you could email it to play-unity-plugin-support@googlegroups.com and I could take another look.