Search code examples
androidpush-notificationbackendless

why there is an error when I add backendless service for android in manifest?


when I add backendless service for Android in manifest like shown in push notification setup in backendless website it gives me this an error and a red line under the first service word

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.peter.notify">


<uses-permission android:name="android.permission.INTERNET" />

<service android:name="com.backendless.push.BackendlessFCMService">
    <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT" />
    </intent-filter>
</service>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".LoginPage">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER"     />
        </intent-filter>
    </activity>
    <activity android:name=".RegisterPage" />
    <activity android:name=".MoviesPage" />

</application>

what I expect my app connect with my backendless account, but what I     get it this error 

(Android resource linking failed
Output:  C:\Users\PETER\AndroidStudioProjects\Notify\app\build    \intermediates\instant_run_merged_manifests\debug\processDebugManifest  \instant-run\AndroidManifest.xml:19: error: unexpected element <service>    found in <manifest>.

Command: C:\Users\PETER\.gradle\caches\transforms-1\files-    1.1\aapt2-3.2.1-4818971-windows.jar\efc3d32fb9b1857254999d94d3fe990e\aapt2-3.2.1-4818971-windows\aapt2.exe link -I\
    C:\Users\PETER\AppData\Local\Android\Sdk\platforms\android-   28\android.jar\
    --manifest\
    C:\Users\PETER\AndroidStudioProjects\Notify\app\build\intermediates\instant_run_merged_manifests\debug\processDebugManifest\instant-run\AndroidManifest.xml\
    -o\
    C:\Users\PETER\AndroidStudioProjects\Notify\app\build\intermediates\processed_res\debug\processDebugResources\out\resources-debug.ap_\
    -R\
    @C:\Users\PETER\AndroidStudioProjects\Notify\app\build\intermediates\incremental\processDebugResources\resources-list-for-resources-debug.ap_.txt\
    --auto-add-overlay\
    --java\
    C:\Users\PETER\AndroidStudioProjects\Notify\app\build\generated\not_namespaced_r_class_sources\debug\processDebugResources\r\
    --custom-package\
    com.example.peter.notify\
    -0\
    apk\
    --preferred-density\
    xxhdpi\
    --output-text-symbols\
    C:\Users\PETER\AndroidStudioProjects\Notify\app\build\intermediates\symbols\debug\R.txt\
    --no-version-vectors

Daemon: AAPT2 aapt2-3.2.1-4818971-windows Daemon #0)


Solution

  • <service> tag should be contained in <application> tag according to documentation.

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.example.peter.notify">
    
    
    <uses-permission android:name="android.permission.INTERNET" />
    
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".LoginPage">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
    
                <category android:name="android.intent.category.LAUNCHER"     />
            </intent-filter>
        </activity>
        <activity android:name=".RegisterPage" />
        <activity android:name=".MoviesPage" />
    
        <service android:name="com.backendless.push.BackendlessFCMService">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
        </service>
    
    </application>
    

    EDIT:

    Make sure you have these dependencies in your build.gradle file and your project is synced with Gradle files.

    implementation 'com.google.firebase:firebase-core:16.0.8'
    implementation 'com.google.firebase:firebase-messaging:17.6.0'
    implementation 'com.backendless:backendless:5.2.4'