Android Studio项目跨电脑迁移后构建卡顿,卡在GIF库下载环节
Hey there, let’s fix this frustrating stuck download issue once and for all! I’ve run into this exact problem when moving Android Studio projects between machines, so I’ve got a few tried-and-true solutions for you.
1. 迁移本地Gradle缓存(最快的解决办法)
Your old computer already had all the downloaded dependencies stored in Gradle’s local cache—we can just copy that over to the new machine to avoid re-downloading everything:
- On your old computer, find the Gradle cache folder:
- Mac/Linux:
~/.gradle/caches - Windows:
C:\Users\<Your Username>\.gradle\caches
- Mac/Linux:
- Copy the entire
cachesfolder to the exact same path on your new computer (overwrite the existing folder if it’s already there) - Restart Android Studio and re-build your project—it should pull dependencies straight from the local cache instead of trying to download them
2. Switch to a faster Maven mirror
If you didn’t back up the cache, the default MavenCentral/JCenter servers are probably slow for your location. Let’s swap in a domestic mirror to speed up downloads:
Open your project’s root build.gradle file, find the repositories block, and replace it with:
repositories { maven { url 'https://maven.aliyun.com/repository/public/' } maven { url 'https://maven.aliyun.com/repository/google/' } maven { url 'https://maven.aliyun.com/repository/jcenter/' } google() mavenCentral() }
Also double-check your module’s build.gradle to make sure the GIF library dependency is spelled correctly—for example, the common one is:
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.28'
3. Force refresh Gradle caches
Sometimes Gradle gets stuck with stale cache data. Let’s wipe and restart:
- Click the
Sync Project with Gradle Filesbutton (the refresh icon next to the elephant in the top-right corner) - If that doesn’t work, go to
File > Invalidate Caches..., check "Invalidate and Restart", and let Android Studio reboot completely
4. Manually add the GIF library as a local dependency
If all else fails, you can download the library directly and add it to your project:
- Find the exact version of the GIF library your project uses (check your module’s
build.gradle), then download the corresponding.aarfile from a Maven repository - Create a
libsfolder in your module’s directory, and drop the.aarfile into it - Update your module’s
build.gradle:
repositories { flatDir { dirs 'libs' } } dependencies { implementation(name: 'android-gif-drawable-1.2.28', ext: 'aar') }
Make sure the name matches the .aar file you downloaded!
Quick final check
Ensure your new Android Studio has the same SDK version, Build Tools version, and NDK (if used) as your old machine—you can find these in File > Project Structure on the original computer, then install them on the new one via the SDK Manager. Missing tools can also cause stuck builds.
内容的提问来源于stack exchange,提问作者nerdydicaprio

