How do you register an Android Service in a Flutter Plugin
Solution 1
I was unable to determine how to include a service definition in a Flutter plugin that would be added to the plugin consuming app.
What I had to do was add the service definition in the AndroidManifest.xml
file of the plugin consuming app.
Solution 2
Haven't tried this with a service, but creating a skeleton manifest in the plugin's folders does seem to merge the skeleton into the app's manifest at build time.
For example, with the following skeleton, the application
meta-data
definition is merged fine.:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.plugin.restrictions_manager">
<application>
<meta-data android:name="android.content.APP_RESTRICTIONS"
android:resource="@xml/app_restrictions" />
</application>
</manifest>
[Edit]
This approach does indeed work with a service declaration. And to see the merged AndroidManifest.xml, look in my_plugin/build/app/outputs/apk/debug/app-debug.apk
, which can be browsed in Android Studio.
dazza5000
Freelance Android Engineer. Co-organizer of the Austin Android Developer Meetup! Name is Darran Kelinske. love.
Updated on December 20, 2022Comments
-
dazza5000 over 1 year
I am creating a card reader integration that uses and Android Service for part of the integration. The standard Android implementation includes an android service definition in the
AndroidManifest.xml
<service android:name="com.anywherecommerce.android.sdk.services.CardReaderConnectionService" android:stopWithTask="false" />
How do I define that in a Flutter Plugin so that the service definition will be added to the AndroidManifest of the app that uses it? Do I just include it as part of the library and leave it up to the user to register the service in their app
AndroidManifest.xml
?