自制Android库经Jitpack引入后导致Android Studio卡顿求助
Hey there! As someone who's been through similar bumps starting out with Android library publishing, let's figure out why your Android Studio is dragging its feet after adding that SNAPSHOT dependency, and fix it up.
Why this is happening
The main culprit here is the master-SNAPSHOT version you're using. SNAPSHOT dependencies are designed for ongoing development—Jitpack will automatically check for updates to the master branch every time you sync or build your project. This constant background fetching, rebuilding, and validating of the latest snapshot version is what's slowing down Android Studio. On top of that, SNAPSHOT builds often don't get cached as effectively as stable releases, so you're repeating unnecessary work over and over.
Fixes you can try right now
1. Switch to a stable tagged release (best long-term fix)
SNAPSHOTs are great for testing in-progress changes, but for regular project use, you should publish a stable version. Here's how:
- Head over to your GitHub repo, go to the Releases section, and draft a new release. Create a tag like
v1.0.0(follow semantic versioning for clarity). - Once you publish the release, Jitpack will automatically build this stable version. Update your dependency to use the tagged version:
implementation 'com.github.ubheamar:android_core:v1.0.0'
This way, Android Studio will fetch the fixed version once, cache it, and not keep checking for updates constantly.
2. Limit SNAPSHOT update frequency (if you need to keep using SNAPSHOT)
If you still need to use the snapshot version for ongoing development, you can tell Gradle to cache it for a set period so it doesn't check for updates every single build. Add this to your root project's build.gradle file:
configurations.all { // Cache SNAPSHOT dependencies for 24 hours before checking for updates resolutionStrategy.cacheChangingModulesFor 24, 'hours' }
You can adjust the time (e.g., 7, 'days') based on how often you push changes to the master branch.
3. Optimize Android Studio's build cache
Sometimes stale or misconfigured cache can make things slower too:
- Make sure build cache is enabled: Go to File > Settings > Build, Execution, Deployment > Build Tools > Gradle and check the box for "Build cache".
- Clear invalid caches: Go to File > Invalidate Caches... and select "Invalidate and Restart". This will clear any corrupted cache files that might be causing extra overhead.
4. Trim down your library's build tasks
Double-check your library's build.gradle to make sure there aren't any unnecessary tasks running every time it's built. For example, if you don't need lint checks for the library during every project build, you can disable them:
tasks.withType(LintTask) { enabled = false }
This reduces the amount of work Android Studio has to do when syncing or building your project.
Final thought
Sticking with stable tagged releases is always the best bet for keeping your project builds fast and reliable. SNAPSHOTs are meant for short-term testing, not long-term project dependencies.
内容的提问来源于stack exchange,提问作者Amar Ubhe

