Google Console上传即时应用APK报错:未声明有效android:targetSandboxVersion
Let's work through resolving this common Instant App upload issue, even if you've already used the com.android.feature plugin and compressed your APKs as instructed:
Explicitly add the required attribute to your Feature module's Manifest
While thecom.android.featureplugin is supposed to auto-injectandroid:targetSandboxVersion="2"(a mandatory requirement for Instant Apps), configuration gaps can sometimes stop this from happening. Open your feature module'sAndroidManifest.xmland manually add the attribute to the root<manifest>tag:<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.your.feature.package" android:targetSandboxVersion="2">This guarantees the attribute is present, bypassing any plugin-related inconsistencies.
Confirm your Gradle plugin setup is correct
Make sure your feature modules are actually using thecom.android.featureplugin (not the standard app plugin):- For older Groovy syntax:
apply plugin: 'com.android.feature' - For newer Kotlin DSL:
plugins { id("com.android.feature") }
Also, verify your base feature module has
baseFeature trueenabled in its build config:android { baseFeature true // ... other configuration settings }- For older Groovy syntax:
Check if the attribute exists in your final signed APK
Use theaapttool to inspect the actual Manifest content inside your APK. Run this command in your terminal:aapt dump xmltree your-instant-app.apk AndroidManifest.xmlIf
targetSandboxVersionis missing from the output, clean your build cache and rebuild from scratch:./gradlew clean ./gradlew assembleReleaseStale build artifacts often cause the attribute to be omitted during the packaging process.
Validate your compressed package content
Ensure you're zipping the correct Instant App APKs—these should be split feature APKs, not a full installable app APK. Google Console requires the zip to contain only the necessary feature files for the Instant App; double-check that you didn't accidentally include the wrong build artifact in your upload package.
This error typically arises from misconfigured Gradle plugins, stale build caches, or using the wrong APK in your zip. Following these steps should get your Instant App uploaded successfully.
内容的提问来源于stack exchange,提问作者Faisal

