dpa99c / cordova-plugin-firebasex

Cordova plugin for Google Firebase
MIT License
570 stars 457 forks source link

How to remove the `com.google.android.gms.permission.AD_ID` permission on Android? #861

Closed adipascu closed 3 months ago

adipascu commented 3 months ago

How to remove the com.google.android.gms.permission.AD_ID permission on Android? I am asking because it's active, we need to report that the app uses advertising IDs on the Play Console, while this is not the case.

dpa99c commented 3 months ago

FIREBASE_ANALYTICS_WITHOUT_ADS plugin variable - see the docs

YRafalsky commented 3 months ago

new requirement of Play Store is to have this permission if you use FireBase SDK. Permission will be added by cordova framework despite value of this FIREBASE_ANALYTICS_WITHOUT_ADS var because permission will be inherited from firebase by Gradle manifest merger during "compile" phase Wasted 2 days to find this out. All you need to do is to confirm you use this permission and specify your need of this permission (Analytics in my case)

dpa99c commented 3 months ago

@YRafalsky if the FIREBASE_ANALYTICS_WITHOUT_ADS plugin variable is set, the plugin uncomments the following line which is added to AndroidManifest.xml:

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

The attribute tools:node="remove" overrides any other inclusion of this permission during the compile phase (such as by Firebase) to ensure the final manifest used for the app build does not contain it.

YRafalsky commented 3 months ago

@dpa99c i did it. After it didn't work - i put hook on "before_compile", took plugin.xml, uncommented string "<uses-permission android:name="com.google.android.gms.permission.AD_ID" tools:node="remove"/>" and on next cordova run i replaced your plugin.xml with mine to be sure this line will be there - no result

part of manifest-merger-blame-release-report.txt

26    <uses-permission android:name="com.google.android.gms.permission.AD_ID" />
26-->[com.google.android.gms:play-services-measurement-api:21.5.0] /root/.gradle/caches/transforms-3/be1a9dd618d01a74d1814267dac664e8/transformed/jetified-play-services-measurement-api-21.5.0/AndroidManifest.xml:25:5-79
26-->[com.google.android.gms:play-services-measurement-api:21.5.0] /root/.gradle/caches/transforms-3/be1a9dd618d01a74d1814267dac664e8/transformed/jetified-play-services-measurement-api-21.5.0/AndroidManifest.xml:25:22-76

part of build log . "IAM BEFORE COMPILE HOOK" is message from my before_compile.js hook where i replace your plugin.xml with my with explicit node <uses-permission android:name="com.google.android.gms.permission.AD_ID" tools:node="remove"/>

This app does not have splash screens defined
Updating splash screens at platforms/android/app/src/main/res
Updating resource files at platforms/android
  copy  resources/values/colors.xml platforms/android/app/src/main/res/values/colors.xml (updated file)
Prepared android project successfully
Executing script found in plugin cordova-plugin-firebasex for hook "after_prepare": plugins/cordova-plugin-firebasex/scripts/after_prepare.js
cordova-plugin-firebasex: Preparing Firebase on Android
cordova-plugin-firebasex: Updated colors.xml with accent color
Executing script found in config.xml for hook "before_compile": before_compile.js
IAM BEFORE COMPILE HOOK
Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOT=/opt/android-sdk-linux (recommended setting)
ANDROID_HOME=/opt/android-sdk-linux (DEPRECATED)
Using Android SDK: /opt/android-sdk-linux

part of my config.xml

    <preference name="android-targetSdkVersion" value="33" />

    <plugin name="cordova-plugin-firebasex" spec="https://github.com/dpa99c/cordova-plugin-firebasex.git#16.4.0-cli" >
        <variable name="IOS_STRIP_DEBUG" value="true"  />
        <variable name="FIREBASE_ANALYTICS_WITHOUT_ADS" value="true" />
    </plugin>

    <engine name="ios" spec="6.2.0" />
    <engine name="android" spec="~9.0.0" />

part of generated cordova/platforms/android/app/build/outputs/sdk-dependencies/release/sdkDependencies.txt file:

