如何解决添加FirebaseUI Auth依赖后Gradle同步的AAPT2错误?
Hey there! I’ve run into this exact AAPT2 error before when working with FirebaseUI, so let’s break down how to fix it based on your setup.
Common Causes & Solutions
1. Mismatched compileSdkVersion with FirebaseUI Requirements
FirebaseUI Auth 3.3.0 requires a minimum compileSdkVersion of 26, but your current setup uses 24. This version mismatch is the most likely culprit for the AAPT2 error. Here’s how to fix it:
- Update your
compileSdkVersionto 26 in your app-levelbuild.gradle - Sync your
targetSdkVersionto 26 as well (best practice for consistency)
2. Resolve Dependency Conflicts
FirebaseUI relies on specific versions of Firebase and Google Play Services libraries. To avoid implicit conflicts, explicitly add compatible versions of these dependencies to your dependencies block—this ensures Gradle doesn’t pull in conflicting library versions under the hood.
3. Clean & Invalidate Caches
AAPT2 errors often stick around due to cached build files. After updating your config:
- Go to File > Invalidate Caches / Restart in Android Studio
- Select Invalidate and Restart to clear all cached data and refresh your build environment
Modified App-Level build.gradle Snippet
Here’s what your updated config should look like (relevant sections):
apply plugin: 'com.android.application' repositories { mavenLocal() flatDir { dirs 'libs' } // Make sure these repos are included to pull Firebase dependencies google() jcenter() } android { compileSdkVersion 26 buildToolsVersion '27.0.3' // This version is compatible with SDK 26 defaultConfig { applicationId "com.google.firebase.udacity.friendlychat" minSdkVersion 16 targetSdkVersion 26 // Match compileSdkVersion for consistency // ... rest of your defaultConfig settings } } dependencies { implementation 'com.firebaseui:firebase-ui-auth:3.3.0' // Explicitly add compatible Firebase/Play Services dependencies implementation 'com.google.firebase:firebase-auth:11.8.0' implementation 'com.google.android.gms:play-services-auth:11.8.0' // ... your other existing dependencies }
After making these changes, sync your Gradle project again—this should resolve the AAPT2 error.
内容的提问来源于stack exchange,提问作者Neeraj Sewani

