I have a small app that tries to run WebView as follows:
public View onCreateView(#NonNull LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_photo_page, container, false);
mWebView = v.findViewById(R.id.web_view);
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mWebView.setWebViewClient(new WebViewClient());
mWebView.loadUrl(mUri.toString());
return v;
}
When i try to run it on an API 24 device that doesn't have google services the WebView works, but for some reason doesn't enable JavaScript, even though setJavaScriptEnabled(true) is used. When i try to perform the same on an API 24 device with google service, the WebView works well and can see JavaScript code. But the oddities don't end there...
In cases when i run the app on a devices that have API lower than 24 (i tried on 23 and 22) possession of google service doesn't influence JavaScript code processing by the WebView. In Either cases JavaScript doesn't work in the WebView for some reason.
API 25 has the same issues as 24 does.
API 26 bring something new. When i perform testing on a device with google services the works well. But without them the app just crashes while inflating writing to logcat the following:
E/WebViewFactory: Chromium WebView package does not exist
android.webkit.WebViewFactory$MissingWebViewPackageException: Failed to load WebView provider: No WebView installed
at android.webkit.WebViewFactory.getWebViewContextAndSetProvider(WebViewFactory.java:334)
at android.webkit.WebViewFactory.getProviderClass(WebViewFactory.java:398)
at android.webkit.WebViewFactory.getProvider(WebViewFactory.java:211)
at android.webkit.WebView.getFactory(WebView.java:2467)
at android.webkit.WebView.ensureProviderCreated(WebView.java:2462)
at android.webkit.WebView.setOverScrollMode(WebView.java:2527)
at android.view.View.<init>(View.java:4536)
at android.view.View.<init>(View.java:4668)
at android.view.ViewGroup.<init>(ViewGroup.java:597)
at android.widget.AbsoluteLayout.<init>(AbsoluteLayout.java:55)
at android.webkit.WebView.<init>(WebView.java:636)
at android.webkit.WebView.<init>(WebView.java:581)
at android.webkit.WebView.<init>(WebView.java:564)
at android.webkit.WebView.<init>(WebView.java:551)
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
at android.view.LayoutInflater.createView(LayoutInflater.java:647)
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:720)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:788)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at com.bignerdranch.android.photogallery.PhotoPageFragment.onCreateView(PhotoPageFragment.java:41)
at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2963)
at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:518)
at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:282)
at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2189)
at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:2100)
at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:2002)
at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:3138)
at androidx.fragment.app.FragmentManager.dispatchActivityCreated(FragmentManager.java:3072)
at androidx.fragment.app.FragmentController.dispatchActivityCreated(FragmentController.java:251)
at androidx.fragment.app.FragmentActivity.onStart(FragmentActivity.java:502)
at androidx.appcompat.app.AppCompatActivity.onStart(AppCompatActivity.java:248)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1333)
at android.app.Activity.performStart(Activity.java:6992)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2780)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.bignerdranch.android.photogallery, PID: 8470
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.bignerdranch.android.photogallery/com.bignerdranch.android.photogallery.PhotoPageActivity}: android.view.InflateException: Binary XML file line #16: Binary XML file line #16: Error inflating class android.webkit.WebView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: android.view.InflateException: Binary XML file line #16: Binary XML file line #16: Error inflating class android.webkit.WebView
Caused by: android.view.InflateException: Binary XML file line #16: Error inflating class android.webkit.WebView
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
at android.view.LayoutInflater.createView(LayoutInflater.java:647)
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:720)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:788)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at com.bignerdranch.android.photogallery.PhotoPageFragment.onCreateView(PhotoPageFragment.java:41)
at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2963)
at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:518)
at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:282)
at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2189)
at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:2100)
at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:2002)
at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:3138)
at androidx.fragment.app.FragmentManager.dispatchActivityCreated(FragmentManager.java:3072)
at androidx.fragment.app.FragmentController.dispatchActivityCreated(FragmentController.java:251)
at androidx.fragment.app.FragmentActivity.onStart(FragmentActivity.java:502)
at androidx.appcompat.app.AppCompatActivity.onStart(AppCompatActivity.java:248)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1333)
at android.app.Activity.performStart(Activity.java:6992)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2780)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
E/AndroidRuntime: Caused by: android.util.AndroidRuntimeException: android.webkit.WebViewFactory$MissingWebViewPackageException: Failed to load WebView provider: No WebView installed
at android.webkit.WebViewFactory.getProviderClass(WebViewFactory.java:438)
at android.webkit.WebViewFactory.getProvider(WebViewFactory.java:211)
at android.webkit.WebView.getFactory(WebView.java:2467)
at android.webkit.WebView.ensureProviderCreated(WebView.java:2462)
at android.webkit.WebView.setOverScrollMode(WebView.java:2527)
at android.view.View.<init>(View.java:4536)
at android.view.View.<init>(View.java:4668)
at android.view.ViewGroup.<init>(ViewGroup.java:597)
at android.widget.AbsoluteLayout.<init>(AbsoluteLayout.java:55)
at android.webkit.WebView.<init>(WebView.java:636)
at android.webkit.WebView.<init>(WebView.java:581)
at android.webkit.WebView.<init>(WebView.java:564)
at android.webkit.WebView.<init>(WebView.java:551)
... 35 more
Caused by: android.webkit.WebViewFactory$MissingWebViewPackageException: Failed to load WebView provider: No WebView installed
at android.webkit.WebViewFactory.getWebViewContextAndSetProvider(WebViewFactory.java:334)
at android.webkit.WebViewFactory.getProviderClass(WebViewFactory.java:398)
... 47 more
On API 27 devices the WebView can see JavaScript even if there are no google services.
All tests was performed on Nexus 5X.
In cases when WebView doesn't process JavaScript i tried to add the following code:
webSettings.setDomStorageEnabled(true);
webSettings.setLoadWithOverviewMode(true);
webSettings.setUseWideViewPort(true);
webSettings.setBuiltInZoomControls(true);
webSettings.setDisplayZoomControls(false);
webSettings.setSupportZoom(true);
webSettings.setDefaultTextEncodingName("utf-8");
mWebView.setWebChromeClient(new WebChromeClient());
and also change the device to another one. Nothing of mentioned above fixed the problem.
So my questions are:
How google services impact possibility to see JavaScript for WebView ?
Why can't WebView be inflated in API 26. It is placed in android so i have to be able to inflate it. Isn't it so ?
And finally. How do i have to use WebView correctly so that it can see JavaScript and not get crashed across all API's ?
Before starting the Fragment or Activity, make sure that the WebView is installed or active.
public static boolean webViewEnabled() {
try {
return CookieManager.getInstance() != null;
} catch (Exception e) {
return false;
}
}
public static boolean appInstalledOrNot(String uri) {
PackageManager pm = ApplicationLoader.getContext().getPackageManager();
boolean app_installed = false;
try {
pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
app_installed = true;
} catch (PackageManager.NameNotFoundException ignored) {
}
return app_installed;
}
Checking if WebView is installed or active (you can even display a suitable response to the user:
if (!webViewEnabled()) {
if (appInstalledOrNot("com.google.android.webview")) {
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uri = Uri.fromParts("package", "com.google.android.webview", null);
intent.setData(uri);
startActivity(intent);
} else if (appInstalledOrNot("com.huawei.webview")) {
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uri = Uri.fromParts("package", "com.huawei.webview", null);
intent.setData(uri);
startActivity(intent);
} else if (appInstalledOrNot("com.android.vending")) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setPackage("com.android.vending");
intent.setData(Uri.parse("market://details?id=com.google.android.webview"));
startActivity(intent);
} else if (appInstalledOrNot("com.huawei.appmarket")) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setPackage("com.huawei.appmarket");
intent.setData(Uri.parse("appmarket://details?id=com.huawei.webview"));
startActivity(intent);
} else {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("https://play.google.com/store/apps/details?id=com.google.android.webview"));
try {
startActivity(intent);
} catch (Exception exception) {
//
}
}
} else {
// startActivity(new Intent(this, WebViewActivity.class)) or ...
}
Related
I am currently having trouble accessing my dropbox account via android studio. I intend to use dropbox to store photos that the user uploads into my application, then store the dropbox filename inside of the database. I have tested this code on Eclipse, and it works like a charm. But I simply cannot get it to work in android studio. I assume I am missing a step somewhere in android studio... but I cannot find what that step may be. I would appreciate any help.
I have added the following to my build.gradle
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.dropbox.core:dropbox-core-sdk:3.1.1'
I have also added this to my android manifest under the package.
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
Here is the simple code I am attempting to execute. Note that I have my ACCESS_TOKEN stored as a final string, and it does contain the correct access token (as I mentioned previously, I can run this code (and more) perfectly in eclipse).
public void dropbox(){
DbxRequestConfig config = DbxRequestConfig.newBuilder("myapp").build();
DbxClientV2 client = new DbxClientV2(config, ACCESS_TOKEN);
FullAccount account = null;
try {
account = client.users().getCurrentAccount(); //This is where my error occurs
} catch (DbxException e) {
e.printStackTrace();
}
Log.d("test",account.getName().getDisplayName());
}
Here is the full error message I get.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.sigm.fetchyourpet, PID: 8294
java.lang.IllegalStateException: Could not execute method for android:onClick
at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:402)
at android.view.View.performClick(View.java:6597)
at android.view.View.performClickInternal(View.java:6574)
at android.view.View.access$3100(View.java:778)
at android.view.View$PerformClick.run(View.java:25885)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:397)
at android.view.View.performClick(View.java:6597)
at android.view.View.performClickInternal(View.java:6574)
at android.view.View.access$3100(View.java:778)
at android.view.View$PerformClick.run(View.java:25885)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: android.os.NetworkOnMainThreadException
at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1513)
at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:117)
at java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java:105)
at java.net.InetAddress.getAllByName(InetAddress.java:1154)
at com.android.okhttp.Dns$1.lookup(Dns.java:39)
at com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:175)
at com.android.okhttp.internal.http.RouteSelector.nextProxy(RouteSelector.java:141)
at com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java:83)
at com.android.okhttp.internal.http.StreamAllocation.findConnection(StreamAllocation.java:174)
at com.android.okhttp.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:126)
at com.android.okhttp.internal.http.StreamAllocation.newStream(StreamAllocation.java:95)
at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:281)
at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:224)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:461)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:127)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:258)
at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getOutputStream(DelegatingHttpsURLConnection.java:218)
at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:26)
at com.dropbox.core.http.StandardHttpRequestor.getOutputStream(StandardHttpRequestor.java:132)
at com.dropbox.core.http.StandardHttpRequestor.access$000(StandardHttpRequestor.java:29)
at com.dropbox.core.http.StandardHttpRequestor$Uploader.<init>(StandardHttpRequestor.java:141)
at com.dropbox.core.http.StandardHttpRequestor.startPost(StandardHttpRequestor.java:73)
at com.dropbox.core.http.StandardHttpRequestor.startPost(StandardHttpRequestor.java:29)
at com.dropbox.core.DbxRequestUtil.startPostRaw(DbxRequestUtil.java:275)
at com.dropbox.core.v2.DbxRawClientV2$1.execute(DbxRawClientV2.java:146)
at com.dropbox.core.v2.DbxRawClientV2.executeRetriable(DbxRawClientV2.java:330)
at com.dropbox.core.v2.DbxRawClientV2.executeRetriableWithRefresh(DbxRawClientV2.java:351)
at com.dropbox.core.v2.DbxRawClientV2.rpcStyle(DbxRawClientV2.java:137)
at com.dropbox.core.v2.users.DbxUserUsersRequests.getCurrentAccount(DbxUserUsersRequests.java:120)
at com.sigm.fetchyourpet.MainActivity.dropbox(MainActivity.java:63)
at com.sigm.fetchyourpet.MainActivity.signUp(MainActivity.java:174)
at java.lang.reflect.Method.invoke(Native Method)
at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:397)
at android.view.View.performClick(View.java:6597)
at android.view.View.performClickInternal(View.java:6574)
at android.view.View.access$3100(View.java:778)
at android.view.View$PerformClick.run(View.java:25885)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
This happens because you are running an HTTP request on the main thread, the easy fix:
Thread thread = new Thread() {
#Override
public void run() {
try {
FullAccount account = client.users().getCurrentAccount();
Log.d("test",account.getName().getDisplayName());
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
thread.start();
I'm following MabBox tutorial at https://docs.mapbox.com/help/tutorials/android-navigation-sdk/ to make a simple navigation fragment that use the basics elements of it.
I already know that MapBox require to instantiate before inflating the View because I made it before on another Fragment to test it out where the fragment is part of a TabLayout component, however, in this one, there's only one Activity that loads the Fragment where I use the SDK and in this case it throws the same error that I fixed previously because I put it afterinflating the layout.
The errore that appears is this one:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.parkingclientapplication, PID: 14257
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.parkingclientapplication/com.example.parkingclientapplication.activities.MapDirectionActivity}: android.view.InflateException: Binary XML file line #8: Binary XML file line #8: Error inflating class com.mapbox.mapboxsdk.maps.MapView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: android.view.InflateException: Binary XML file line #8: Binary XML file line #8: Error inflating class com.mapbox.mapboxsdk.maps.MapView
Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class com.mapbox.mapboxsdk.maps.MapView
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
at android.view.LayoutInflater.createView(LayoutInflater.java:647)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.example.parkingclientapplication.activities.MapDirectionActivity.onCreate(MapDirectionActivity.kt:15)
at android.app.Activity.performCreate(Activity.java:6975)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: com.mapbox.mapboxsdk.exceptions.MapboxConfigurationException:
Using MapView requires calling Mapbox.getInstance(Context context, String accessToken) before inflating or creating the view. The access token parameter is required when using a Mapbox service.
Please see https://www.mapbox.com/help/create-api-access-token/ to learn how to create one.
More information in this guide https://www.mapbox.com/help/first-steps-android-sdk/#access-tokens.
at com.mapbox.mapboxsdk.Mapbox.validateMapbox(Mapbox.java:165)
at com.mapbox.mapboxsdk.Mapbox.getAccessToken(Mapbox.java:77)
at com.mapbox.mapboxsdk.storage.FileSource.<init>(FileSource.java:234)
at com.mapbox.mapboxsdk.storage.FileSource.getInstance(FileSource.java:68)
at com.mapbox.mapboxsdk.maps.renderer.MapRenderer.<init>(MapRenderer.java:34)
E/AndroidRuntime: at com.mapbox.mapboxsdk.maps.renderer.glsurfaceview.GLSurfaceViewMapRenderer.<init>(GLSurfaceViewMapRenderer.java:33)
at com.mapbox.mapboxsdk.maps.MapView$5.<init>(MapView.java:294)
at com.mapbox.mapboxsdk.maps.MapView.initialiseDrawingSurface(MapView.java:294)
at com.mapbox.mapboxsdk.maps.MapView.initialize(MapView.java:137)
at com.mapbox.mapboxsdk.maps.MapView.<init>(MapView.java:100)
... 25 more
The code for the Activity is:
class MapDirectionActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_map_direction)
supportFragmentManager.inTransaction {
add(R.id.form_clientNavMenu, MapDirectionFragment())
}
//Logout action on custom toolbar layout
logout.setOnClickListener {
val intent = Intent(this, MainActivity::class.java)
startActivity(intent)
}
}
}
The code for the onCreateView method of the Fragment is:
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
Mapbox.getInstance(context!!, getString(R.string.access_token))
val view = inflater.inflate(R.layout.fragment_map_direction, container, false)
mapView = view.findViewById(R.id.mapView)
mapView.onCreate(savedInstanceState)
mapView.getMapAsync(this)
// Inflate the layout for this fragment
return view
}
I only wrote onCreateView method because I think the error could be in there instead on the rest of the code which is the same as in the link, but I could be wrong.
Set the method:
Mapbox.getInstance(this,getString(R.string.access_token));
Before the:
setContentView(R.layout.activity_map);
If you having this exception change code structure as follows.
i.e:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Mapbox.getInstance(this,getString(R.string.access_token));
setContentView(R.layout.activity_map);
mapView = (MapView) findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(mapboxMap -> mapboxMap.setStyle(
new Style.Builder().fromUrl(Style.MAPBOX_STREETS)
));
}
Thanks #Tobrun for the answer, the problem was not that I missed the accessToken but I mixed activity and fragment layout so the components in one of them should be in the other. However, looking for the accessToken made me realize about other possible ones.
In the Navigation Library version alpha09+ (using alpha11) I am experiencing a ClassNotFoundException for one of my data classes which I defined as an argType in my navigation graph.
app:argType="com.package.app.data.model.user.User.Full"
This class does exist. When downgrading back to alpha08, the issue does not appear to happen.
This is the full stacktrace:
2019-01-28 10:30:32.028 6970-6970/com.package.app.debug E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.package.app.debug, PID: 6970
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.package.app.debug/com.package.app.ui.MainActivity}: android.view.InflateException: Binary XML file line #53: Binary XML file line #53: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: android.view.InflateException: Binary XML file line #53: Binary XML file line #53: Error inflating class fragment
Caused by: android.view.InflateException: Binary XML file line #53: Error inflating class fragment
Caused by: java.lang.RuntimeException: Exception inflating com.package.app.debug:navigation/navigation_main line 376
at androidx.navigation.NavInflater.inflate(NavInflater.java:89)
at androidx.navigation.NavController.setGraph(NavController.java:424)
at androidx.navigation.NavController.setGraph(NavController.java:406)
at androidx.navigation.fragment.NavHostFragment.onCreate(NavHostFragment.java:226)
at androidx.fragment.app.Fragment.performCreate(Fragment.java:2414)
at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1418)
at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1684)
at androidx.fragment.app.FragmentManagerImpl.addFragment(FragmentManager.java:1930)
at androidx.fragment.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3745)
at androidx.fragment.app.FragmentController.onCreateView(FragmentController.java:120)
at androidx.fragment.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:405)
at androidx.fragment.app.FragmentActivity.onCreateView(FragmentActivity.java:387)
at co.lokalise.android.sdk.core.LokaliseLayoutInflater$PrivateWrapperFactory2.onCreateView(LokaliseLayoutInflater.java:362)
at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:186)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:780)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at co.lokalise.android.sdk.core.LokaliseLayoutInflater.inflate(LokaliseLayoutInflater.java:84)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.package.app.ui.MainActivity.onCreate(MainActivity.kt:75)
at android.app.Activity.performCreate(Activity.java:7136)
at android.app.Activity.performCreate(Activity.java:7127)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
2019-01-28 10:30:32.031 6970-6970/com.package.app.debug E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.RuntimeException: java.lang.ClassNotFoundException: com.package.app.data.model.user.User.Full
at androidx.navigation.NavType.fromArgType(NavType.java:180)
at androidx.navigation.NavInflater.inflateArgument(NavInflater.java:181)
at androidx.navigation.NavInflater.inflateArgumentForDestination(NavInflater.java:145)
at androidx.navigation.NavInflater.inflate(NavInflater.java:120)
at androidx.navigation.NavInflater.inflate(NavInflater.java:131)
at androidx.navigation.NavInflater.inflate(NavInflater.java:80)
... 41 more
Caused by: java.lang.ClassNotFoundException: com.package.app.data.model.user.User.Full
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:453)
at java.lang.Class.forName(Class.java:378)
at androidx.navigation.NavType.fromArgType(NavType.java:168)
... 46 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.package.app.data.model.user.User.Full" on path: DexPathList[[zip file "/system/framework/org.apache.http.legacy.boot.jar", zip file "/data/app/com.package.app.debug-7IobagfWCqi3XccTjnUgwg==/base.apk", zip file "/data/app/com.package.app.debug-7IobagfWCqi3XccTjnUgwg==/split_lib_dependencies_apk.apk", zip file "/data/app/com.package.app.debug-7IobagfWCqi3XccTjnUgwg==/split_lib_resources_apk.apk", zip file "/data/app/com.package.app.debug-7IobagfWCqi3XccTjnUgwg==/split_lib_slice_0_apk.apk", zip file "/data/app/com.package.app.debug-7IobagfWCqi3XccTjnUgwg==/split_lib_slice_1_apk.apk", zip file "/data/app/com.package.app.debug-7IobagfWCqi3XccTjnUgwg==/split_lib_slice_2_apk.apk", zip file "/data/app/com.package.app.debug-7IobagfWCqi3XccTjnUgwg==/split_lib_slice_3_apk.apk", zip file "/data/app/com.package.app.debug-7IobagfWCqi3XccTjnUgwg==/split_lib_slice_4_apk.apk", zip file "/data/app/com.package.app.debug-7IobagfWCqi3XccTjnUgwg==/split_lib_slice_5_apk.apk", zip file "/data/app/com.package.app.debug-7IobagfWCqi3XccTjnUgwg==/split_lib_slice_6_apk.apk", zip file "/data/app/com.package.app.debug-7IobagfWCqi3XccTjnUgwg==/split_lib_slice_7_apk.apk", zip file "/data/app/com.package.app.debug-7IobagfWCqi3XccTjnUgwg==/split_lib_slice_8_apk.apk", zip file "/data/app/com.package.app.debug-7IobagfWCqi3XccTjnUgwg==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.package.app.debug-7IobagfWCqi3XccTjnUgwg==/lib/x86, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
... 50 more
Suppressed: java.io.IOException: No original dex files found for dex location /data/app/com.package.app.debug-7IobagfWCqi3XccTjnUgwg==/split_lib_resources_apk.apk
at dalvik.system.DexFile.openDexFileNative(Native Method)
at dalvik.system.DexFile.openDexFile(DexFile.java:354)
at dalvik.system.DexFile.<init>(DexFile.java:101)
at dalvik.system.DexFile.<init>(DexFile.java:75)
at dalvik.system.DexPathList.loadDexFile(DexPathList.java:394)
at dalvik.system.DexPathList.makeDexElements(DexPathList.java:354)
at dalvik.system.DexPathList.<init>(DexPathList.java:164)
2019-01-28 10:30:32.031 6970-6970/com.package.app.debug E/AndroidRuntime: at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:74)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:65)
at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:64)
at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:73)
at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:88)
at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:74)
at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:40)
at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:727)
at android.app.LoadedApk.getClassLoader(LoadedApk.java:810)
at android.app.LoadedApk.getResources(LoadedApk.java:1032)
at android.app.ContextImpl.createAppContext(ContextImpl.java:2345)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5749)
at android.app.ActivityThread.access$1100(ActivityThread.java:199)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1650)
... 6 more
I have updated the Navigation Library component from alpha08 to alpha11. When they released alpha09, I also updated and had this same issue and thought it was a bug, so I waited. Now, the issue still persists and I can't seem to be able to figure out want went wrong.
I have already disabled ProGuard for debugging, as well as minify and have enabled Multidex to see if this would help.
debug {
minifyEnabled false
useProguard false
versionNameSuffix '-DEBUG'
applicationIdSuffix '.debug'
}
The class has also been added to the proguard-rules, to see if that would work.
-keep class com.package.app.data.model.** { *; }
As far as I'm concerned, this should work? Android Studio also generates the XML for me exactly like this.
Thanks in advance.
After all, it was a known bug in Android Studio.
Since the release of 1.0.0-alpha09, something changed in the way they handled inner classes.
If a parcelable is an inner class, it has to be written like:
com.domain.app.User$Full where Full is the parcelized object.
If you want to read more about this, check out this answer on Google's Issue Tracker: https://issuetracker.google.com/u/2/issues/123614632#comment4
Just faced problem similar to this issue and I got realized I didn't set up any proguard rules. Here's additional information that might be helpful.
The following codes are found in navigation component version 2.2.0-rc02.
// NavType.java
try {
String className;
if (type.startsWith(".") && packageName != null) {
className = packageName + type;
} else {
className = type;
}
if (type.endsWith("[]")) {
className = className.substring(0, className.length() - 2);
Class<?> clazz = Class.forName(className);
if (Parcelable.class.isAssignableFrom(clazz)) {
return new ParcelableArrayType(clazz);
} else if (Serializable.class.isAssignableFrom(clazz)) {
return new SerializableArrayType(clazz);
}
} else {
Class<?> clazz = Class.forName(className);
if (Parcelable.class.isAssignableFrom(clazz)) {
return new ParcelableType(clazz);
} else if (Enum.class.isAssignableFrom(clazz)) {
return new EnumType(clazz);
} else if (Serializable.class.isAssignableFrom(clazz)) {
return new SerializableType(clazz);
}
}
throw new IllegalArgumentException(className + " is not Serializable or "
+ "Parcelable.");
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
You can see it looks for classes using Class.forName(String) method. So keeping their names is enough.
# Instead of -keep
-keepnames class com.package.app.data.model.** { *; }
And if packageName is provided, you can omit package name from value of argType attribute, but sadly it won't work if you use some application id suffixes depending on build variants. (So do not omit package name from argType)
I had the same problem, my argType was the class that was the Subclass of the fragment. I moved that class out of the fragment and problem was fixed
The app works on previous versions of Android, but not on Oreo. It's a WebView with Notifications. I've been researching this error and haven't found anything similar.
The stack trace:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: net.oneteamit.tk, PID: 3171
java.lang.RuntimeException: Unable to start activity ComponentInfo{net.oneteamit.tk/net.oneteamit.tk.MainActivity}:
java.lang.IllegalArgumentException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: java.lang.IllegalArgumentException
at android.os.Parcel.readException(Parcel.java:1946)
at android.os.Parcel.readException(Parcel.java:1888)
at android.app.INotificationManager$Stub$Proxy.createNotificationChannels(INotificationManager.java:1418)
at android.app.NotificationManager.createNotificationChannels(NotificationManager.java:446)
at android.app.NotificationManager.createNotificationChannel(NotificationManager.java:434)
at net.oneteamit.tk.MainActivity.onCreate(MainActivity.java:47)
at android.app.Activity.performCreate(Activity.java:6975)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
MainActivity:
public class MainActivity extends AppCompatActivity {
private WebView mWebView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mWebView = (WebView) findViewById(R.id.activity_main_webview);
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mWebView.loadUrl("My test URL");
mWebView.setWebViewClient(new WebViewClient());
mWebView.getSettings().setAppCacheEnabled(false);
mWebView.clearCache(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// Create channel to show notifications.
String channelId = getString(R.string.default_notification_channel_id);
String channelName = getString(R.string.default_notification_channel_name);
NotificationManager notificationManager =
getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(
new NotificationChannel(channelId,
channelName,
NotificationManager.IMPORTANCE_LOW));
}
mWebView.getSettings().setUseWideViewPort(true);
mWebView.getSettings().setLoadWithOverviewMode(true);
mWebView.setInitialScale(1);
mWebView.getSettings().setBuiltInZoomControls(true);
}
}
This exception occurs when the channel name is invalid. I was able to reproduce the stack trace by running with an empty channel name:
<string name="default_notification_channel_name"></string>
Check the value you have defined for default_notification_channel_name and change it to a valid value.
<string name="app_name"></string> was the reason of this error. Empty string causes FATAL EXCEPTION.
AppCompactActivity is backward compatible but not forward compatible,are there any components that you are using that are not supported by Android 8.0,or is the Android Studio or the IDE up to date with Oreo.
my application is on Google Play and it runs fine on most of devices (thousands of users). But in rare cases (fraction of percent of daily active users) I get Error inflating class android.webkit.WebView when I inflate layout for my fragment in onCreateView method.
Full stack trace is following:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.tapmedia.tapito/com.tapmedia.tapito.LockscreenActivity}: android.view.InflateException: Binary XML file line #20: Error inflating class android.webkit.WebView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2694)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2759)
at android.app.ActivityThread.access$900(ActivityThread.java:178)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1449)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5944)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
Caused by: android.view.InflateException: Binary XML file line #20: Error inflating class android.webkit.WebView
at android.view.LayoutInflater.createView(LayoutInflater.java:640)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:689)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:748)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:821)
at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
at com.tapmedia.tapito.WebViewFragment.onCreateView(SourceFile:84)
at android.support.v4.app.Fragment.performCreateView(SourceFile:1789)
at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:924)
at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1116)
at android.support.v4.app.FragmentManagerImpl.onCreateView(SourceFile:2196)
at android.support.v4.app.FragmentActivity.onCreateView(SourceFile:300)
at android.support.v7.app.AppCompatDelegateImplV7.callActivityOnCreateView(SourceFile:838)
at android.support.v7.app.AppCompatDelegateImplV11.callActivityOnCreateView(SourceFile:34)
at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(SourceFile:826)
at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(SourceFile:44)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:732)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
at android.view.LayoutInflater.inflate(LayoutInflater.java:366)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(SourceFile:249)
at android.support.v7.app.AppCompatActivity.setContentView(SourceFile:106)
at com.tapmedia.tapito.LockscreenActivity.onCreate(SourceFile:103)
at android.app.Activity.performCreate(Activity.java:6289)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2647)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2759)
at android.app.ActivityThread.access$900(ActivityThread.java:178)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1449)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5944)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Constructor.java)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at android.view.LayoutInflater.createView(LayoutInflater.java:614)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:689)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:748)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:821)
at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
at com.tapmedia.tapito.WebViewFragment.onCreateView(SourceFile:84)
at android.support.v4.app.Fragment.performCreateView(SourceFile:1789)
at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:924)
at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1116)
at android.support.v4.app.FragmentManagerImpl.onCreateView(SourceFile:2196)
at android.support.v4.app.FragmentActivity.onCreateView(SourceFile:300)
at android.support.v7.app.AppCompatDelegateImplV7.callActivityOnCreateView(SourceFile:838)
at android.support.v7.app.AppCompatDelegateImplV11.callActivityOnCreateView(SourceFile:34)
at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(SourceFile:826)
at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(SourceFile:44)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:732)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
at android.view.LayoutInflater.inflate(LayoutInflater.java:366)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(SourceFile:249)
at android.support.v7.app.AppCompatActivity.setContentView(SourceFile:106)
at com.tapmedia.tapito.LockscreenActivity.onCreate(SourceFile:103)
at android.app.Activity.performCreate(Activity.java:6289)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2647)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2759)
at android.app.ActivityThread.access$900(ActivityThread.java:178)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1449)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5944)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
Caused by: android.util.AndroidRuntimeException: android.content.pm.PackageManager$NameNotFoundException: com.google.android.webview
at android.webkit.WebViewFactory.getFactoryClass(WebViewFactory.java:161)
at android.webkit.WebViewFactory.getProvider(WebViewFactory.java:101)
at android.webkit.WebView.getFactory(WebView.java:2193)
at android.webkit.WebView.ensureProviderCreated(WebView.java:2188)
at android.webkit.WebView.setOverScrollMode(WebView.java:2247)
at android.view.View.(View.java:3795)
at android.view.View.(View.java:3909)
at android.view.ViewGroup.(ViewGroup.java:507)
at android.widget.AbsoluteLayout.(AbsoluteLayout.java:55)
at android.webkit.WebView.(WebView.java:547)
at android.webkit.WebView.(WebView.java:492)
at android.webkit.WebView.(WebView.java:475)
at android.webkit.WebView.(WebView.java:462)
at java.lang.reflect.Constructor.newInstance(Constructor.java)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at android.view.LayoutInflater.createView(LayoutInflater.java:614)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:689)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:748)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:821)
at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
at com.tapmedia.tapito.WebViewFragment.onCreateView(SourceFile:84)
at android.support.v4.app.Fragment.performCreateView(SourceFile:1789)
at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:924)
at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1116)
at android.support.v4.app.FragmentManagerImpl.onCreateView(SourceFile:2196)
at android.support.v4.app.FragmentActivity.onCreateView(SourceFile:300)
at android.support.v7.app.AppCompatDelegateImplV7.callActivityOnCreateView(SourceFile:838)
at android.support.v7.app.AppCompatDelegateImplV11.callActivityOnCreateView(SourceFile:34)
at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(SourceFile:826)
at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(SourceFile:44)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:732)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
at android.view.LayoutInflater.inflate(LayoutInflater.java:366)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(SourceFile:249)
at android.support.v7.app.AppCompatActivity.setContentView(SourceFile:106)
at com.tapmedia.tapito.LockscreenActivity.onCreate(SourceFile:103)
at android.app.Activity.performCreate(Activity.java:6289)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2647)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2759)
at android.app.ActivityThread.access$900(ActivityThread.java:178)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1449)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5944)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
Caused by: android.content.pm.PackageManager$NameNotFoundException: com.google.android.webview
at android.app.ApplicationPackageManager.getPackageInfo(ApplicationPackageManager.java:137)
at android.webkit.WebViewFactory.getFactoryClass(WebViewFactory.java:133)
at android.webkit.WebViewFactory.getProvider(WebViewFactory.java:101)
at android.webkit.WebView.getFactory(WebView.java:2193)
at android.webkit.WebView.ensureProviderCreated(WebView.java:2188)
at android.webkit.WebView.setOverScrollMode(WebView.java:2247)
at android.view.View.(View.java:3795)
at android.view.View.(View.java:3909)
at android.view.ViewGroup.(ViewGroup.java:507)
at android.widget.AbsoluteLayout.(AbsoluteLayout.java:55)
at android.webkit.WebView.(WebView.java:547)
at android.webkit.WebView.(WebView.java:492)
at android.webkit.WebView.(WebView.java:475)
at android.webkit.WebView.(WebView.java:462)
at java.lang.reflect.Constructor.newInstance(Constructor.java)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at android.view.LayoutInflater.createView(LayoutInflater.java:614)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:689)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:748)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:821)
at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
at com.tapmedia.tapito.WebViewFragment.onCreateView(SourceFile:84)
at android.support.v4.app.Fragment.performCreateView(SourceFile:1789)
at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:924)
at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1116)
at android.support.v4.app.FragmentManagerImpl.onCreateView(SourceFile:2196)
at android.support.v4.app.FragmentActivity.onCreateView(SourceFile:300)
at android.support.v7.app.AppCompatDelegateImplV7.callActivityOnCreateView(SourceFile:838)
at android.support.v7.app.AppCompatDelegateImplV11.callActivityOnCreateView(SourceFile:34)
at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(SourceFile:826)
at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(SourceFile:44)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:732)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
at android.view.LayoutInflater.inflate(LayoutInflater.java:366)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(SourceFile:249)
at android.support.v7.app.AppCompatActivity.setContentView(SourceFile:106)
at com.tapmedia.tapito.LockscreenActivity.onCreate(SourceFile:103)
at android.app.Activity.performCreate(Activity.java:6289)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2647)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2759)
at android.app.ActivityThread.access$900(ActivityThread.java:178)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1449)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5944)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
I don't understand what's wrong. Because this error comes from online reporting tool (Crashlytics/Fabric), I can't tell, whether this happens every time the specific user tries to use the fragment or if the user normally gets the fragment inflated and the error happens only from time to time.
WebView widget is part of the system, right? I mean - I can't be missing something in my production APK - like support library or so. Or can I?
If you see these reports from devices running Android Lollipop, please ignore them. This likely happens whenever something launches an activity that uses WebView while the WebView package is in the middle of being updated by Play Store (which can only happen on Lollipop currently). During updates, packages are treated as not installed by the package manager. That is, there is nothing wrong with your app. The time window while the updated package is considered non-existent is typically small, so when the app is relaunched after such a crash, it will start normally.
To fix this problem that appears on Android Lollipop you can use a custom WebView that creates a new configuration only on Android Lollipop (API 21 and 22). Replace the WebView on your XML layout with this custom WebView.
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.Configuration;
import android.os.Build;
import android.util.AttributeSet;
import android.webkit.WebView;
public class LollipopFixedWebView extends WebView {
public LollipopFixedWebView(Context context) {
super(getFixedContext(context));
}
public LollipopFixedWebView(Context context, AttributeSet attrs) {
super(getFixedContext(context), attrs);
}
public LollipopFixedWebView(Context context, AttributeSet attrs, int defStyleAttr) {
super(getFixedContext(context), attrs, defStyleAttr);
}
// To fix Android Lollipop WebView problem create a new configuration on that Android version only
private static Context getFixedContext(Context context) {
if (Build.VERSION.SDK_INT == 21 || Build.VERSION.SDK_INT == 22) // Android Lollipop 5.0 & 5.1
return context.createConfigurationContext(new Configuration());
return context;
}
}
If you are not relying on new Material DayNight theme switching (or other UiMode events), you can add android:configChanges="uiMode" to the webview activity manifest to prevent AppCompatDelegate updating the resources configuration and thereby messing up the webview inflation.
I've got this problem in 2020 too and, now, there's a solution:
Just add this new dependencies:
implementation 'androidx.appcompat:appcompat:1.2.0-beta01'
implementation 'androidx.appcompat:appcompat-resources:1.2.0-beta01'
The documentation says:
Fixed an issue where androidx.appcompat:appcompat:1.1.0 crashes
webview when webview is long pressed (b/141351441)
In the onCreate of the activity that inflates Webview in the UI, you
can have a try-catch to save yourself from the errors producing in the
Crashlytics.
/**
* This element touches the UI elements
* of the application and set them up.
*/
try {
setContentView(R.layout.activity_main);
// ... further setup
} catch (Exception ex) {
transferToNoPackageFoundActivity(ex.getMessage());
}
private void transferToNoPackageFoundActivity(String errorMessage) {
Intent intent = new Intent(this, NoPackageFoundActivity.class);
intent.putExtra(Intent.EXTRA_INTENT, errorMessage);
startActivity(intent);
finish();
}
In the NoPackageFoundActivity, you can take the user to the Playstore for downloading the webview package.
/**
* This field is used for presenting the user
* with an error image for no connectivity.
*/
private lateinit var mErrorImage: ImageView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_no_network)
// get the intent for the error message, if any.
val intent: Intent = intent
if (intent.hasExtra(Intent.EXTRA_INTENT)) {
println(intent.getStringExtra(Intent.EXTRA_INTENT))
}
mErrorImage = findViewById(R.id.error_image)
mErrorImage.contentDescription = resources.getString(R.string.no_network_image_desc)
Glide.with(this)
.load(R.drawable.ic_no_web_view_illustration)
.into(mErrorImage)
val enableButton = findViewById<Button>(R.id.error_handler_btn)
enableButton.setOnClickListener { openGooglePlayStore() }
enableButton.text = resources.getString(R.string.no_package_btn_text)
val reloadText = findViewById<TextView>(R.id.no_network_reload)
reloadText.setOnClickListener { reloadApplication() }
val errorHeadingText = findViewById<TextView>(R.id.error_heading)
val errorSubheadingText = findViewById<TextView>(R.id.error_subheading)
errorHeadingText.text = resources.getString(R.string.no_package_heading_text)
errorSubheadingText.text = resources.getString(R.string.no_package_subheading_text)
}
/**
* This is a onClickListener Handler that
* reloads the application when the user
* clicks on it.
* It starts the activity again from
*/
private fun reloadApplication() {
val intent = Intent(this, SplashScreen::class.java)
startActivity(intent)
finish()
}
private fun openGooglePlayStore() {
// you can also use BuildConfig.APPLICATION_ID
val appId = "com.google.android.webview"
val rateIntent = Intent(Intent.ACTION_VIEW,
Uri.parse("market://details?id=$appId"))
var marketFound = false
// find all applications able to handle our rateIntent
val otherApps = packageManager
.queryIntentActivities(rateIntent, 0)
for (otherApp in otherApps) { // look for Google Play application
if (otherApp.activityInfo.applicationInfo.packageName
== "com.android.vending") {
val otherAppActivity = otherApp.activityInfo
val componentName = ComponentName(
otherAppActivity.applicationInfo.packageName,
otherAppActivity.name
)
// make sure it does NOT open in the stack of your activity
rateIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
// task reparenting if needed
rateIntent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED)
// if the Google Play was already open in a search result
// this make sure it still go to the app page you requested
rateIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
// this make sure only the Google Play app is allowed to
// intercept the intent
rateIntent.component = componentName
startActivity(rateIntent)
marketFound = true
break
}
}
// if GP not present on device, open web browser
if (!marketFound) {
val webIntent = Intent(Intent.ACTION_VIEW,
Uri.parse("https://play.google.com/store/apps/details?id=$appId"))
startActivity(webIntent)
}
}