Crash while inflating ongoing-notification layout right after upgrade. Android 10 only - android

It started to happen out of the blue a couple of months ago.
Android 10 only.
After the user upgrades to a new version of our app, a crash happens on launch.
The crash is only observed once for a given user.
So we think the crash happens right after the upgrade to the new build.
It is the new build that crashes (not the old one).
This is an example of a crash.
Fatal Exception: android.app.RemoteServiceException: Bad notification(tag=null, id=30) posted from package yo.app,
crashing app(uid=10613, pid=16365):
Couldn't inflate contentViewsandroid.view.InflateException: Binary XML file line #19 in yo.app:layout/sky_eraser_main:
Binary XML file line #19 in yo.app:layout/sky_eraser_main: Error inflating class androidx.appcompat.widget.Toolbar
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2052)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7710)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:516)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
The crashes look different from build to build.
But the pattern is the same.
Let me transcribe what is happening in our opinion.
There is an ongoing notification (id=30) displaying the temperature (we are making a weather app).
The notification is not able to post because of a crash while inflating its RemoteViews layout.
It seems that the original layout is substituted by another,
completely unrelated layout (sky_eraser_main used in another place of our app).
The wrong layout is different from build to build.
It looks as though integer layout-ids are getting mixed up.
Could it be the result of some weird R8 optimisation?
Unfortunately, we are not able to reproduce the crash locally.
Do you have an idea how to tackle these crashes?
The context
Target SDK: 30
Deployed as Android app bundle.
minifyEnabled = true
This is a kotlin multiplatform project.

From what you've been explaining looks like the resource references got updated as the app launches. This guy has the same problem
Essentially, the R class is an autogenerated class by the whole Android Studio build system that gets autogenerated whenever you add, remove and edit resource files. At the end of the day, each field of the "final" R classes (drawable, id, layout, etc.) hold an int value. And for some dark unknown reasons those references are getting updated at the time you first launch the app after an update on Android 10, (and very probably in Android 11 or some other vendor-dependant implementations of Android)
And as per the comment section in his answer (100+) votes doesn't seem to have a fix. I would try to try-catch the inflation of the layout and abort the notification if I manage to catch any exceptions.
Another approach would be to delay the launch of the notification using something like WorkManager to ensure that the references got updated by the time the NotifyWork kicks in

You may want to explicitly keep the whole class yo.app.R:
-keepattributes InnerClasses
-keep class yo.app.R
-keep class yo.app.R$* {
<fields>;
}

Related

Proguard rule for Huawei push client

I have Unable to create application im.app.android.core.AppDemoApplication: e3.b: com.pushserver.android.huaweiPushClient cant cast com.myApp.android.push_lib.huawei.HcmPushClient to PushClient error
What proguard rule should I add? I have tried -keep class com.myApp.android.push_lib.** { *; } but after that I just see the blank screen - no crash, just stuck when trying to start.
Not really an answer, but too long for a comment. I'll update this answer in case we make progress.
1. What is the "normal bug"?
can't cast com.myApp.android.push_lib.huawei.HcmPushClient to PushClient
This means that somewhere in your code you are assigning/passing an instance of HcmPushClient to something that is expecting it to be a PushClient. I would assume that PushClient is some class that you defined in your project, but is does not extend from HcmPushClient. Try to find this piece of code and fix it or add it here to your question.
2. What does ProGuard have to do with this?
Actually, I think not much. If ProGuard would create this error, the message would look more like
can't cast com.myApp.android.push_lib.a.b to c
But since all class names in the error message are the original ones, it does not seem like ProGuard is making issues here. BUT: You can still decypher the message a little bit, because this part is obfuscated:
Unable to create application im.app.android.core.AppDemoApplication: e3.b:
e3.b refers to a class that was obfuscated by ProGuard. To find out what class it is, you can check the file /build/outputs/mapping/release/mapping.txt in your project folder. This is a simple text file that stores the information what class name was renamed to what obfuscated name. In this file search for -> e3 to find the class that was renamed to e3. Somewhere close to this line, you should also be able to find out what exactly e3.b is. Could be a method, could also be a member variable or an inner class.
I hope these two points will bring you closer to make the app run.

Find View id in source code from Crashlytics crash report

