Android Studio Gradle升级失败:http://schemas.android.com/apk/res/android URI未注册
I’ve run into this exact headache when upgrading multi-project Android builds to Android Plugin for Gradle 3.0.1, so let’s walk through the most reliable fixes step by step:
1. Add Namespace Declarations to Library Modules
Starting with AGP 3.0+, library modules require a namespace property in their build.gradle file—this replaces the old reliance on the package attribute in the manifest for resource resolution. If this is missing, the resource system can fail to register the Android schema URI correctly.
For each of your three sub-project libraries, add this to the android block:
android { namespace "com.your.library.package.name" // Replace with your library's actual package // Rest of your android config... }
Pro tip: Keep this namespace matching the package attribute in the library’s AndroidManifest.xml (while AGP allows them to differ, consistency avoids unnecessary bugs).
2. Validate XML Resource xmlns Declarations
Double-check every XML file (layouts, drawables, styles, etc.) across all modules to ensure they have the correct root namespace declaration:
xmlns:android="http://schemas.android.com/apk/res/android"
Typos here (like missing a slash or misspelled domain) are a super common culprit. Also, remove any duplicate or conflicting xmlns declarations in the same file.
3. Clean and Rebuild (With Cache Clearing)
Old build artifacts often cause weird sync issues after plugin upgrades. Try this sequence:
- Run
./gradlew cleanfrom the project root (or use Android Studio’s Build > Clean Project) - Delete the
.gradlefolder in your project root to clear cached Gradle files - Re-sync the project with Gradle files (click the sync icon in the toolbar)
- Rebuild with
./gradlew assembleDebug(or Build > Rebuild Project)
4. Fix Resource Conflicts Across Modules
If multiple modules have resources with the same name (e.g., layout/main.xml in two libraries), this can break resource URI resolution. Fix it by:
- Renaming conflicting resources to be unique
- Or adding a resource prefix to each library’s
build.gradleto enforce unique names:android { resourcePrefix "feature1_" // Replace with a unique prefix for the module // ... }
This forces all resources in the library to start with feature1_, eliminating collisions.
5. Verify Project-Level Gradle Configs
Make sure your project-level files are correctly set for AGP 3.0.1 and Gradle 4.1:
Project build.gradle:
buildscript { repositories { google() jcenter() } dependencies { classpath 'com.android.tools.build:gradle:3.0.1' } }
gradle-wrapper.properties:
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
If none of these steps work, check for custom Gradle plugins or scripts that might be modifying resource processing—sometimes third-party tools aren’t fully compatible with AGP 3.0.1 yet.
内容的提问来源于stack exchange,提问作者kencorbin

