Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Downloadable fonts for Android dev and "Chrome has Stopped" error

As part of the new downloadable fonts support in Oreo and the Support Library, I have started incorporating the functionality into the apps I develop. The first app was successful - straightforward app with just a few activities. The second app was not successful. After adding the downloadable fonts (based on the this resource: https://developer.android.com/guide/topics/ui/look-and-feel/downloadable-fonts.html) I encounter this error when launching an activity:

01-05 13:48:50.849 1112-16753/? I/ActivityManager: Start proc 22862:com.android.chrome:sandboxed_process0/u0i247 for webview_service edu.bsu.android.apps.traveler/org.chromium.content.app.SandboxedProcessService0

01-05 13:48:51.047 22862-22862/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.android.chrome:sandboxed_process0, PID: 22862 android.content.res.Resources$NotFoundException: Array resource ID #0x7f030030
at android.content.res.Resources.obtainTypedArray(Resources.java:618)
at android.content.res.Resources.preloadFonts(Resources.java:380)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5769)
at android.app.ActivityThread.-wrap1(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1656)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.WebViewZygoteInit.main(WebViewZygoteInit.java:146)

The app does not crash, but a popup appears twice stating "Chrome has stopped" - Open app again or Send feedback.

Based on the stacktrace, resource ID #0x7f030030 is the following entry in R.java (which I expect):

public static final int preloaded_fonts=0x7f030030;

I believe I have identified the cause of the error - again, the error states Chrome has the problem, but yet this occurs in my app:

  • The layout for the activity contains a TextView with an autoLink attribute of "web", "map" or "all".
  • I preload the fonts in the manifest based on the document referenced above.

Eliminating either the preload declaration in the manifest or removing the autoLink attribute resolves the issue. TextViews that do not use "web", "map" or "all" for the autoLink attribute do not generate the error ("phone" works, which I would expect since it isn't a web-based intent). Obviously neither is an ideal solution. This only occurs on the initial launch of the app.

Again, the first app worked fine with the same fonts, preloading in the manifest, and using the autoLink attribute. There are differences between the working and non-working apps however:

  • The non-working app is a large app, so it uses the multidex library, whereas the working app does not.
  • The non-working app is localized and designed for multiple devices, so it includes both an English and German language values directories as well as screen size dependent values directories. The working app does not use multiple values resource folders.

In order to resolve this issue, I have tried the following:

  • Thinking the ResourceID was conflicting with something, I created a brand new resource for the font array, which created a new ID. Error still occurred.
  • Added the font array XML file to all values folders in the project, regardless of screen size or localization. Error still occurred.
  • Tried different fonts and just a single font. Error still occurred.
  • Removed the "web", "map", and "all" autoLink value from TextViews. Error went away.
  • Removed the preload_fonts meta tag from the manifest. Error went away.

I found an issue tracker somewhat related to this problem (I am the most recent submission on the tracker, however it was before I fully understood the complexity of the problem): https://issuetracker.google.com/u/1/issues/65575496

I have tested the app generating the error on the following devices and the "Chrome has stopped" error appears only on the Oreo devices. The "easy" app works on all devices, no errors reported.

  • Pixel 2 XL, 8.1.0 - error
  • Nexus 5X, 8.1.0 - error
  • Nexus 6, 7.1.1 - no error with either app

Both apps have the following gradle configs:

compileSdkVersion 27
buildToolsVersion '27.0.3'
minSdkVersion 16
targetSdkVersion 27
supportLibraryVersion = "27.0.2"
playServicesVersion = "11.8.0"

Is there a solution to this problem (other not preloading fonts or using the web, map or all autoLink attribute) or is this related to the issue tracker mentioned earlier?

like image 990
Kyle Avatar asked Jan 05 '18 20:01

Kyle


1 Answers

This issue might have the same root cause with this existing bug related to WebView updates on Play Store. TextView/Linkify uses a WebView for address recognition.

Linkify.MAP_ADDRESSES does not work properly and works only for US addresses. Please do not use Linkify.MAP_ADDRESSES or Linkify.ALL (or the attributes for them) if possible.

like image 81
Siyamed Avatar answered Nov 06 '22 18:11

Siyamed