15

I got the following error testing on Android 5.0 (API 21). Tested on other OS versions works well.

java.lang.RuntimeException: Unable to start activity ComponentInfo{...ui.activities.navigationActivity.fragments.legalFragment.LegalDetailActivity}: android.view.InflateException: Binary XML file line #24: Error inflating class android.webkit.WebView

Can't find nothing special about the xml layout, at line 24:

<WebView
    android:id="@+id/nav_fg_legal_detail_web"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
  />

The code:

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)

    setTheme(R.style.AppTheme_NoActionBar)
    setContentView(R.layout.legal_detail_activity) // crash here. Nothing done to web view yet.

I am using library 'androidx.appcompat:appcompat:1.1.0'.

Update: the full stack:

--------- beginning of crash
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.byte_artisan.mchat2, PID: 4198
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.byte_artisan.mchat2/com.byte_artisan.mchat2.ui.activities.navigationActivity.fragments.legalFragment.LegalDetailActivity}: android.view.InflateException: Binary XML file line #24: Error inflating class android.webkit.WebView
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
    at android.app.ActivityThread.access$800(ActivityThread.java:144)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5221)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
 Caused by: android.view.InflateException: Binary XML file line #23: Error inflating class android.webkit.WebView
    at android.view.LayoutInflater.createView(LayoutInflater.java:633)
    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
    at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
    at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
    at com.byte_artisan.mchat2.ui.activities.navigationActivity.fragments.legalFragment.LegalDetailActivity.onCreate(LegalDetailActivity.kt:18)
    at android.app.Activity.performCreate(Activity.java:5937)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360) 
    at android.app.ActivityThread.access$800(ActivityThread.java:144) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:135) 
    at android.app.ActivityThread.main(ActivityThread.java:5221) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at java.lang.reflect.Method.invoke(Method.java:372) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694) 
 Caused by: java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Constructor.newInstance(Native Method)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
    at android.view.LayoutInflater.createView(LayoutInflater.java:607)
    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55) 
    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682) 
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741) 
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:806) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:504) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:414) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:365) 
    at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555) 
    at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161) 
    at com.byte_artisan.mchat2.ui.activities.navigationActivity.fragments.legalFragment.LegalDetailActivity.onCreate(LegalDetailActivity.kt:18) 
    at android.app.Activity.performCreate(Activity.java:5937) 
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105) 
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251) 
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360) 
    at android.app.ActivityThread.access$800(ActivityThread.java:144) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:135) 
    at android.app.ActivityThread.main(ActivityThread.java:5221) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at java.lang.reflect.Method.invoke(Method.java:372) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694) 
 Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x2040002
    at android.content.res.Resources.getText(Resources.java:274)
    at android.content.res.Resources.getString(Resources.java:360)
    at com.android.org.chromium.content.browser.ContentViewCore.setContainerView(ContentViewCore.java:702)
    at com.android.org.chromium.content.browser.ContentViewCore.initialize(ContentViewCore.java:608)
    at com.android.org.chromium.android_webview.AwContents.createAndInitializeContentViewCore(AwContents.java:619)
    at com.android.org.chromium.android_webview.AwContents.setNewAwContents(AwContents.java:758)
    at com.android.org.chromium.android_webview.AwContents.<init>(AwContents.java:608)
    at com.android.org.chromium.android_webview.AwContents.<init>(AwContents.java:546)
    at com.android.webview.chromium.WebViewChromium.initForReal(WebViewChromium.java:312)
    at com.android.webview.chromium.WebViewChromium.access$100(WebViewChromium.java:97)
    at com.android.webview.chromium.WebViewChromium$1.run(WebViewChromium.java:264)
    at com.android.webview.chromium.WebViewChromium$WebViewChromiumRunQueue.drainQueue(WebViewChromium.java:124)
    at com.android.webview.chromium.WebViewChromium$WebViewChromiumRunQueue$1.run(WebViewChromium.java:111)
    at com.android.org.chromium.base.ThreadUtils.runOnUiThread(ThreadUtils.java:144)
    at com.android.webview.chromium.WebViewChromium$WebViewChromiumRunQueue.addTask(WebViewChromium.java:108)
    at com.android.webview.chro
MiguelSlv
  • 14,067
  • 15
  • 102
  • 169

4 Answers4

16

24 April 2020, I solved it with this:

implementation 'androidx.appcompat:appcompat:1.2.0-beta01'

Previous and not working version is below:

implementation 'androidx.appcompat:appcompat:1.1.0'
ChrisF
  • 134,786
  • 31
  • 255
  • 325
canerkaseler
  • 6,204
  • 45
  • 38
7

Recently I faced the same, There is an issue which is mentioned over here, which is not solved yet. The crash only occurs on API 21.

There are few solutions which mention downgrading the androidx.appcompat:appcompat versions. This answer helped me. Also, there are other possible workarounds mentioned, pick the answer that applies to you.

EDIT: The crash also occurs on API 22 and 23 if the user doesn't have Google Play installed.

