无法解析firebase-storage-19.2.0依赖,多种尝试方案无效
Hey, I know you’ve spent hours digging into this with no luck—let’s break down your specific issues and fix them step by step, since you’ve got some constraints around keeping those Aliyun Maven sources.
First, let’s recap the core problems you’re facing:
- Adding
com.google.firebase:firebase-storage:19.2.0triggers a dependency resolution failure every time - Removing Aliyun Maven sources throws the
Cause: invalid type code: B4error, so you can’t ditch those sources entirely
Here are targeted fixes tailored to your Gradle setup:
1. Fix Version Conflicts with Firebase BOM
You’re using the Firebase BOM (com.google.firebase:firebase-bom:25.12.0) to manage versions, but you’re also hardcoding versions for some Firebase libraries (like firebase-core:17.5.1, firebase-auth:19.4.0, and firebase-storage:19.2.0). This mismatch is almost certainly causing the resolution failure when you add Storage.
Update your module-level build.gradle (:app) dependencies section to let the BOM handle all Firebase versions:
dependencies { implementation fileTree(dir: "libs", include: ["*.jar"]) implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'androidx.constraintlayout:constraintlayout:2.0.1' // Keep the BOM to manage all Firebase versions implementation platform('com.google.firebase:firebase-bom:25.12.0') implementation 'com.google.firebase:firebase-analytics' // Remove hardcoded versions—let the BOM pick compatible ones implementation 'com.google.firebase:firebase-core' implementation 'com.google.firebase:firebase-auth' implementation 'com.google.firebase:firebase-storage' testImplementation 'junit:junit:4.13' androidTestImplementation 'androidx.test.ext:junit:1.1.2' androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' }
2. Adjust Maven Source Order & Protocol
Your current Aliyun sources use HTTP, which can lead to caching or security issues. Switch to HTTPS, and reorder your repos to prioritize official Google/JCenter sources first (even if the SDK Manager doesn’t show Google repo, Gradle can still access it directly):
Update your project-level build.gradle repository sections:
buildscript { repositories { google() jcenter() // Use HTTPS for Aliyun sources, place them after official repos as fallback maven { url 'https://maven.aliyun.com/nexus/content/repositories/google' } maven { url 'https://maven.aliyun.com/nexus/content/repositories/jcenter' } } // Rest of your buildscript dependencies stay the same } allprojects { repositories { google() jcenter() maven { url 'https://maven.aliyun.com/nexus/content/repositories/google' } maven { url 'https://maven.aliyun.com/nexus/content/repositories/jcenter' } } }
3. Clear Gradle Cache & Resync
Corrupted cache is a common culprit for these weird resolution errors. Do a full cache reset:
- Go to
File > Invalidate Caches...in Android Studio, select Invalidate and Restart - Manually delete your local Gradle cache folder:
- Windows:
C:\Users\<YourUsername>\.gradle\caches - Mac/Linux:
~/.gradle/caches
- Windows:
- Click the Sync Project with Gradle Files button in the toolbar to refresh dependencies
4. Troubleshoot the "invalid type code: B4" Error
This error usually comes from corrupted cached dependencies or bad files from the repo. If the above steps don’t fix it:
- Temporarily comment out the Aliyun sources, leaving only
google()andjcenter() - Run
./gradlew clean build --refresh-dependenciesin the terminal (this forces Gradle to pull fresh dependencies from official sources) - Once the build succeeds, uncomment the Aliyun sources—Gradle will now use the fresh, valid cache instead of corrupted files
As for the SDK Manager not showing Google repo: that’s just a UI quirk. As long as google() is in your Gradle repos, Gradle can pull dependencies directly, so you don’t need to fix the SDK Manager for this issue.
内容的提问来源于stack exchange,提问作者natsunoyoru

