You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何解决添加FirebaseUI Auth依赖后Gradle同步的AAPT2错误?

Fixing AAPT2 Error When Adding FirebaseUI Auth Dependency

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 compileSdkVersion to 26 in your app-level build.gradle
  • Sync your targetSdkVersion to 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 08:44:29