Android Studio error: error: unknown element service found

1

Good day I have the following error with google services in firebase Android Studio

error: unknown element <service> found.

Message {kind = ERROR, text = error: unknown element found., sources = [C: \ Users \ Sony Vaio \ Desktop \ Backup_20_10_18 \ 09_08_18 \ DiabetesApp_new \ app \ build \ intermediates \ manifests \ full \ debug \ AndroidManifest .xml: 20], original message =, tool name = Optional.of (AAPT)}

And in the manifest I have this error too

And I have structured the manifest like this

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="info.androidhive.firebase"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="15"
        android:targetSdkVersion="23" />

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

    <!-- To auto-complete the email text field in the login form with the user's emails -->
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.READ_PROFILE" />
    <uses-permission android:name="android.permission.READ_CONTACTS" />

    <service android:name="info.androidhive.firebase.MyFirebaseMessagingService" >
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service>

    <uses-permission android:name="com.github.hathibelagal.pn.permission.C2D_MESSAGE" />



    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <!-- Optional permission for App measurement to run. -->
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

    <permission
        android:name="info.androidhive.firebase.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />

    <uses-permission android:name="info.androidhive.firebase.permission.C2D_MESSAGE" />

    <application
        android:allowBackup="true"
        android:debuggable="true"
        android:icon="@mipmap/ic_launcherb"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:testOnly="true"
        android:theme="@style/AppTheme" >
        <activity
            android:name="info.androidhive.firebase.LoginActivity"
            android:theme="@style/AppTheme.NoActionBar" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="info.androidhive.firebase.MainActivity"
            android:label="@string/title_activity_profile"
            android:theme="@style/AppTheme.NoActionBar" />
        <activity
            android:name="info.androidhive.firebase.SignupActivity"
            android:label="@string/title_activity_login"
            android:theme="@style/AppTheme.NoActionBar" />
        <activity
            android:name="info.androidhive.firebase.ResetPasswordActivity"
            android:label="@string/title_activity_reset_password"
            android:theme="@style/AppTheme.NoActionBar" />
        <activity
            android:name="info.androidhive.firebase.Calculate"
            android:parentActivityName="info.androidhive.firebase.MainActivity" />
        <activity
            android:name="info.androidhive.firebase.Hipoglucemia"
            android:parentActivityName="info.androidhive.firebase.MainActivity" />
        <activity
            android:name="info.androidhive.firebase.Hitorial"
            android:parentActivityName="info.androidhive.firebase.MainActivity" />
        <activity android:name="info.androidhive.firebase.Hitorial2" />
        <activity
            android:name="info.androidhive.firebase.History"
            android:parentActivityName="info.androidhive.firebase.MainActivity" />
        <!--
         FirebaseMessagingService performs security checks at runtime,
             no need for explicit permissions despite exported="true"
        -->
        <service
            android:name="com.google.firebase.messaging.FirebaseMessagingService"
            android:exported="true" >
            <intent-filter android:priority="-500" >
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
        </service>

        <receiver
            android:name="com.google.android.gms.measurement.AppMeasurementReceiver"
            android:enabled="true" >
            <intent-filter>
                <action android:name="com.google.android.gms.measurement.UPLOAD" />
            </intent-filter>
        </receiver>

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

        <activity
            android:name="com.google.android.gms.common.api.GoogleApiActivity"
            android:exported="false"
            android:theme="@android:style/Theme.Translucent.NoTitleBar" />

        <receiver
            android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver"
            android:exported="true"
            android:permission="com.google.android.c2dm.permission.SEND" >
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <action android:name="com.google.android.c2dm.intent.REGISTRATION" />

                <category android:name="info.androidhive.firebase" />
            </intent-filter>
        </receiver>
        <!--
 Internal (not exported) receiver used by the app to start its own exported services
             without risk of being spoofed.
        -->
        <receiver
            android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver"
            android:exported="false" />
        <!--
 FirebaseInstanceIdService performs security checks at runtime,
             no need for explicit permissions despite exported="true"
        -->
        <service
            android:name="com.google.firebase.iid.FirebaseInstanceIdService"
            android:exported="true" >
            <intent-filter android:priority="-500" >
                <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
            </intent-filter>
        </service>

        <provider
            android:name="com.google.firebase.provider.FirebaseInitProvider"
            android:authorities="info.androidhive.firebase.firebaseinitprovider"
            android:exported="false"
            android:initOrder="100" />

        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />

        <provider
            android:name="com.android.tools.ir.server.InstantRunContentProvider"
            android:authorities="info.androidhive.firebase.com.android.tools.ir.server.InstantRunContentProvider"
            android:multiprocess="true" />
    </application>

</manifest>

And I have the following structure in build.Gradle (app)

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion '27.0.3'

    defaultConfig {
        applicationId "info.androidhive.firebase"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    }
