如何修复任务':app:mergeDebugResources'

时间:2019-05-29 07:45:01

标签: java android gradle android-gradle

我已更新至Android 3.4,并且正在使用TO-DO应用,当我想运行它时,却出现了此错误:

Executing tasks: [:app:assembleDebug]

> Task :app:preBuild UP-TO-DATE
> Task :app:preDebugBuild UP-TO-DATE
> Task :app:compileDebugAidl NO-SOURCE
> Task :app:compileDebugRenderscript NO-SOURCE
> Task :app:checkDebugManifest UP-TO-DATE
> Task :app:generateDebugBuildConfig UP-TO-DATE
> Task :app:prepareLintJar UP-TO-DATE
> Task :app:generateDebugSources UP-TO-DATE
> Task :app:javaPreCompileDebug UP-TO-DATE
> Task :app:mainApkListPersistenceDebug UP-TO-DATE
> Task :app:generateDebugResValues UP-TO-DATE
> Task :app:generateDebugResources UP-TO-DATE
> Task :app:mergeDebugResources FAILED

Execution failed for task ':app:mergeDebugResources'
>1 exception was raised by workers:
  com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource compilation failed
  C:\Users\CHARAN\Desktop\Android Development\BPTODO\app\src\main\res\drawable-v24\ic_launcher_foreground.xml:11: error: not well-formed (invalid token).
  C:\Users\CHARAN\Desktop\Android Development\BPTODO\app\src\main\res\drawable-v24\ic_launcher_foreground.xml: error: file failed to compile.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 35s
8 actionable tasks: 1 executed, 7 up-to-date

我尝试过 1.清理和重建 2.使缓存无效并重新启动 3.更改gradle依赖关系 这是android studio建议的 Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights. 甚至尝试过

成绩(项目)

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

buildscript {
    repositories {
        google()
        jcenter()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.1'

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

allprojects {
    repositories {
        google()
        jcenter()

    }
}

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

Gradle(app)


android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.bptodo"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.android.support:recyclerview-v7:28.0.0'
}

Activity_main.xml

<LinearLayout
    android:orientation="vertical"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#F4F4F4"
    tools:context=".MainActivity">


    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:background="#1eea40"
        android:layout_height="198dp">

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <LinearLayout
                android:layout_marginLeft="16dp"
                android:orientation="vertical"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">

                <TextView
                    android:id="@+id/titlepage"
                    android:layout_marginTop="20dp"
                    android:textSize="32sp"
                    android:textColor="#FFF"
                    android:text="TO DO's"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />

                <TextView
                    android:id="@+id/subtitlepage"
                    android:textSize="18sp"
                    android:textColor="#4A4E6A"
                    android:layout_marginTop="8dp"
                    android:text="Finish Them Quickly Today"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />

            </LinearLayout>

            <Button
                android:id="@+id/btnAddNew"
                android:layout_width="99dp"
                android:layout_height="52dp"
                android:layout_marginLeft="60dp"
                android:layout_marginTop="35dp"
                android:background="@drawable/bgbtnnew"
                android:text="+"
                android:textAlignment="center"
                android:textColor="#FFF"
                android:textSize="38sp" />

        </LinearLayout>

        <View
            android:layout_marginTop="20dp"
            android:layout_width="match_parent"
            android:background="#131E69"
            android:layout_height="1dp" />

    </LinearLayout>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/ourdoes"
        android:layout_width="match_parent"
        android:layout_marginTop="-60dp"
        android:layout_marginRight="16dp"
        android:layout_marginLeft="16dp"
        android:layout_height="wrap_content">

    </android.support.v7.widget.RecyclerView>

    <TextView
        android:id="@+id/endpage"
        android:textSize="16sp"
        android:textColor="#9A9A9A"
        android:layout_marginTop="20dp"
        android:text="No More Does"
        android:textAlignment="center"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
</LinearLayout>

“我希望输出平稳,请帮助” 预先感谢

2 个答案:

答案 0 :(得分:0)

构建>清理项目

./gradlew clean build

在各个应用的 build.gradle 部分android {}中,插入:

aaptOptions {  
    cruncherEnabled = false  
}

答案 1 :(得分:0)

检查文件:res\drawable-v24\ic_launcher_foreground.xml

您的错误表明它的格式不正确。这意味着存在一些语法错误或错字或缺少括号,或者可能没有图像。