error: unexpected element <service> found in <manifest>

Viewed 1199

I'm trying to build my Cordova app with a plugin created by me. This plugin contains a service that runs in the background, and I am not able to compile the app with it. This is the error that the console shows me when I do cordova build android:

What went wrong: Execution failed for task ':app:processDebugResources'. A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade Android resource linking failed C:\Users\dev\Desktop\appTest\platforms\android\app\src\main\AndroidManifest.xml:10:9-101: AAPT: error: unexpected element <service> found in <manifest>

My plugin.xml config:

<config-file target="AndroidManifest.xml" parent="/manifest/application">            
    <service android:name=".ForegroundService" android:enabled="true" android:exported="true"></service>
</config-file>

<config-file target="AndroidManifest.xml" parent="/manifest">
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
</config-file>

Any ideas?

My Cordova version is 10.0.0

1 Answers

You need to add xmlns:android="http://schemas.android.com/apk/res/android" to the root widget tag of config.xml

Related