Google play console ad permission problem

Recently, I integrated IronSource ads sdk into my unity game and after building and uploading to google play console, a warning occured: “Your advertising ID declaration in Play Console says that your app uses advertising ID. A manifest file in one of your active artifacts doesn’t include the com.google.android.gms.permission.AD_ID permission.”.
After that, I turned on custom main manifest option in unity player settings
CnL8S
then added the following line in my main manifest code:

<uses-permission android:name="com.google.android.gms.permission.AD_ID"/>

Final manifest script:

<?xml version="1.0" encoding="utf-8"?>
<manifest
    xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.unity3d.player"
    xmlns:tools="http://schemas.android.com/tools">
    
    <uses-permission android:name="com.google.android.gms.permission.AD_ID" />   
    
    <application>
        <activity android:name="com.unity3d.player.UnityPlayerActivity"
                  android:theme="@style/UnityThemeSelector">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
        </activity>
    </application>
</manifest>

As a result, after re-uploading the build, I again get the same error. What could be the reason for the repeated error?

I tried the following:

  1. building without custom manifest
  2. building with custom manifest and adding
    <uses-permission android:name="com.google.android.gms.permission.AD_ID"/>
    tag
  3. adding the same tag at the end of manifest, before manifest and after application closing tags.
  4. exporting unity game, to then import it to android studio and build from there using custom manifests with the same ad permission tag as well.
  5. tried using different ad permission tag:
    <uses-permission android:name="com.google.android.gms.permission.AD_ID" tools:node="remove"/>

nothing helped

(p.s. I also built the game as an .apk file and the test ads worked fine. It probably means that ad permission worked properly, and the problem was in google play console services, or other stuff like that)

1 Like

My solution was to uncheck the Custom Main Manifest, and create this script:

#if UNITY_EDITOR && UNITY_ANDROID
using UnityEditor.Android;
using System.Xml;
using System.IO;
using System.Text;
using UnityEditor;

public class FinalAndroidManifestCheck : IPostGenerateGradleAndroidProject
{
    public int callbackOrder => 999; // High number to ensure this runs last

    public void OnPostGenerateGradleAndroidProject(string basePath)
    {
        string manifestPath = Path.Combine(basePath, "src/main/AndroidManifest.xml");
        AndroidXmlDocument manifestDoc = new AndroidXmlDocument(manifestPath);

        if (!PermissionExists(manifestDoc, "com.google.android.gms.permission.AD_ID"))
        {
            AddPermission(manifestDoc, "com.google.android.gms.permission.AD_ID");
            manifestDoc.Save();
        }
    }

    private bool PermissionExists(AndroidXmlDocument doc, string permissionName)
    {
        XmlNodeList permissions = doc.SelectNodes("/manifest/uses-permission");
        foreach (XmlNode perm in permissions)
        {
            string name = perm.Attributes["android:name"]?.InnerText;
            if (name == permissionName)
                return true;
        }
        return false;
    }

    private void AddPermission(AndroidXmlDocument doc, string permissionName)
    {
        XmlNode manifestNode = doc.SelectSingleNode("/manifest");
        XmlElement permElement = doc.CreateElement("uses-permission");
        permElement.SetAttribute(
            "name",
            "http://schemas.android.com/apk/res/android",
            permissionName
        );
        manifestNode.AppendChild(permElement);
    }
}

internal class AndroidXmlDocument : XmlDocument
{
    private string path;

    public AndroidXmlDocument(string path)
    {
        this.path = path;
        Load(path);
    }

    public void Save()
    {
        Save(path);
    }

    private void Save(string filePath)
    {
        using (var writer = new XmlTextWriter(filePath, new UTF8Encoding(false)))
        {
            writer.Formatting = Formatting.Indented;
            Save(writer);
        }
    }
}
#endif