Error on Android Manifest

2020-05-09 10:49发布

问题:

I have a problem when I tried to make the App signed to distribute to Google Play. Here is the error:

Error:(22) Error: The <receiver> element must be a direct child of the <application> element [WrongManifestParent]

And the manifest:

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

    <!-- Permisos -->
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

    <!-- Optional permission for reliable local dispatching on non-Google Play devices -->
    <uses-permission android:name="android.permission.WAKE_LOCK" />

    <!-- Add the following meta-data for devices running Google Play service. -->
    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

    <!--
         Optionally, register AnalyticsReceiver and AnalyticsService to support background
         dispatching on non-Google Play devices
    -->
    <receiver
        android:name="com.google.android.gms.analytics.AnalyticsReceiver"
        android:enabled="true">
        <intent-filter>
            <action android:name="com.google.android.gms.analytics.ANALYTICS_DISPATCH" />
        </intent-filter>
    </receiver>

    <service
        android:name="com.google.android.gms.analytics.AnalyticsService"
        android:enabled="true"
        android:exported="false" />

    <!--
         Optionally, register CampaignTrackingReceiver and CampaignTrackingService to enable
         installation campaign reporting
    -->
    <receiver
        android:name="com.google.android.gms.analytics.CampaignTrackingReceiver"
        android:exported="true">
        <intent-filter>
            <action android:name="com.android.vending.INSTALL_REFERRER" />
        </intent-filter>
    </receiver>

    <service android:name="com.google.android.gms.analytics.CampaignTrackingService" />

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

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

    </application>

</manifest>

I'm not sure what's causing this. Any help is appreciated.

回答1:

Follow the Manifest file structure ......

use this

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

        <!-- Permisos -->
        <uses-permission android:name="android.permission.INTERNET" />
        <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
        <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

        <!-- Optional permission for reliable local dispatching on non-Google Play devices -->
        <uses-permission android:name="android.permission.WAKE_LOCK" />



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

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


  <!-- Add the following meta-data for devices running Google Play service. -->
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />

        <!--
             Optionally, register AnalyticsReceiver and AnalyticsService to support background
             dispatching on non-Google Play devices
        -->
        <receiver
            android:name="com.google.android.gms.analytics.AnalyticsReceiver"
            android:enabled="true">
            <intent-filter>
                <action android:name="com.google.android.gms.analytics.ANALYTICS_DISPATCH" />
            </intent-filter>
        </receiver>

        <service
            android:name="com.google.android.gms.analytics.AnalyticsService"
            android:enabled="true"
            android:exported="false" />

        <!--
             Optionally, register CampaignTrackingReceiver and CampaignTrackingService to enable
             installation campaign reporting
        -->
        <receiver
            android:name="com.google.android.gms.analytics.CampaignTrackingReceiver"
            android:exported="true">
            <intent-filter>
                <action android:name="com.android.vending.INSTALL_REFERRER" />
            </intent-filter>
        </receiver>

        <service android:name="com.google.android.gms.analytics.CampaignTrackingService" />

        </application>

    </manifest>

enjoy coding ............



回答2:

Your receiver and service elements should be in the application element, this should work:

<?xml version="1.0" encoding="utf-8"?>

<!-- Permisos -->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

<!-- Optional permission for reliable local dispatching on non-Google Play devices -->
<uses-permission android:name="android.permission.WAKE_LOCK"/>

<!-- Add the following meta-data for devices running Google Play service. -->
<meta-data
    android:name="com.google.android.gms.version"
    android:value="@integer/google_play_services_version"/>

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

            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>
    <service
        android:name="com.google.android.gms.analytics.AnalyticsService"
        android:enabled="true"
        android:exported="false"/>

    <service android:name="com.google.android.gms.analytics.CampaignTrackingService"/>

    <!--
     Optionally, register CampaignTrackingReceiver and CampaignTrackingService to enable
     installation campaign reporting
-->
    <receiver
        android:name="com.google.android.gms.analytics.CampaignTrackingReceiver"
        android:exported="true">
        <intent-filter>
            <action android:name="com.android.vending.INSTALL_REFERRER"/>
        </intent-filter>
    </receiver>

    <!--
             Optionally, register AnalyticsReceiver and AnalyticsService to support background
             dispatching on non-Google Play devices
        -->
    <receiver
        android:name="com.google.android.gms.analytics.AnalyticsReceiver"
        android:enabled="true">
        <intent-filter>
            <action android:name="com.google.android.gms.analytics.ANALYTICS_DISPATCH"/>
        </intent-filter>
    </receiver>
</application>