library {
  maven_library {
    groupId: "com.google.android.gms"
    artifactId: "play-services-measurement-api"
    version: "21.5.0"
  }
  digests {
    sha256: "hL\225\312\377K\005>9\237\265\0275\351\364\310\334.\2307\212I\b\003/\310\256qy\v3\260"
  }
}

generated cordova/platforms/android/project.properties

# This file was originally created by the Android Tools, but is now
# used by cordova-android to manage the state of the various third party
# libraries used in your application

# This is the Library Module that contains the Cordova Library, this is not
# required when using an AAR

# This is the application project.  This is only required for Android Studio Gradle projects

# Project target.
target=android-33
android.library.reference.1=CordovaLib
android.library.reference.2=app
cordova.gradle.include.1=cordova-plugin-firebasex/ip-build.gradle
cordova.system.library.1=com.google.android.gms:play-services-auth:20.7.0
cordova.system.library.2=com.google.firebase:firebase-analytics:21.5.0
cordova.system.library.3=com.google.firebase:firebase-messaging:23.3.1
cordova.system.library.4=com.google.firebase:firebase-config:21.5.0
cordova.system.library.5=com.google.firebase:firebase-perf:20.5.0
cordova.system.library.6=com.google.firebase:firebase-auth:22.2.0
cordova.system.library.7=com.google.firebase:firebase-firestore:24.9.1
cordova.system.library.8=com.google.firebase:firebase-functions:20.4.0
cordova.system.library.9=com.google.firebase:firebase-iid:21.1.0
cordova.system.library.10=com.google.firebase:firebase-installations:17.2.0
cordova.system.library.11=com.google.firebase:firebase-crashlytics:18.5.1
cordova.system.library.12=com.google.firebase:firebase-crashlytics-ndk:18.5.1
cordova.system.library.13=com.google.code.gson:gson:2.9.0
cordova.system.library.14=io.grpc:grpc-okhttp:1.46.0

Google says If your app uses an SDK that has declared the Ad ID permission, it will acquire the permission declaration through manifest merge. link to decompiled fork of library that gives me this permission https://github.com/dandar3/android-google-play-services-measurement-sdk-api/blob/d1519077fde577d1ab8ca04f1af7f039513cb418/AndroidManifest.xml#L28 - here is explicit declaration

using: gradle-7.1.1 npm install -g cordova@11.0

P.S. Found this lib here https://github.com/dpa99c/cordova-android-play-services-gradle-release/blob/master/plugin.xml#L51 and here https://github.com/dpa99c/cordova-plugin-firebasex/blob/master/plugin.xml#L43 Not sure if it helps. Not an expert of cordova at all

dpa99c commented 3 months ago

You need to set the plugin variable in package.json not config.xml because this is where Cordova now reads the plugin variables from. I know this feature works as I use it production on several apps and have no need to declare use of the AD ID permission.

YRafalsky commented 3 months ago

@dpa99c package dependencies: "cordova-plugin-firebasex": "git+https://github.com/dpa99c/cordova-plugin-firebasex.git#16.4.0-cli" package cordova/plugins:

"cordova-plugin-firebasex": {
        "IOS_STRIP_DEBUG": true,
        "FIREBASE_ANALYTICS_WITHOUT_ADS": true
      },
dpa99c commented 3 months ago

If you set it after installing the plugin you must remove and re add the plugin to apply the change. Then if it doesn't appear in AndroidManiifest, remove and readd the android platform

YRafalsky commented 3 months ago

@dpa99c it's installed from scratch in docker container

build command is:

let regularIcon = 'cordova-res android --icon-source icon.png --type icon'
  let adaptiveIcon = "cordova-res android --icon-foreground-source adaptive-icon.png --icon-background-source '#ffffff' --type adaptive-icon"

cd cordova && cordova platform rm ' + platform + ' && cordova platform add ' + platform +' && ' + regularIcon + ' && ' + adaptiveIcon + ' && cordova build ' + platform + ' -d --release --buildConfig=./old_apk_config/apk_build.json -- --packageType=apk

as you see i rm platform on each build

dFelinger commented 3 months ago

Cause of this issue is old npm version which does not run the postinstall script from plugin's package.json. Just update your node version.