Android:exported needs to be explicitly specified for <service>.Apps targeting Android 12 and higher

There is an error android:exported needs to be explicitly specified for service while compiling

gradle-wrapper.properties:

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip

AndroidManifest.xml:

<?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.nari.vpn">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
    <uses-permission android:name="com.android.vending.BILLING" />

    <application
        android:name="com.nari.vpn.MainApplication"
        android:allowBackup="true"
        android:exported="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        tools:ignore="GoogleAppIndexingWarning"
        tools:targetApi="n">

        <activity
            android:name="com.nari.vpn.activity.SplashActivity"
            android:exported="true"
            android:theme="@style/splashTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="com.nari.vpn.activity.About" android:exported="true" />
        <activity android:name="com.nari.vpn.activity.Faq" android:exported="true"/> <!-- google ads -->
        <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="@string/admob_app_id" />
        <meta-data
            android:name="com.google.android.gms.ads.AD_MANAGER_APP"
            android:value="true" />

        <activity android:name="com.nari.vpn.activity.MainActivity" android:exported="true"
            android:launchMode="singleTask"
            />
    </application>

</manifest>

I specified android:exported= for all the activities but still it is giving me an error. No errors were reported as an error in the Java code itself.

EDIT:

Dependencies/Libraries used:

    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.github.AnchorFreePartner.hydra-sdk-android:sdk:3.4.0'
    implementation 'com.github.AnchorFreePartner.hydra-sdk-android:openvpn:3.4.0'
    implementation 'androidx.appcompat:appcompat:1.3.0'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.2.1'
    implementation 'com.google.android.material:material:1.5.0-alpha01'
    implementation 'com.jakewharton:butterknife:10.2.3'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.3'
    implementation 'androidx.multidex:multidex:2.0.1'

    //cutoms things
    //implementation "com.airbnb.android:lottie:3.6.0"


    //ad-mob and facebook mediation
    implementation 'com.google.android.gms:play-services-ads:20.2.0'//19.8.0
    implementation 'com.google.ads.mediation:facebook:6.5.1.0'

    //customs
    implementation 'com.github.pepperonas:materialdialog:0.3.4'
    implementation 'pl.bclogic:pulsator4droid:1.0.3'

    //Preference Library
    implementation 'com.pixplicity.easyprefs:library:1.9.0'


    //Drawer Library
    implementation 'com.infideap.drawerbehavior:drawer-behavior:1.0.1'

    //checkBox
    implementation 'net.igenius:customcheckbox:1.3'


    //Custom Toast
    implementation 'com.github.GrenderG:Toasty:1.5.0'

}

2] Updated all dependencies still not working

Upvotes: 1

Views: 1624

Answers (1)

Looping Boy
Looping Boy

Reputation: 94

The reason is because some of the dependency libraries that you're using have elements which do not have "android:exported" attribute.

You need to do this:

Lower the version in your gradle to 30 and sync and build. Go to your AndroidManifest.xml file and click on "Merged Manifest". Find items such as Activity, Receiver, Service, etc that don't have "android:exported" attribute. Then add them to your AndroidManifest.xml file in this way.

<activity
    android:name="SomeActivity"
    android:exported="false"
    tools:node="merge"
    tools:replace="android:exported" />

Now you can increase your version to 31.

I fixed it that way ! Hope it helps you !

Upvotes: 4

Related Questions