EDIT 2: As mentioned in the issue tracker here, and upgrading the androidx.appcompat:appcompat version to 1.2.0-alpha02 is providing the fix in some cases. Please go through a detailed discussion to find a suitable workaround.

As mentioned by @MiguelSlv adding this maven repository is a temporary fix, However, all the above workarounds have side effects. As the bug is not fixed yet, it is not a clean solution.

EDIT 3: As of May, 2020, there is a fix.

implementation 'androidx.appcompat:appcompat:1.2.0-beta01'

Previous not working version:

implementation 'androidx.appcompat:appcompat:1.1.0'
Masoom Badi
  • 986
  • 9
  • 18
  • Not sure the issue you mention is the same. In your issue the crash is about a resource. i don't see it on my stack error. – MiguelSlv Jan 03 '20 at 01:30
  • 1
    I think it is similar, please see the other issue and discussion, it is concluded that 1.2.0-alpha02` fixes it. https://issuetracker.google.com/issues/141351441#comment35 – Masoom Badi Jan 03 '20 at 01:40
  • 1
    @MiguelSlv I guess you are facing similar issue from stack track it is clear `Caused by: android.content.res.Resources$NotFoundException: String resource ID` kindly check with the solution provided, I guess it would help – Shadow Droid Jan 03 '20 at 06:04
  • 1
    @Sam. kindly update answer with the point you have mentioned in the comment – Shadow Droid Jan 03 '20 at 06:05
  • alpha01 doesn't fix it for me. I try to use then alpha02 but, for some reason, gradle can't find it. i added maven repository 'https://ci.android.com/builds/submitted/6052626/androidx_snapshot/latest/repository/'. Modifying the constructor can have some side effects.Still looking for a clean solution for my case. – MiguelSlv Jan 03 '20 at 14:02
  • I have updated the answer, the bug is from 2016 and it is still not fixed, so all the solutions are workaround solutions. – Masoom Badi Jan 03 '20 at 16:45
5

This answer I am writing in Mar, 2020, could be changed after that.

In my case , in build.gradle (app level), I changed

implementation 'androidx.appcompat:appcompat:1.0.0'

to

implementation 'androidx.appcompat:appcompat:1.2.0-alpha02'

and the Problem is solved.

Other configuration I already have, but I didn't change them:-

  1. In Gradle project level
classpath 'com.android.tools.build:gradle:3.5.3'
  1. And in gradle-wrapper.properties
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
  1. And in gradle app level
android {
    compileSdkVersion 29
    buildToolsVersion '29.0.2'
    ...
}

Noting that this solution is tested on real device with android version 5

Anbuselvan Rocky
  • 606
  • 6
  • 22
  • thanks for comment... developers who want latest stable version can look this link https://mvnrepository.com/artifact/androidx.appcompat/appcompat?repo=google – Ucdemir Apr 09 '20 at 12:11
  • I used latest androidx... still problem occur have not solved – Ucdemir Apr 14 '20 at 13:31
  • @ Beyaz: if the answer is not working for you, it doesn't not mean it's wrong. as it solved my problem and already up voted by other 2 developers. thanks for understanding – صلي علي محمد - Atef Farouk Apr 14 '20 at 20:10
  • Dear @Atef, I have over ten apps ... All of my apps have crash problem for android 5.1 ... You are telling it worked for you... but you are wrong... I'm still trying fix this bug – Ucdemir Apr 14 '20 at 21:02
  • @ Beyaz: I understand your feedback. appreciated. – صلي علي محمد - Atef Farouk Apr 14 '20 at 21:06
  • Dear @Atef ... maybe it is fixed with implementation 'androidx.appcompat:appcompat:1.2.0-alpha02 but I used latest one androidx.appcompat:appcompat:1.2.0-beta01 where I found from this address https://mvnrepository.com/artifact/androidx.appcompat/appcompat?repo=google But it is weird .. if it is fixed with alpha but occur in beta ??? I will test your suggested implemention and will see result... I'm trying fix this crash nearly for two week... did a lot effort – Ucdemir Apr 15 '20 at 13:09
  • I edited my answer for complete configuration I have. – صلي علي محمد - Atef Farouk Apr 16 '20 at 06:29
0

I have over ten apps, All of my apps have "Inflating problems" I was trying to solve problems... And I have tested with emulators and real device, they have no crash ... But My user thus! Finally while testing with emulator , I catched crash.. Here is result: This answer writing with 19 April 2020:

androidx.appcompat:appcompat:1.2.0-beta01
androidx.appcompat:appcompat:1.2.0-alpha03
androidx.appcompat:appcompat:1.2.0-alpha02

above versions have Serious problems.... Creating dialog, cause Edittext or TextView inflating problems...

below versions have been tested a little but there were no crash

androidx.appcompat:appcompat:1.2.0-alpha01
androidx.appcompat:appcompat:1.1.0 

Still testing this versions , will share results

Ucdemir
  • 2,852
  • 2
  • 26
  • 44