I release an app with Crashlytics inside to send crash report, here is report I received:
"Fatal Exception: java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive a notification.
Make sure the content of your adapter is not modified from a background thread, but only from the UI thread. Make sure your adapter calls notifyDataSetChanged() when its content changes. [in ListView(2131493375, class android.widget.ListView) with Adapter(class com.nhatnq.app.b.cr)]
at android.widget.ListView.layoutChildren(ListView.java)
at android.widget.AbsListView.onLayout(AbsListView.java)
..."
I want to know which Apdater/ListView got this crash, so I want to trace from these things:
"com.nhatnq.app.b.cr": package name is hidden, I can not know. In my app, I have an "ExpandableContactAdapter extends BaseExpandableListAdapter" in package com.nhatnq.app.contact.ExpandableContactAdapter.java, and some Fragments which include adapter such as com.nhatnq.app.fragment.HistoryFragment$ExpandableHistoryAdapter,
com.nhatnq.app.fragment.MessageFragment$ExpandableMessageAdapter,...
ListView(2131493375): this is ID of ListView. I convert this from dec to hex, then find in my local source code (in R.java), but not found this resource ID. Perhaps ID is encoded by time key when release.
What I need to check here, to find correct ListView/Adapter then I can check? Now I have 5 adapters and really do not know what need to check, as this issue only happen on some phones.
I work in a team, other guy take responsible for releasing app from team source code.
Your release "guy" is probably using Proguard or something similar, so the class name is obsfucated (class com.nhatnq.app.b.cr). This is a procedure makes it harder for someone to reverse engineer your code.
You need to ask him to Retrace (or deobfuscate) the code so you can properly identify the class. He should retain files for doing this, in the case of Proguard, here is a reference:
http://simplyadvanced.net/blog/android-how-to-decode-proguards-obfuscated-code-from-stack-trace/

MEDIA_PROJECTION_SERVICE not valid in call to getSystemService()

I am trying to develop an application that requires the ability to capture screen content. I'm targeting lollipop to avoid the requirement for root. When trying to get an instance of the MediaProjectionManager via a call to getSystemService() I am getting the following error reported in Android Studio:
Must be one of: Context.POWER_SERVICE, Context.WINDOW_SERVICE, Context.LAYOUT_INFLATER_SERVICE, Context.ACCOUNT_SERVICE, Context.ACTIVITY_SERVICE, Context.ALARM_SERVICE, Context.NOTIFICATION_SERVICE, Context.ACCESSIBILITY_SERVICE, Context.CAPTIONING_SERVICE, Context.KEYGUARD_SERVICE, Context.LOCATION_SERVICE, Context.SEARCH_SERVICE, Context.SENSOR_SERVICE, Context.STORAGE_SERVICE, Context.WALLPAPER_SERVICE, Context.VIBRATOR_SERVICE, Context.CONNECTIVITY_SERVICE, Context.WIFI_SERVICE, Context.WIFI_P2P_SERVICE, Context.NSD_SERVICE, Context.AUDIO_SERVICE, Context.MEDIA_ROUTER_SERVICE, Context.TELEPHONY_SERVICE, Context.CLIPBOARD_SERVICE, Context.INPUT_METHOD_SERVICE, Context.TEXT_SERVICES_MANAGER_SERVICE, Context.DROPBOX_SERVICE, Context.DEVICE_POLICY_SERVICE, Context.UI_MODE_SERVICE, Context.DOWNLOAD_SERVICE, Context.NFC_SERVICE, Context.BLUETOOTH_SERVICE, Context.USB_SERVICE, Context.INPUT_SERVICE, Context.DISPLAY_SERVICE, Context.USER_SERVICE, Context.PRINT_SERVICE less... (Ctrl+F1)
Reports two types of problems:
* Supplying the wrong type of resource identifier. For example, when calling Resources.getString(int id), you should be passing R.string.something, not R.drawable.something.
* Passing the wrong constant to a method which expects one of a specific set of constants. For example, when calling View#setLayoutDirection, the parameter must be android.view.View.LAYOUT_DIRECTION_LTR or android.view.View.LAYOUT_DIRECTION_RTL.
I am currently at a loss as to why this constant is not considered valid, it's there as an autocomplete option, so it's present, and it's shown in all sample code I have seen for screen capture in lollipop. I have verified that the project setup specifies Android SDK 21 as min and target. Is there something else obvious/stupid I might be missing that would cause this error?
UPDATE: Took the exact same code to Eclipse and it works without issue. So this is related to something in Android Studio specifically it seems.
I get this error while getting Context.BLUETOOTH_SERVICEand the error doc (Must be one of..) contains Context.BLUETOOTH_SERVICE though.
This is not the way Android Studio "1.2" should work. :#
Anyway, its an Inspection bug, Constant and Resource Type mismatch (How in the hell Bluetooth is a resource in android context).
You can suppress this for Class/Method/Statement, for statement, add #SuppressWarnings("ResourceType") above or before the statement.
Another approach:
Goto Settings>>Editor>>Inspection>>Android>>Constant and Resource Type Mismatches and make the severity to anything but Error, probably Warning or Weak Warning.
(Though it fixes the error issue, but I want this mismatch to be an error when it really happens.)
Run into the same problem, it is so strange, there are no any other threads talking about this problem.
Well, actually you can just ignore this error and still run the program, even with
the red marks on it

