com.android.builder.internal.aapt.v2.Aapt2Exceptio

2019-07-31 02:31发布

REVISED: got a new error after upgrading to AS(3.2.1) and Gradle(4.6).

Here is build.gradle code. Gradle property has " android.enableAapt2 = true" and wrapper property has "distributionUrl=https://services.gradle.org/distributions/gradle-4.6-all.zip"

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    buildToolsVersion '28.0.3'
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/CHANGES'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/dependencies.txt'
        exclude 'META-INF/LGPL2.1'
    }
    defaultConfig {
        applicationId "com.abc.app"
        minSdkVersion 19
        targetSdkVersion 28
        versionCode 1
        versionName "1.0.0"
        multiDexEnabled true
        testInstrumentationRunner "com.android.test.runner.MultiDexTestRunner"
        vectorDrawables.useSupportLibrary = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    dexOptions {
        javaMaxHeapSize "2048M"
    }
    configurations {
        all*.exclude module: 'mediarouter-v7'
        all*.exclude module: 'support-compat'
        compile.exclude group: "org.apache.httpcomponents", module: "httpclient"
    }

    productFlavors {
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')

    implementation 'ch.acra:acra:4.9.1'

    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.android.support:recyclerview-v7:28.0.0'
    implementation 'com.android.support:support-v4:28.0.0'
    implementation 'com.android.support:multidex:1.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.android.support:percent:28.0.0'

    implementation 'com.google.android.gms:play-services:10.2.1'
    implementation 'com.google.android.gms:play-services-gcm:10.2.1'
    implementation 'com.google.android.gms:play-services-ads:10.2.1'
    implementation 'com.google.android.gms:play-services-auth:10.2.1'

    implementation 'com.google.maps.android:android-maps-utils:0.3.+'
    implementation 'de.hdodenhof:circleimageview:1.3.0'
    implementation 'com.jakewharton:butterknife:8.5.1'
    implementation 'com.uber.sdk:rides-android:0.5.3'
    implementation 'com.google.code.gson:gson:2.8.1'
    implementation 'org.jsoup:jsoup:1.11.3'
    testImplementation 'junit:junit:4.12'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
}


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

The new error is

    Caused by: com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource linking failed

C:\Users\<User>\.gradle\caches\transforms-1\files-1.1\appcompat-v7-28.0.0.aar\888450102b7519d6fb3ec4fed42688ef\res\color\abc_btn_colored_text_material.xml:20: error: attribute alpha (aka com.abc.app:alpha) not found.
C:\Users\<User>\.gradle\caches\transforms-1\files-1.1\appcompat-v7-28.0.0.aar\888450102b7519d6fb3ec4fed42688ef\res\color\abc_tint_btn_checkable.xml:19: error: attribute alpha (aka com.abc.app:alpha) not found.
C:\Users\<User>\.gradle\caches\transforms-1\files-1.1\appcompat-v7-28.0.0.aar\888450102b7519d6fb3ec4fed42688ef\res\color\abc_tint_default.xml:19: error: attribute alpha (aka com.abc.app:alpha) not found.
C:\Users\<User>\.gradle\caches\transforms-1\files-1.1\appcompat-v7-28.0.0.aar\888450102b7519d6fb3ec4fed42688ef\res\color\abc_tint_edittext.xml:19: error: attribute alpha (aka com.abc.app:alpha) not found.
C:\Users\<User>\.gradle\caches\transforms-1\files-1.1\appcompat-v7-28.0.0.aar\888450102b7519d6fb3ec4fed42688ef\res\color\abc_tint_seek_thumb.xml:19: error: attribute alpha (aka com.abc.app:alpha) not found.
C:\Users\<User>\.gradle\caches\transforms-1\files-1.1\appcompat-v7-28.0.0.aar\888450102b7519d6fb3ec4fed42688ef\res\color\abc_tint_spinner.xml:19: error: attribute alpha (aka com.abc.app:alpha) not found.
C:\Users\<User>\.gradle\caches\transforms-1\files-1.1\appcompat-v7-28.0.0.aar\888450102b7519d6fb3ec4fed42688ef\res\color\abc_tint_switch_track.xml:19: error: attribute alpha (aka com.abc.app:alpha) not found.
C:\Users\<User>\.gradle\caches\transforms-1\files-1.1\appcompat-v7-28.0.0.aar\888450102b7519d6fb3ec4fed42688ef\res\color\abc_tint_switch_track.xml:20: error: attribute alpha (aka com.abc.app:alpha) not found.
C:\Users\<User>\.gradle\caches\transforms-1\files-1.1\appcompat-v7-28.0.0.aar\888450102b7519d6fb3ec4fed42688ef\res\color\abc_tint_switch_track.xml:21: error: attribute alpha (aka com.abc.app:alpha) not found.
C:\Users\<User>\.gradle\caches\transforms-1\files-1.1\design-28.0.0.aar\d2abd1d1eab13b237ffd0fc5d63d6820\res\color\design_tint_password_toggle.xml:19: error: attribute alpha (aka com.abc.app:alpha) not found.
C:\Users\<User>\.gradle\caches\transforms-1\files-1.1\support-media-compat-28.0.0.aar\f0a6c1a9d43f0b2d6cca2c26c28e9e86\res\layout\notification_template_big_media.xml:23: error: resource layout/notification_template_icon_group (aka com.abc.app:layout/notification_template_icon_group) not found.
C:\Users\<User>\.gradle\caches\transforms-1\files-1.1\support-media-compat-28.0.0.aar\f0a6c1a9d43f0b2d6cca2c26c28e9e86\res\layout\notification_template_big_media.xml:23: error: resource dimen/notification_large_icon_height (aka com.abc.app:dimen/notification_large_icon_height) not found.
C:\Users\<User>\.gradle\caches\transforms-1\files-1.1\support-media-compat-28.0.0.aar\f0a6c1a9d43f0b2d6cca2c26c28e9e86\res\layout\notification_template_big_media.xml:23: error: resource dimen/notification_large_icon_width (aka com.abc.app:dimen/notification_large_icon_width) not found.
C:\Users\<User>\.gradle\caches\transforms-1\files-1.1\support-media-compat-28.0.0.aar\f0a6c1a9d43f0b2d6cca2c26c28e9e86\res\layout\notification_template_big_media.xml:34: error: resource dimen/notification_large_icon_width (aka com.abc.app:dimen/notification_large_icon_width) not found.
C:\Users\<User>\.gradle\caches\transforms-1\files-1.1\support-media-compat-28.0.0.aar\f0a6c1a9d43f0b2d6cca2c26c28e9e86\res\layout\notification_template_big_media.xml:34: error: resource dimen/notification_large_icon_width (aka com.abc.app:dimen/notification_large_icon_width) not found.
C:\Users\<User>\.gradle\caches\transforms-1\files-1.1\support-media-compat-28.0.0.aar\f0a6c1a9d43f0b2d6cca2c26c28e9e86\res\layout\notification_template_big_media_custom.xml:23: error: resource layout/notification_template_icon_group (aka com.abc.app:layout/notification_template_icon_group) not found.
C:\Users\<User>\.gradle\caches\transforms-1\files-1.1\support-media-compat-28.0.0.aar\f0a6c1a9d43f0b2d6cca2c26c28e9e86\res\layout\notification_template_big_media_custom.xml:23: error: resource dimen/notification_large_icon_height (aka com.abc.app:dimen/notification_large_icon_height) not found.
C:\Users\<User>\.gradle\caches\transforms-1\files-1.1\support-media-compat-28.0.0.aar\f0a6c1a9d43f0b2d6cca2c26c28e9e86\res\layout\notification_template_big_media_custom.xml:23: error: resource dimen/notification_large_icon_width (aka com.abc.app:dimen/notification_large_icon_width) not found.
C:\Users\<User>\.gradle\caches\transforms-1\files-1.1\support-media-compat-28.0.0.aar\f0a6c1a9d43f0b2d6cca2c26c28e9e86\res\layout\notification_template_big_media_custom.xml:34: error: resource dimen/notification_large_icon_height (aka com.abc.app:dimen/notification_large_icon_height) not found.

Tried many solutions including Invalidate Caches/Restart, Close and Import Project, remove cache file, reinstall Android Studio, Clean & Rebuild. None of them could make the project build successfully.

Any other possible solutions?

1条回答
【Aperson】
2楼-- · 2019-07-31 03:26

Try deleting your gradle caches. For example, on Windows:

C:\Users\[username]\.gradle\caches

then perform the following:

  1. Android Studio>File>Sync with File System
  2. Android Studio>File>Sync Project with Gradle Files
  3. Android Studio>Build> Clean Project
  4. Android Studio>Build> Rebuild Project
查看更多
登录 后发表回答