Search code examples
cordovaphonegap-pluginscordova-pluginsphonegap-build

Namespace prefix android is not defined


I am trying to use FCM for push Notification in my telerik app builder "https://github.com/fechanique/cordova-plugin-fcm" i get the error "Namespace prefix android is not defined" and my function getToken is not working

<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
       id="cordova-plugin-fcm"
       version="2.1.1">
<name>FCMPlugin</name>
<description>Cordova FCM Plugin</description>
<license>Apache 2.0</license>
<keywords>cordova, fcm, push, plugin</keywords>

<info>
    Cordova FCM plugin v2.1.1 installed
    For more details visit https://github.com/fechanique/cordova-plugin-fcm
</info>

<js-module src="www/FCMPlugin.js" name="FCMPlugin">
<clobbers target="FCMPlugin" />
</js-module>

<engines>
<engine name="cordova-android" version=">=4.0.0" />
</engines>

<!-- ANDROID CONFIGURATION -->


<platform name="android">
    <config-file target="AndroidManifest.xml" parent="/manifest/application">
        <activity android:exported="true" android:name="com.gae.scaffolder.plugin.FCMPluginActivity" android:launchMode="singleTop">
            <intent-filter>   
                <action android:name="FCM_PLUGIN_ACTIVITY" />  
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>            
        </activity>
        <service android:name="com.gae.scaffolder.plugin.MyFirebaseMessagingService">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT"/>
            </intent-filter>
        </service>
        <service android:name="com.gae.scaffolder.plugin.MyFirebaseInstanceIDService">
            <intent-filter>
                <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
            </intent-filter>
        </service>
    </config-file>
    <config-file target="res/xml/config.xml" parent="/*">
        <feature name="FCMPlugin" >
                <param name="android-package" value="com.gae.scaffolder.plugin.FCMPlugin"/>
                <param name="onload" value="true" />
            </feature>
    </config-file>

    <framework src="com.google.firebase:firebase-core:+" />
    <framework src="com.google.firebase:firebase-messaging:+" />

    <framework src="src/android/FCMPlugin.gradle" custom="true" type="gradleReference"/>
  <source-file src="src/android/google-services.json" target-dir="src/com/gae/scaffolder/plugin" />
    <source-file src="src/android/FCMPlugin.java" target-dir="src/com/gae/scaffolder/plugin" />
    <source-file src="src/android/MyFirebaseMessagingService.java" target-dir="src/com/gae/scaffolder/plugin" />
    <source-file src="src/android/MyFirebaseInstanceIDService.java" target-dir="src/com/gae/scaffolder/plugin" />
    <source-file src="src/android/FCMPluginActivity.java" target-dir="src/com/gae/scaffolder/plugin" />
</platform>

//function in my script//
 fcmPlugin.getToken(function (token) {
            alert(token);
        });

Solution

  • I am new to Cordova, so I am going out on a limb here.

    I ran into a similar error with my config.xml using config-file. To fix it I had to add to the widget tag:

    xmlns:android="http://schemas.android.com/apk/res/android"
    

    You may have to do something similar.