Android Studio构建Debug APK时Gradle超时及提取APK无法安装求助
Hey there, I’ve dealt with these exact headaches before— let’s break down how to fix each problem:
1. Why the extracted Instant Run APK can’t be installed
Instant Run generates incremental, split APKs instead of a single complete package. These are designed only to work with the specific device and session you used to deploy via Instant Run, so they’ll throw "corrupted package" errors when installed elsewhere.
Fix:
- Disable Instant Run first: Go to
File > Settings > Build, Execution, Deployment > Instant Runand uncheck all options. - Restart Android Studio, then rebuild your project from scratch.
2. Gradle stuck when building Debug APK
This is usually tied to cached data, offline mode limitations, or compatibility issues. Try these steps in order:
- Turn off Gradle Offline Mode:
Head toFile > Settings > Build, Execution, Deployment > Gradleand uncheck "Offline work". Sometimes offline mode can cause Gradle to hang if it’s missing cached dependencies that it needs to resolve for a full build. - Clean up cached files:
- Delete the
.gradlefolder in your project’s root directory. - Delete the
buildfolder inside your app module. - Click
Build > Clean Project, thenBuild > Rebuild Project.
- Delete the
- Update Gradle to a stable version:
Open your project-levelbuild.gradlefile and make sure you’re using a recent stable Gradle plugin version. For example:dependencies { classpath 'com.android.tools.build:gradle:7.4.2' // Use a stable version compatible with your AS } - Temporarily disable Lint checks:
Lint can sometimes slow down builds drastically. Add this to your app-levelbuild.gradleto skip it temporarily:android { lintOptions { checkReleaseBuilds false abortOnError false } }
Final Steps
Once you’ve fixed the Gradle stuck issue, go to Build > Build Bundle(s) / APK(s) > Build APK(s). This will generate a complete, installable Debug APK in app/build/outputs/apk/debug/ that works on any compatible device.
内容的提问来源于stack exchange,提问作者Nithis

