应用更新后In App message引发崩溃问题求助
Problem Context
My app's Firebase In-App Messaging functioned flawlessly until I rolled out a new version. Now, it throws an android.view.InflateException whenever trying to display in-app messages. Oddly enough, if I uninstall the old version first then install the new one, everything works as expected. I've already tried switching to different versions of the Firebase In-App Messaging dependencies, but the issue persists.
Here's the full crash log:
2019-04-29 14:16:34.060 26803-26803/? E/UncaughtException: android.view.InflateException: Binary XML file line #15: Binary XML file line #15: Error inflating class
Caused by: android.view.InflateException: Binary XML file line #15: Error inflating class
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
at android.view.LayoutInflater.createView(LayoutInflater.java:652)
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:742)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:810)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:752)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:883)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:846)
at android.view.LayoutInflater.inflate(LayoutInflater.java:522)
at android.view.LayoutInflater.inflate(LayoutInflater.java:430)
at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
at com.google.firebase.inappmessaging.display.internal.bindingwrappers.ModalBindingWrapper.inflate(com.google.firebase:firebase-inappmessaging-display@@17.1.1:74)
at com.google.firebase.inappmessaging.display.FirebaseInAppMessagingDisplay.inflateBinding(com.google.firebase:firebase-inappmessaging-display@@17.1.1:350)
at com.google.firebase.inappmessaging.display.FirebaseInAppMessagingDisplay.access$400(com.google.firebase:firebase-inappmessaging-display@@17.1.1:82)
at com.google.firebase.inappmessaging.display.FirebaseInAppMessagingDisplay$2.run(com.google.firebase:firebase-inappmessaging-display@@17.1.1:292)
at android.os.Handler.handleCallback(Handler.java:754)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:163)
at android.app.ActivityThread.main(ActivityThread.java:6393)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:933)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
Recommended Solutions
Since the issue only triggers on app updates (not fresh installs), it's almost certainly tied to leftover cached data or resource conflicts from the old version. Try these steps:
Clear Firebase IAM cache on app update
Detect when your app is updated and explicitly clear any cached in-app messaging data. You can implement this in yourApplicationclass or main activity:PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0); long lastUpdateTime = packageInfo.lastUpdateTime; SharedPreferences prefs = getSharedPreferences("AppUpdateTracker", MODE_PRIVATE); long savedUpdateTime = prefs.getLong("last_updated", 0); if (lastUpdateTime > savedUpdateTime) { // Clear cached IAM messages FirebaseInAppMessaging.getInstance().clearMessages(); // Update tracking time prefs.edit().putLong("last_updated", lastUpdateTime).apply(); }Audit for resource conflicts
The inflate error points to layout resource issues. Verify:- Any custom in-app messaging layouts you've defined are fully updated in the new version (no leftover old layout files or duplicate resource IDs).
- There are no conflicting drawables, strings, or styles between the old and new app versions that could break inflation.
Force a clean build
Old build artifacts can cause unexpected conflicts during updates:- Run
./gradlew cleanin your project root to delete stale build files. - Rebuild your project from scratch in Android Studio (
Build > Rebuild Project). - Sync your Gradle files to ensure all Firebase dependencies are correctly resolved (
File > Sync Project with Gradle Files).
- Run
Verify Firebase initialization order
Ensure Firebase is initialized before any in-app messaging code runs. In yourApplicationclass:@Override public void onCreate() { super.onCreate(); FirebaseApp.initializeApp(this); // All other initialization logic comes after this }Improper initialization order can clash with cached state from the old app version.
Test with a newer Firebase IAM SDK version
The error references v17.1.1—try updating to a slightly newer release (like 17.2.0) which may include fixes for update-specific bugs:implementation 'com.google.firebase:firebase-inappmessaging-display:17.2.0'
Debugging Tip
If the above steps don't resolve the issue, enable verbose logging for Firebase IAM to get more context about the inflation failure:
FirebaseInAppMessaging.getInstance().setMessagesSuppressed(false); FirebaseInAppMessagingDisplay.getInstance().setDisplayDebugModeEnabled(true);
This will log detailed information about the layout inflation process, helping you pinpoint the exact class or resource causing the crash.
内容的提问来源于stack exchange,提问作者CodeForMe