AndroidAnnotations cannot find symbol class

I'm using AndroidAnnotations in an Android Studio gradle project. I currently get error output from AA during compilation that says:
cannot find symbol class MyActivity_
The error output does not prevent building the application - its not really a compile error because the class is there, it seems that it is just an unfortunate timing issue with the compilation process.
Is there anything I can do to avoid these false-positive errors from AA? When there are "fake" errors shown every time I compile, its very easy to miss the real errors.
I had same error. To solve it I have revert my last changes and it has worked again.
I think it was either wrong optimized import(you must import generated classes eg. xxx_) or I injected layout by id what was not existed in the layout xml
Update
I figured it. My problem was what I had use private mofidier instead of proteced in
#ViewById(R.id.list)
private ListView list;
Try to see if you missed to fix some errors in the class MainActivity or in someone of his Bean member that you have annoted.
The problem doesn't have to be in MainActivty, but it is probably because of a private modifier which is used with Android Anotations (in injection, method declaration etc) somewhere in your code

Why am I getting "can't find view" exceptions when the layout hasn't changed?

I'm working on one of my android widgets, which uses LauncherPlus to add scrolling functionality, and am running into a frustrating issue. My currently published version of the code, again using LauncherPlus, is working well, scrolling and all. I'm adding a requested feature, one which allows changing text sizes, but an exception is thrown when I test the update. There exception is:
mobi.intuitit.android.widget.SimpleRemoteViews$ActionException: can't find view:0x7f070041
I haven't changed anything in the layouts and the only code change references a view id which was already referenced in that same section of code. I looked through the R.java and found which resource was referred to and again, nothing has changed there. Here's the bit of code where the issue is coming from:
itemViews.setBoundBitmap(R.id.profile, "setImageBitmap", SonetProvider.SonetProviderColumns.profile.ordinal(), 0);
itemViews.setBoundCharSequence(R.id.friend, "setText", SonetProvider.SonetProviderColumns.friend.ordinal(), 0);
itemViews.setBoundCharSequence(R.id.created, "setText", SonetProvider.SonetProviderColumns.createdtext.ordinal(), 0);
itemViews.setBoundCharSequence(R.id.message, "setText", SonetProvider.SonetProviderColumns.message.ordinal(), 0);
The exception is thrown when applying the first line. Out of curiosity, I changed the order of these lines, and each one of them will cause the exception, though again, the layout hasn't changed. After the exception is thrown the widget will build successfully, but I can't publish this update with an exception (force close) being thrown. Any ideas why there is a resource issue? Thanks!
UPDATE:
I found this discussion where it seems that widget resources may not be reloaded on application updates:
http://groups.google.com/group/android-developers/browse_thread/thread/55a8e44974e8c6ad?fwc=1&pli=1
Does anyone have any experience with this, or a workaround? This may be what I'm facing.
Use Project > Clean in Eclipse or ant clean from the command line, then try again. Since resource IDs are integers, they are inlined in the bytecode of the classes that reference them, and so sometimes your pre-compiled classes can get out of sync with new resource IDs from a fresh compile. I work from the command line mostly, and I always tack clean onto my ant commands (e.g., ant clean install) to avoid this problem.

Categories

Resources