home_widget icon indicating copy to clipboard operation
home_widget copied to clipboard

No Widget found with Name HomeWidgetExampleProvider

Open whlla opened this issue 3 years ago • 15 comments

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.

whlla avatar Sep 10 '21 03:09 whlla

Could you check what the defined package name in your HomeWidgetExampleProvider.kt is? It should match the package identifier from your app

ABausG avatar Sep 10 '21 16:09 ABausG

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.

whlla avatar Sep 10 '21 21:09 whlla

Could you provide the complete stack trace?

ABausG avatar Nov 21 '21 12:11 ABausG

I Have the same problem

image

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

jeffersonmello avatar Jan 10 '22 17:01 jeffersonmello

I Have the same problem

image

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 avatar Jan 11 '22 12:01 jeffersonmello

@jeffersonmello I have the same problem. How did you change to java?

desmeit avatar Apr 07 '22 13:04 desmeit

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?

apoleo88 avatar May 20 '22 16:05 apoleo88

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. 😉

ColinSchmale avatar May 22 '22 21:05 ColinSchmale

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]]

apoleo88 avatar May 23 '22 12:05 apoleo88

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?

In your HomeWidgetExampleProvider.kt you should have package app.myapp instead.

ColinSchmale avatar May 23 '22 13:05 ColinSchmale

I checked now and it was already package app.myapp

apoleo88 avatar May 23 '22 13:05 apoleo88

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.

apoleo88 avatar May 24 '22 09:05 apoleo88

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?

ABausG avatar Jun 05 '22 21:06 ABausG

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.

apoleo88 avatar Jun 06 '22 14:06 apoleo88

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?

MrVipinVijayan avatar Aug 23 '22 03:08 MrVipinVijayan

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

theRealGetman avatar May 08 '23 13:05 theRealGetman

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 avatar Jul 30 '23 16:07 milindgoel15

@milindgoel15 could you try again using qualifiedAndroidName

ABausG avatar Aug 08 '23 08:08 ABausG

@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",
    );

milindgoel15 avatar Aug 08 '23 09:08 milindgoel15

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 avatar Sep 04 '23 10:09 milindgoel15

@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?

ABausG avatar Sep 05 '23 17:09 ABausG

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

milindgoel15 avatar Sep 05 '23 17:09 milindgoel15

in my case, I only add capability for Runner without Widget Extension. I added it that work a charm

mtiendat avatar Sep 13 '23 11:09 mtiendat

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

huutrung789 avatar Feb 01 '24 04:02 huutrung789

qualifiedAndroidName: 'com.example.app.HomeWidgetExampleProvider',

For every one who struggled with flavory this qualifiedAndroidName could help

Mounix99 avatar Mar 21 '24 19:03 Mounix99