问题
After I updated the target level for my Android app from 28 to 29 (Android 10) the app crashes on a Pixel 3 (with Android 10).
Versions used
- Android Gradle Plugin 3.5.0
- Gradle 5.5.1
Question: Is this a known issue?
Details
- The crash happens on various layouts using different tags (TextView, androidx.appcompat.widget.AppCompatTextView, etc)
- I use the attribute "android:fontFamily" and reference a font bundled in one of my external libraries.
- The font file,
opensans_regular.ttf
, is placed inres\font
Stacktrace below. For security reasons I've replaced the apps package names with x.y.z.
2019-09-05 14:23:43.530 9060-9060/x.y.z E/AndroidRuntime: FATAL EXCEPTION: main
Process: x.y.z, PID: 9060
java.lang.RuntimeException: Unable to resume activity {x.y.z/x.y.main.devicefinder.BleFindActivity}: android.view.InflateException: Binary XML file line #73 in x.y.z:layout/fragment_add_devices: Binary XML file line #73 in x.y.z:layout/fragment_add_devices: Error inflating class TextView
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4205)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4237)
at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:52)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Caused by: android.view.InflateException: Binary XML file line #73 in x.y.z:layout/fragment_add_devices: Binary XML file line #73 in x.y.z:layout/fragment_add_devices: Error inflating class TextView
Caused by: android.view.InflateException: Binary XML file line #73 in x.y.z:layout/fragment_add_devices: Error inflating class TextView
Caused by: java.lang.IndexOutOfBoundsException: index=0 out of bounds (limit=0, nb=4)
at java.nio.Buffer.checkIndex(Buffer.java:564)
at java.nio.DirectByteBuffer.getInt(DirectByteBuffer.java:570)
at android.graphics.fonts.FontFileUtil.analyzeStyle(FontFileUtil.java:94)
at android.graphics.fonts.Font$Builder.build(Font.java:364)
at android.graphics.Typeface$Builder.build(Typeface.java:596)
at android.content.res.ResourcesImpl.loadFont(ResourcesImpl.java:980)
at android.content.res.Resources.getFont(Resources.java:400)
at android.content.res.TypedArray.getFont(TypedArray.java:1035)
at android.widget.TextView.readTextAppearance(TextView.java:3991)
at android.widget.TextView.<init>(TextView.java:1064)
at android.widget.TextView.<init>(TextView.java:968)
at androidx.appcompat.widget.AppCompatTextView.<init>(AppCompatTextView.java:87)
at androidx.appcompat.widget.AppCompatTextView.<init>(AppCompatTextView.java:83)
at androidx.appcompat.app.AppCompatViewInflater.createTextView(AppCompatViewInflater.java:177)
at androidx.appcompat.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:102)
at androidx.appcompat.app.AppCompatDelegateImpl.createView(AppCompatDelegateImpl.java:1266)
at androidx.appcompat.app.AppCompatDelegateImpl.onCreateView(AppCompatDelegateImpl.java:1316)
at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:242)
at android.view.LayoutInflater.tryCreateView(LayoutInflater.java:1061)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:997)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:961)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1123)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)
at android.view.LayoutInflater.inflate(LayoutInflater.java:682)
at android.view.LayoutInflater.inflate(LayoutInflater.java:534)
at x.y.main.devicefinder.BleFindFragment.onCreateView(BleFindFragment.java:62)
at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2439)
at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1460)
2019-09-05 14:23:43.531 9060-9060/x.y.z E/AndroidRuntime: at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784)
at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852)
at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:802)
at androidx.fragment.app.FragmentManagerImpl.executeOps(FragmentManager.java:2625)
at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2411)
at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2366)
at androidx.fragment.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2273)
at androidx.fragment.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3273)
at androidx.fragment.app.FragmentManagerImpl.dispatchResume(FragmentManager.java:3241)
at androidx.fragment.app.FragmentController.dispatchResume(FragmentController.java:223)
at androidx.fragment.app.FragmentActivity.onResumeFragments(FragmentActivity.java:538)
at androidx.fragment.app.FragmentActivity.onPostResume(FragmentActivity.java:527)
at androidx.appcompat.app.AppCompatActivity.onPostResume(AppCompatActivity.java:172)
at android.app.Activity.performResume(Activity.java:7964)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4195)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4237)
at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:52)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Update 1: I copied the font from the library module and included in the app res folder but still have this issue. So I changed the title to made this question more generic.
Update 2: When using a .otf font it works
回答1:
I've now reported this to Google: https://issuetracker.google.com/issues/140546806 So it now became a known issue I suppose :-)
Update
The root cause: My ttf file was empty(!). I never noticed as older Androids would silently ignore this.
回答2:
Replace your existing fonts with other supporting fonts.
来源:https://stackoverflow.com/questions/57805544/crash-when-using-bundled-ttf-font-on-android-10-android-q