home_widget
home_widget copied to clipboard
No Widget found with Name HomeWidgetExampleProvider
After following set up instructions and comparing with example app, I'm not sure what the issue might be.
In my AndroidManifex.xml
I have:
<receiver android:name="HomeWidgetExampleProvider" >
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data android:name="android.appwidget.provider"
android:resource="@xml/home_widget_example" />
</receiver>
And in my android/app/src/main/kotlin/com/someName/app/anotherName/HomeWidgetExampleProvider.kt
I have the same code from the example project.
I did add Kotlin support to my Flutter app which was originally configured as Java. After sorting our some build issues, MainActivity.kt
path seems to be working, but HomeWidgetExampleProvider.kt
in the same directory is not?
Any ideas?
EDIT: I forgot to mention, the example widget will build fine and has the time when initially created, but this error is still thrown and also thrown on subsequent updates from Workmanager periodic task. Time will remain the same as when created.
Could you check what the defined package name in your HomeWidgetExampleProvider.kt
is? It should match the package identifier from your app
It matches. From AndroidManifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.someName.app.anotherName">
From HomeWidgetExampleProvider.kt:
package com.someName.app.anotherName
import android.appwidget.AppWidgetManager
import android.content.Context
import android.content.SharedPreferences
import android.net.Uri
import android.widget.RemoteViews
import es.antonborri.home_widget.HomeWidgetBackgroundIntent
import es.antonborri.home_widget.HomeWidgetLaunchIntent
import es.antonborri.home_widget.HomeWidgetProvider
class HomeWidgetExampleProvider : HomeWidgetProvider() {
Not sure if this is relevant, but when opening AndroidManifest.xml in Flutter project it shows android:name="HomeWidgetExampleProvider"
as unresolved class. When I open the inner Android project in separate AndroidSutdio it does not show this and can access class definition from AndroidManifest.xml.
Could you provide the complete stack trace?
I Have the same problem
I/flutter (23693): PlatformException(-3, No Widget found with Name AppWidgetProvider. Argument 'name' must be the same as your AppWidgetProvider you wish to update, java.lang.ClassNotFoundException: br.com.fixxinvest.app.fixxinvest.AppWidgetProvider I/flutter (23693): at java.lang.Class.classForName(Native Method) I/flutter (23693): at java.lang.Class.forName(Class.java:454) I/flutter (23693): at java.lang.Class.forName(Class.java:379) I/flutter (23693): at es.antonborri.home_widget.HomeWidgetPlugin.onMethodCall(HomeWidgetPlugin.kt:82) I/flutter (23693): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262) I/flutter (23693): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:178) I/flutter (23693): at io.flutter.embedding.engine.dart.DartMessenger.lambda$handleMessageFromDart$0$DartMessenger(DartMessenger.java:206) I/flutter (23693): at io.flutter.embedding.engine.dart.-$$Lambda$DartMessenger$6ZD1MYkhaLxyPjtoFDxe45u43DI.run(Unknown Source:12) I/flutter (23693): at android.os.Handler.handleCallback(Handler.java:883) I/flutter (23693): at android.os.Handler.dispatchMessage(Handler.java:100) I/flutter (23693): at android.os.Looper.loop(Looper.j
I Have the same problem
I/flutter (23693): PlatformException(-3, No Widget found with Name AppWidgetProvider. Argument 'name' must be the same as your AppWidgetProvider you wish to update, java.lang.ClassNotFoundException: br.com.fixxinvest.app.fixxinvest.AppWidgetProvider I/flutter (23693): at java.lang.Class.classForName(Native Method) I/flutter (23693): at java.lang.Class.forName(Class.java:454) I/flutter (23693): at java.lang.Class.forName(Class.java:379) I/flutter (23693): at es.antonborri.home_widget.HomeWidgetPlugin.onMethodCall(HomeWidgetPlugin.kt:82) I/flutter (23693): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262) I/flutter (23693): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:178) I/flutter (23693): at io.flutter.embedding.engine.dart.DartMessenger.lambda$handleMessageFromDart$0$DartMessenger(DartMessenger.java:206) I/flutter (23693): at io.flutter.embedding.engine.dart.-$$Lambda$DartMessenger$6ZD1MYkhaLxyPjtoFDxe45u43DI.run(Unknown Source:12) I/flutter (23693): at android.os.Handler.handleCallback(Handler.java:883) I/flutter (23693): at android.os.Handler.dispatchMessage(Handler.java:100) I/flutter (23693): at android.os.Looper.loop(Looper.j
I solved this problem, my application use Java with language on Android, but the widget provider created as Kotlin. I changed de widget provider to java implementation and work fine.
@jeffersonmello I have the same problem. How did you change to java?
Could you check what the defined package name in your
HomeWidgetExampleProvider.kt
is? It should match the package identifier from your app
In mine is:
package es.antonborri.home_widget_example
Should this have been changed automatically? How?
When HomeWidgetExampleProvider.kt
is generate? How can I create another Provider with a different name?
It should not be necessary to use a Java Provider. Kotlin works perfectly with my project.
Make sure the applicationId
in your build.gradle
is the same as your package name. The plugin uses Context.getPackageName
to get the package name of the Provider but his method returns the application ID and not the package name. 😉
Thanks for the reply. I don't know what I am doing wrong.
In build.gradle:
defaultConfig {
applicationId "app.myapp"
}
I added in the AndroidManifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="app.myapp">
<application
android:name=".Application"
android:label="myApp"
android:icon="@mipmap/ic_launcher"
android:requestLegacyExternalStorage="true">
...
<receiver android:name="HomeWidgetExampleProvider"
android:exported="false">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data android:name="android.appwidget.provider"
android:resource="@xml/home_widget_lauch" />
</receiver>
</application>
</manifest>
The Widget is called to be created:
HomeWidget.updateWidget(
name: 'HomeWidgetExampleProvider',
androidName: 'HomeWidgetExampleProvider',
iOSName: 'HomeWidgetExample',
);
ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: PlatformException(-3, No Widget found with Name HomeWidgetExampleProvider. Argument 'name' must be the same as your AppWidgetProvider you wish to update, java.lang.ClassNotFoundException: app.myapp.HomeWidgetExampleProvider
E/flutter ( 6100): at java.lang.Class.classForName(Native Method)
E/flutter ( 6100): at java.lang.Class.forName(Class.java:454)
E/flutter ( 6100): at java.lang.Class.forName(Class.java:379)
E/flutter ( 6100): at es.antonborri.home_widget.HomeWidgetPlugin.onMethodCall(HomeWidgetPlugin.kt:83)
E/flutter ( 6100): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262)
E/flutter ( 6100): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:296)
E/flutter ( 6100): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$DartMessenger(DartMessenger.java:320)
E/flutter ( 6100): at io.flutter.embedding.engine.dart.-$$Lambda$DartMessenger$AIEPqY6mWzaNK15HekX9bftoAXs.run(Unknown Source:12)
E/flutter ( 6100): at android.os.Handler.handleCallback(Handler.java:938)
E/flutter ( 6100): at android.os.Handler.dispatchMessage(Handler.java:99)
E/flutter ( 6100): at android.os.Looper.loopOnce(Looper.java:201)
E/flutter ( 6100): at android.os.Looper.loop(Looper.java:288)
E/flutter ( 6100): at android.app.ActivityThread.main(ActivityThread.java:7842)
E/flutter ( 6100): at java.lang.reflect.Method.invoke(Native Method)
E/flutter ( 6100): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
E/flutter ( 6100): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
E/flutter ( 6100): Caused by: java.lang.ClassNotFoundException: Didn't find class "app.myapp.HomeWidgetExampleProvider" on path: DexPathList[[zip file "/data/app/~~rHF4N3oMkzO4HMcPquExvg==/app.myapp-APlUQNsTjQl0KcLC6rbhhA==/base.apk"],nativeLibraryDirectories=[/data/app/~~rHF4N3oMkzO4HMcPquExvg==/app.myapp-APlUQNsTjQl0KcLC6rbhhA==/lib/x86_64, /data/app/~~rHF4N3oMkzO4HMcPquExvg==/app.myapp-APlUQNsTjQl0KcLC6rbhhA==/base.apk!/lib/x86_64, /system/lib64, /system_ext/lib64]]
Could you check what the defined package name in your
HomeWidgetExampleProvider.kt
is? It should match the package identifier from your appIn mine is:
package es.antonborri.home_widget_example
Should this have been changed automatically? How?When
HomeWidgetExampleProvider.kt
is generate? How can I create another Provider with a different name?
In your HomeWidgetExampleProvider.kt you should have package app.myapp
instead.
I checked now and it was already package app.myapp
I checked in the widget menu of Android, and it has a widget for the app, but this isn't shown by default when created or updated. Not sure when it has been created, maybe when it installed the app?
It needs to be placed manually, is there a way to add it to the home automatically?
I still get the error No Widget found with Name HomeWidgetExampleProvider
, nothing changed.
Not sure when it has been created, maybe when it installed the app?
Yes the Widget should come up in the menu to add widgets after installation
It needs to be placed manually, is there a way to add it to the home automatically?
There might be launchers which do this automatically but in general I don't think launchers add the widget automatically and personally I don't think they should.
I still get the error No Widget found with Name HomeWidgetExampleProvider, nothing changed.
What is the name of the class your widget is using? Also in the latest versions there is now the option to use the qualified name (see #62 for more info) maybe this can help you?
I found out that I was putting the file in the wrong directory. !nstead, when I put the WidgetProvider in my:
\android\app\src\main\kotlin\com\example\appname
then it worked fine. Maybe the documentation could be more clear about it.
I created an android native channel to ask to add the widget to the home screen. Need to test on IOS yet.
I feel it is a common need that the user chooses to create a widget inside the app, instead to have to go through the widgets list in order to find what he needs. It also allows to personalize right away the widget.
I have different build variants and I want one widget for all variants. so I get the error saying the packagename_variant.className widget not found. How can we fix this?
I have different build variants and I want one widget for all variants. so I get the error saying the packagename_variant.className widget not found. How can we fix this?
Same for me. It works fine with default variant, but doesn't work with "dev" flavor
So if the app has flavor added for Android apps, the widget will not work in any flavor that is not the default. And will give you No widget found error as in the title: https://katb.in/zebajedasew
@milindgoel15 could you try again using qualifiedAndroidName
@milindgoel15 could you try again using
qualifiedAndroidName
same error happens. Adding qualifiedAndroidName breaks the regular flavor as well.
HomeWidget.updateWidget(
androidName: "GlanceWidget",
qualifiedAndroidName: "GlanceWidget",
);
HomeWidget.updateWidget(
androidName: "CurrentWeather",
qualifiedAndroidName: "CurrentWeather",
);
same error happens. Adding qualifiedAndroidName breaks the regular flavor as well.
HomeWidget.updateWidget( androidName: "GlanceWidget", qualifiedAndroidName: "GlanceWidget", ); HomeWidget.updateWidget( androidName: "CurrentWeather", qualifiedAndroidName: "CurrentWeather", );
An update to this comment, turns out I didn't write the qualifiedAndroidName properly. This needs a full package name along with the widget name. So using only the qualifiedAndroidName for production flavor will remove the "No widget found error"..
@milindgoel15 yeah I meant to answer you that you should have a name with the full package name syntax. I guess the documentation for that could be improved. Do you have an idea what might be a wording that would've helped you the first time?
Something like this ig
In order to force the homescreen widgets to update its data, you need to call this code:
HomeWidget.updateWidget(
name: 'HomeWidgetExampleProvider',
androidName: 'HomeWidgetExampleProvider',
iOSName: 'HomeWidgetExample',
qualifiedAndroidName: 'com.example.app.HomeWidgetExampleProvider',
);
Where the parameters must adhere to the following naming scheme:
- qualifiedAndroidName: This must be set with the full package name + the name of the widget you want to update.
- iOSName: The name for your iOS widget extension.
- name: this is the fallback widget name in case the others fail or provide a null value. (Must only include the name of the widget)
- androidName: This should be the name of the widget you want to update.
Though in the kotlin side of code, there's no mention of this androidName
https://github.com/ABausG/home_widget/blob/main/android/src/main/kotlin/es/antonborri/home_widget/HomeWidgetPlugin.kt#L81
It checks for android or name
in my case, I only add capability for Runner without Widget Extension. I added it that work a charm
I found out that I was putting the file in the wrong directory. !nstead, when I put the WidgetProvider in my:
\android\app\src\main\kotlin\com\example\appname
then it worked fine. Maybe the documentation could be more clear about it.I created an android native channel to ask to add the widget to the home screen. Need to test on IOS yet.
I feel it is a common need that the user chooses to create a widget inside the app, instead to have to go through the widgets list in order to find what he needs. It also allows to personalize right away the widget.
I faced the same issue and it is resolved by this solution
qualifiedAndroidName: 'com.example.app.HomeWidgetExampleProvider',
For every one who struggled with flavory this qualifiedAndroidName
could help