【问题标题】:How to resolve AAPT2 error?如何解决 AAPT2 错误?
【发布时间】:2018-09-17 08:18:31
【问题描述】:

自从我添加implementation 'com.firebaseui:firebase-ui-auth:3.3.0' 后,我正在通过firebase 进行身份验证,我在同步gradle 后收到AAPT2 error: check logs for details 错误。 这是我的 build.gradle 文件。

build.gradle(app)

apply plugin: 'com.android.application'
repositories {
mavenLocal()
flatDir {
    dirs 'libs'
}
}

android {
compileSdkVersion 24
buildToolsVersion '27.0.3'

defaultConfig {
    applicationId "com.google.firebase.udacity.friendlychat"
    minSdkVersion 16
    targetSdkVersion 24
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
packagingOptions {
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/LICENSE-FIREBASE.txt'
    exclude 'META-INF/NOTICE'
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
testImplementation 'junit:junit:4.12'

implementation 'com.android.support:design:24.2.1'
implementation 'com.android.support:appcompat-v7:24.2.1'


//  Firebase
implementation 'com.google.firebase:firebase-database:12.0.1'

implementation 'com.firebaseui:firebase-ui-auth:3.3.0'
implementation 'com.google.firebase:firebase-auth:12.0.1'

// Displaying images
implementation 'com.github.bumptech.glide:glide:3.6.1'
}

apply plugin: 'com.google.gms.google-services'

还有 build.gradle(Project)

// Top-level build file where you can add configuration options common to 
all sub-projects/modules.

buildscript {
repositories {
    jcenter()
    mavenLocal()
    google()
}
dependencies {
    classpath 'com.android.tools.build:gradle:3.1.0'
    classpath 'com.google.gms:google-services:3.2.1' // google-services 
plugin



    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}
}

allprojects {
repositories {
    jcenter()
    mavenLocal()
    maven {
        url "https://maven.google.com" // Google's Maven repository
    }
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}

我删除此implementation 'com.firebaseui:firebase-ui-auth:3.3.0' 的那一刻,错误就消失了。我认为添加这个是在创建AAPT2 error。

Google SDK Tools、Google Repository 和 Google Play Services 也已安装。还请解释这是什么AAPT2 error,如果可能的话,这是如何发生的。

【问题讨论】:

  • 在 gradle 控制台中运行 assembleDebug 以查找导致错误的特定行。
  • @Abhi 查看问题的编辑版本。我在那里提到了导致错误的行。
  • 是否 assembleDebug 将该行作为错误原因?可能还有其他冲突的错误。

标签: android android-studio android-gradle-plugin android-studio-3.0 aapt2


【解决方案1】:

使用这个

implementation 'com.android.support:design:27.0.3'
implementation 'com.android.support:appcompat-v7:27.0.3'

不是这个

implementation 'com.android.support:design:24.2.1'
implementation 'com.android.support:appcompat-v7:24.2.1'

更新compileSdkVersion 27 和targetSdkVersion 27

【讨论】:

  • @a_petrolhead 打开gradle.properties 并添加:android.enableAapt2=false
  • @a_petrolhead 测试用例尝试更新compileSdkVersion 27 和targetSdkVersion 27
  • @a_petrolhead 你可以试试
  • 当我评论此implementation 'com.firebaseui:firebase-ui-auth:3.3.0' 时,在同步 gradle 之后我没有收到任何错误。所以,我不认为改变 sdk 版本会有所帮助。 `
  • 将 compilesdkversion 和 targetsdkversion 更新到 27 工作。我认为,由于我使用的是最新版本的 FirebaseDatabase 和 Firebase 身份验证依赖项,因此有必要将 sdk 版本更新到最新版本。感谢您的帮助。
【解决方案2】:

在 Android Studio 中,当您使用 gradle 3.0 的 android 插件时,默认启用 Aapt2。

这主要是为了改进增量资源处理,查看this页面了解更多信息。

如果您不想看到此错误,可以通过在 gradle.properties 中添加以下行来禁用它。

android.enableAapt2=false

【讨论】:

  • 这不是修复,只是一种解决方法,现在可能已弃用。
【解决方案3】:

已解决!!问题出在版本控制上。

还必须更新您应用的 build.gradle 以指定至少 26 的 compileSdkVersion (Android O)

我花了几个小时才弄明白。

在此处阅读更多信息,https://firebase.googleblog.com/2017/08/some-updates-to-apps-using-google-play.html

【讨论】:

    猜你喜欢
    • 2019-01-23
    • 2021-03-26
    • 2021-04-26
    • 1970-01-01
    • 1970-01-01
    • 2021-12-29
    • 2018-06-30
    • 2012-02-18
    • 2011-08-30
    相关资源
    最近更新 更多