I had this issue and one of the libraries I used wasn’t setting it correctly.
Find location
First of all, we need to find the exact location and/or cause for the error,
which can be done with different approaches (see below).
Find by inspecting merged-manifest (approach #1)
You can find it by doing the steps:
-
Set target SDK to 30 (to silence 31+ errors).
-
Open application’s manifest (
AndroidManifest.xml
) and click on “Merged Manifest
” tab on bottom of your edit pane:
Which if you configure
build.gradle
like:allprojects { buildDir = "${rootProject.rootDir}/build/${project.name}" }
Something similar should be in a sub-path like:
build/my-app/intermediates/merged_manifest/debug/AndroidManifest.xml
-
Go to the individual manifest file of all the libraries (You can skip this step if the merged manifest is created and you can just look into the merged manifest)
-
Search if there’s any entry of type activity, service, receiver, or provider which does not have an
exported
attribute, and for each entry follow below “Fix found entries” section (or see once for how to setexported
attribute). -
Set target SDK back to 31 (or whatever it was before changing to 30).
Find by console logs (approach #2)
-
In Git-bash run something like:
./gradlew assembleDebug --stacktrace --info | tee my-logs.txt
-
Open
my-logs.txt
file (which previous step created, in your preferred text-editor). -
Now, the exact location is hidden in the logs,
hence search in the createdmy-logs.txt
file,
for these keywords:activity#
service#
receiver#
provider#
-
Which should find something like:
activity#androidx.test.core.app.InstrumentationActivityInvoker$BootstrapActivity
ADDED from [androidx.test:core:1.2.0] C:\Users\Admin\.gradle\caches\transforms-3\709730c74fe4dc9f8fd991eb4d1c2adc\transformed\jetified-core-1.2.0\AndroidManifest.xml:27:9-33:20
- Open
AndroidManifest.xml
file that previous steps did find, search if there’s any entry of typeactivity
,service
,receiver
, orprovider
which does not have anexported
attribute, and see below “Fix found entries” section (for how to set each entriesexported
attribute).
Note that (at time of writting) passing
--stacktrace
alone did not include location info 😉
Fix found entries
If the real (not build-generated) source of found entry is in root-project’s manifest (or somewhere you can alter),
set exported
attribute to corresponding need (which is normally false
) therein directly, like:
<receiver
android:name="<name_of_the_entry>"
android:exported="false or true"
tools:node="merge" />
Note that both
android:exported="..."
andtools:node="merge"
are set above.
But if found entry’s specification is written in the manifest of a third-party library (which’s real-source you can’t alter),
override the specification of said library by adding it to our root-project’s manifest, for example like:
<provider
android:name="com.squareup.picasso.PicassoProvider"
android:exported="false"
tools:node="merge"
tools:overrideLibrary="com.squareup.picasso.picasso" />
Note that this time
tools:overrideLibrary="..."
is set as well.For more information see Documentation,
and/or Similar issue in a SDK.