【问题标题】:why there is an error when I add backendless service for android in manifest?为什么我在清单中为 android 添加后端服务时会出错?
【发布时间】:2019-04-13 06:45:37
【问题描述】:

当我在清单中添加适用于 Android 的后端服务时,如后端网站中的推送通知设置中所示,它会给我一个错误,并在第一个服务字下显示一条红线

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

守护进程:AAPT2 aapt2-3.2.1-4818971-windows 守护进程 #0)

【问题讨论】:

    标签: android push-notification backendless


    【解决方案1】:

    根据documentation&lt;application&gt;标签应该包含&lt;service&gt;标签。

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

    编辑:

    确保您的 build.gradle 文件中有这些依赖项,并且您的项目已与 Gradle 文件同步。

    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'
    

    【讨论】:

    • 现在 中的 BackendlessFCMService 当我按 alt 输入时变为红色,询问我是否要创建类 BackendlessFCMService 但没有任何反应跨度>
    • @Petersafwat 检查编辑是否解决了您的问题
    • @Petersafwat 是否识别出该服务,还是还是同样的问题?
    • BackendlessFCMService in 仍然是红色的,但是当我运行应用程序时它崩溃了,我发现一个错误说(应用程序没有定义权限com.example.peter.notify.permission.C2D_MESSAGE),尽管我添加了这些权限() 在清单中
    • 将您的权限中的“您的包名称”更改为“com.example.peter.notify”。此外,由于它无法识别服务,因此看起来像是 Gradle 的问题。你能发布你的build.gradle 文件吗?
    【解决方案2】:

    您的服务声明放错地方了。它必须在&lt;application/&gt; 下,与您的活动处于同一级别。

    【讨论】:

      【解决方案3】:

      在application标签下声明服务(BackendlessFCMService)。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2022-11-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-05-11
        • 2012-09-30
        相关资源
        最近更新 更多