How to find the dependency that added the undesired permission
#1. Search the merge manifest log to for the undesired permission (in my case, I was looking for com.google.android.gms.permission.AD_ID):
ADDED from [com.google.android.gms:play-services-measurement:21.3.0]
/Users/<username>/.gradle/caches/.../play-services-measurement-21.3.0/AndroidManifest.xml:40:13-87
uses-permission#com.google.android.gms.permission.AD_ID
#2. When the library in question isn't a dependency you added, you'll need to check the dependency graph to locate the parent dependency.
From the command line, generate and save the dependency graph to a file: (replace app
if your app uses a different identifier)
$ ./gradlew app:dependencies > dependency-graph.log
Search the output to locate the dependency, and then follow the graph up to find its parent:
+--- com.google.firebase:firebase-crashlytics-ndk:18.4.3. <-- AHA!
| ...
+--- com.google.firebase:firebase-analytics-ktx:21.3.0
| +--- com.google.firebase:firebase-analytics:21.3.0
| | +--- com.google.android.gms:play-services-measurement:21.3.0. <-- Dependency
| | ...
In my case, com.google.android.gms:play-services-measurement:21.3.0
was being added by Crashlytics. (Not really a surprise... 😂)
I'm adding this answer because the information in the manifest merge log was insufficient to find the dependency in question, and in that regard, the OP's original question was still unanswered. Thanks to @Dharmaraj's comment on where to find the manifest merge log.