repositories {
    maven { url 'https://jitpack.io' }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    implementation 'com.google.firebase:firebase-auth:9.0.2'
    implementation 'com.android.support:appcompat-v7:23.4.0'
    implementation 'com.google.firebase:firebase-database:9.0.2'
    implementation 'com.android.support:design:23.4.0'
    implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3'
    implementation 'com.google.firebase:firebase-messaging:9.0.2'


}

apply plugin: 'com.google.gms.google-services'

If someone can help me please

    
asked by Julian 31.10.2018 в 21:09
source

2 answers

1

Your manifesto:

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

<uses-sdk
    android:minSdkVersion="15"
    android:targetSdkVersion="23" />

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

<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />

<service android:name="info.androidhive.firebase.MyFirebaseMessagingService" >
    <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT" />
    </intent-filter>
</service>

<uses-permission android:name="com.github.hathibelagal.pn.permission.C2D_MESSAGE" />



<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <!-- Optional permission for App measurement to run. -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

<permission
    android:name="info.androidhive.firebase.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />

<uses-permission android:name="info.androidhive.firebase.permission.C2D_MESSAGE" />

<application
    android:allowBackup="true"
    android:debuggable="true"
    android:icon="@mipmap/ic_launcherb"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:testOnly="true"
    android:theme="@style/AppTheme" >
    <activity
        android:name="info.androidhive.firebase.LoginActivity"
        android:theme="@style/AppTheme.NoActionBar" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="info.androidhive.firebase.MainActivity"
        android:label="@string/title_activity_profile"
        android:theme="@style/AppTheme.NoActionBar" />
    <activity
        android:name="info.androidhive.firebase.SignupActivity"
        android:label="@string/title_activity_login"
        android:theme="@style/AppTheme.NoActionBar" />
    <activity
        android:name="info.androidhive.firebase.ResetPasswordActivity"
        android:label="@string/title_activity_reset_password"
        android:theme="@style/AppTheme.NoActionBar" />
    <activity
        android:name="info.androidhive.firebase.Calculate"
        android:parentActivityName="info.androidhive.firebase.MainActivity" />
    <activity
        android:name="info.androidhive.firebase.Hipoglucemia"
        android:parentActivityName="info.androidhive.firebase.MainActivity" />
    <activity
        android:name="info.androidhive.firebase.Hitorial"
        android:parentActivityName="info.androidhive.firebase.MainActivity" />
    <activity android:name="info.androidhive.firebase.Hitorial2" />
    <activity
        android:name="info.androidhive.firebase.History"
        android:parentActivityName="info.androidhive.firebase.MainActivity" />
    <!--
     FirebaseMessagingService performs security checks at runtime,
         no need for explicit permissions despite exported="true"
    -->
    <service
        android:name="com.google.firebase.messaging.FirebaseMessagingService"
        android:exported="true" >
        <intent-filter android:priority="-500" >
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service>

    <receiver
        android:name="com.google.android.gms.measurement.AppMeasurementReceiver"
        android:enabled="true" >
        <intent-filter>
            <action android:name="com.google.android.gms.measurement.UPLOAD" />
        </intent-filter>
    </receiver>

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

    <activity
        android:name="com.google.android.gms.common.api.GoogleApiActivity"
        android:exported="false"
        android:theme="@android:style/Theme.Translucent.NoTitleBar" />

    <receiver
        android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver"
        android:exported="true"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />

            <category android:name="info.androidhive.firebase" />
        </intent-filter>
        </receiver>

    <receiver
        android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver"
        android:exported="false" />

    <service
        android:name="com.google.firebase.iid.FirebaseInstanceIdService"
        android:exported="true" >
        <intent-filter android:priority="-500" >
            <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
        </intent-filter>
    </service>

    <provider
        android:name="com.google.firebase.provider.FirebaseInitProvider"
        android:authorities="info.androidhive.firebase.firebaseinitprovider"
        android:exported="false"
        android:initOrder="100" />

    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

    <provider
        android:name="com.android.tools.ir.server.InstantRunContentProvider"
        android:authorities="info.androidhive.firebase.com.android.tools.ir.server.InstantRunContentProvider"
        android:multiprocess="true" />
</application>

    
answered by 31.10.2018 в 21:42
0

The error:

  

error: unknown element found.

in your case it indicates that you are actually defining the next <service> element at the permissions level, which is not valid:

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

    <service android:name="info.androidhive.firebase.MyFirebaseMessagingService" >
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service>

    <uses-permission android:name="com.github.hathibelagal.pn.permission.C2D_MESSAGE" />
...
...

you must define it within <application since the definition of services must always be defined within the <application> tag.

Review App Manifest

By the way I see that you are also using within your file Build.gradle to define the dependencies compile :

dependencies {
       compile '...'
       testCompile '...'
       compile '...'
       compile '...'
}

you must change to use now implementation :

dependencies {
       implementation '...'
       testImplementation '...'
       implementation '...'
       implementation '...'
}
    
answered by 31.10.2018 в 22:30