1

I'm currently developing an app and making a widget with Glance. App size spiked from 2.8MB to 5.3MB from Glance.

I'm thinking to use Dynamic Feature/Delivery to reduce the app size issue so user only need to download the widget when they need to.

But I got a strange crash even after the module is downloaded. The widget cannot render and only shows "Can't load widget" text in the launcher.

The error doesn't happen if I set the module at install time:

         <dist:install-time>

            <dist:removable dist:value="false"/>

        </dist:install-time>

When I changed into on demand it's broken:

        <dist:on-demand />

Here's the error log

 Error inflating AppWidget AppWidgetProviderInfo(UserHandle{0}/ComponentInfo{com.example.foo/com.example.foo.glance.ui.glance.MyWidgetReceiver})
                                                                                                android.content.res.Resources$NotFoundException: Resource ID #0x0
                                                                                                    at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:240)
                                                                                                    at android.content.res.Resources.loadXmlResourceParser(Resources.java:2529)
                                                                                                    at android.content.res.Resources.getLayout(Resources.java:1335)
                                                                                                    at android.view.LayoutInflater.inflate(LayoutInflater.java:536)
                                                                                                    at android.appwidget.AppWidgetHostView.getDefaultView(AppWidgetHostView.java:926)
                                                                                                    at android.appwidget.AppWidgetHostView.applyRemoteViews(AppWidgetHostView.java:579)
                                                                                                    at android.appwidget.AppWidgetHostView.updateAppWidget(AppWidgetHostView.java:533)
                                                                                                    at com.android.launcher3.widget.LauncherAppWidgetHostView.updateAppWidget(LauncherAppWidgetHostView.java:247)
                                                                                                    at android.appwidget.AppWidgetHost.updateAppWidgetView(AppWidgetHost.java:529)
                                                                                                    at android.appwidget.AppWidgetHost$UpdateHandler.handleMessage(AppWidgetHost.java:158)
                                                                                                    at android.os.Handler.dispatchMessage(Handler.java:106)
                                                                                                    at android.os.Looper.loopOnce(Looper.java:226)
                                                                                                    at android.os.Looper.loop(Looper.java:313)
                                                                                                    at android.app.ActivityThread.main(ActivityThread.java:8751)
                                                                                                    at java.lang.reflect.Method.invoke(Native Method)
                                                                                                    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
                                                                                                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)

Is there any idea how can I enable widget via dynamic delivery?

DTechnlogy
  • 320
  • 4
  • 12

1 Answers1

0

Few things to consider:

Dynamic modules AndroidManifest gets merged into the base module. Thus the widget provider is present in the base module, meaning, even if the Dynamic feature is not installed the widget will be present in the picker.

A possible solution is to have the receiver disabled and enable it programatically once the DF is downloaded (example)

Now, for the ResourceNotFound issue that could be related to the location of the initial layout or resources defined in the widget metadata.

Are you defining a initialLayout? If yes, maybe try to move that to the base module?

Marcel
  • 2,094
  • 3
  • 23
  • 37
  • I can't disable the broadcast receiver. If I disable trough manifest, I cant turn it on again idk why, but it works if i disable it programmatically. But I can't disable it programmatically since the start since the dfm is not downloaded yet and crashes instead. For `initialLayout`, no I don't even use it. Is it required? Thanks – DTechnlogy Sep 12 '22 at 16:04