5

When trying to load a url in my Android Things webview the page initially loads, then crashes the UI with an error message pointing towards the IoT FrameworkPackageStubs.

I am using a Raspberry Pi on Dev Preview 5.1 which supports Webviews and OpenGL but have no idea why my very simple application seems to be crashing. The code for it is as follows

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    WebView webView = (WebView) findViewById(R.id.webView);
    if(webView != null)
    webView.loadUrl("https://www.facebook.com");
}

Here is my manifest file

 <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.airborneathletics.videohwtest">

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.BLUETOOTH"/>
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <uses-library android:name="com.google.android.things" android:required="false"/>
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

and my Gradle depdencies

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:26.+'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'

    provided 'com.google.android.things:androidthings:0.5.1-devpreview'
}

And finally my error message I'm receiving when making the calls.

    --------- beginning of crash
08-31 20:30:33.458 10146-10146/com.google.android.iot.frameworkpackagestubs E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                              Process: com.google.android.iot.frameworkpackagestubs, PID: 10146
                                                                                              java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.google.android.iot.frameworkpackagestubs/com.google.android.iot.frameworkpackagestubs.Stubs$BrowserStub}: java.lang.ClassNotFoundException: Didn't find class "com.google.android.iot.frameworkpackagestubs.Stubs$BrowserStub" on path: DexPathList[[zip file "/system/app/IoTFrameworkPackageStubs/IoTFrameworkPackageStubs.apk"],nativeLibraryDirectories=[/system/app/IoTFrameworkPackageStubs/lib/arm, /system/lib, /system/vendor/lib, /system/lib, /system/vendor/lib]]
                                                                                                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2718)
                                                                                                  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.ClassNotFoundException: Didn't find class "com.google.android.iot.frameworkpackagestubs.Stubs$BrowserStub" on path: DexPathList[[zip file "/system/app/IoTFrameworkPackageStubs/IoTFrameworkPackageStubs.apk"],nativeLibraryDirectories=[/system/app/IoTFrameworkPackageStubs/lib/arm, /system/lib, /system/vendor/lib, /system/lib, /system/vendor/lib]]
                                                                                                  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:93)
                                                                                                  at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
                                                                                                  at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
                                                                                                  at android.app.Instrumentation.newActivity(Instrumentation.java:1173)
                                                                                                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2708)
                                                                                                  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) 

I will admit some websites do work, but when I go to https://www.google.com and type in a search it crashes with the same message.

Thanks for the assistance.

Al Lelopath
  • 6,448
  • 13
  • 82
  • 139
DomHDD
  • 53
  • 1
  • 3

2 Answers2

3

You're likely running into the same problem as here.

When links are loaded in Android, by default the system will try to launch an application to handle the URL, in this case a browser. However Android Things does not include a browser by default, so it fails to handle the URL and crashes.

You can override this default behavior and have the URLs load in your app's WebView, by setting the WebViewClient in your app before loading any URLs:

WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.setWebViewClient(new WebViewClient());

This is documented here.

Steve
  • 46
  • 1
0

If you have a web view along with a progress bar, then the code is down below:

WebView myWebView = (WebView) findViewById(R.id.webView3);

        progressDialog = new ProgressDialog(YOUR_ACTIVITY.this);
        progressDialog.setCancelable(true);
        progressDialog.setMessage("Please wait....");
        progressDialog.show();

        myWebView.setWebViewClient(new WebViewClient() {   // setting Progress Bar
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                Log.d(TAG, "LOADING");
                return true;
            }

            @Override
            public void onPageFinished(WebView view, String url) {
                if (progressDialog.isShowing()) {
                    progressDialog.dismiss();
                }
            }

        });

        myWebView.setInitialScale(1);
        myWebView.getSettings().setLoadWithOverviewMode(true);
        myWebView.getSettings().setUseWideViewPort(true);
        myWebView.getSettings().setJavaScriptEnabled(true);myWebView.loadUrl("https://www.google.com");

        myWebView.getSettings().setSupportZoom(true);
        myWebView.getSettings().setBuiltInZoomControls(true);
        myWebView.getSettings().setDisplayZoomControls(false);
Akhil Nair
  • 434
  • 1
  • 6
  • 17