无法构建 Android APK - 任务“:app:mergeDebugResources”执行失败

Unable to build Android APK - Execution failed for task ':app:mergeDebugResources'

提问人:Encipherer 提问时间:5/24/2019 最后编辑:Encipherer 更新时间:5/24/2019 访问量:2257

问:

有些人将这个问题标记为重复。但是,即使我尝试了类似问题中给出的所有方法,问题仍然没有解决。aapt2.exe仍然抛出错误并说aapt2.exe停止工作。

我在Mac机器上开发了一个项目,它完全可以正常工作。现在我想把这个项目移到另一个系统,这样其他成员也可以在其中工作。当我安装 Android Studio 并在 Windows 机器中打开同一个项目时,它向我显示以下错误,我无法从该系统生成任何构建。当我尝试进行构建时,我在对话框中出现以下错误

aapt2.exe is stopped working
FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:mergeDebugResources'.
> 8 exceptions were raised by workers:
  com.android.builder.internal.aapt.v2.Aapt2InternalException: AAPT2 aapt2-3.4.1-5326820-windows Daemon #0: Daemon startup failed
  This should not happen under normal circumstances, please file an issue if it does.
  com.android.builder.internal.aapt.v2.Aapt2InternalException: AAPT2 aapt2-3.4.1-5326820-windows Daemon #6: Daemon startup failed
  This should not happen under normal circumstances, please file an issue if it does.
  com.android.builder.internal.aapt.v2.Aapt2InternalException: AAPT2 aapt2-3.4.1-5326820-windows Daemon #5: Daemon startup failed
  This should not happen under normal circumstances, please file an issue if it does.
  com.android.builder.internal.aapt.v2.Aapt2InternalException: AAPT2 aapt2-3.4.1-5326820-windows Daemon #4: Daemon startup failed
  This should not happen under normal circumstances, please file an issue if it does.
  com.android.builder.internal.aapt.v2.Aapt2InternalException: AAPT2 aapt2-3.4.1-5326820-windows Daemon #3: Daemon startup failed
  This should not happen under normal circumstances, please file an issue if it does.
  com.android.builder.internal.aapt.v2.Aapt2InternalException: AAPT2 aapt2-3.4.1-5326820-windows Daemon #2: Daemon startup failed
  This should not happen under normal circumstances, please file an issue if it does.
  com.android.builder.internal.aapt.v2.Aapt2InternalException: AAPT2 aapt2-3.4.1-5326820-windows Daemon #1: Daemon startup failed
  This should not happen under normal circumstances, please file an issue if it does.
  com.android.builder.internal.aapt.v2.Aapt2InternalException: AAPT2 aapt2-3.4.1-5326820-windows Daemon #7: Daemon startup failed
  This should not happen under normal circumstances, please file an issue if it does.

但是我可以在同一台机器上创建新项目并在其中进行构建。只有在这个迁移的项目中,我才能进行构建。我检查并更改了 Android 构建版本和 gradle 版本,还尝试使缓存失效并重新启动,但没有任何解决我的问题。Andr 我的 gradle 文件是......

App Gradle 文件

apply plugin: 'com.android.application'
//apply plugin: 'com.android.library'

android {
    compileSdkVersion 28
    buildToolsVersion "28.0.3"
    defaultConfig {
        applicationId "com.sit.novus.novusmobileframework"
        minSdkVersion 24
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

allprojects {
    repositories {
        google()
        jcenter()

    }
}

dependencies {
    //compile fileTree(dir: 'libs', include: ['*.jar'])
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    testImplementation ('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })

    //Media Picker
    implementation project(path: ':switchdatetime')
    implementation project(path: ':RTextEditorView-0.1.1')

    implementation  'com.android.support:appcompat-v7:28.0.0'
    implementation  'com.android.support:design:28.0.0'
    implementation  'com.android.support:cardview-v7:28.0.0'
    implementation  'com.github.bumptech.glide:glide:3.7.0'
    implementation  'com.android.support:recyclerview-v7:28.0.0'
    implementation  'com.android.volley:volley:1.1.0'
    implementation  'com.chootdev:csnackbar:1.3.1'
    implementation  'us.belka:androidtoggleswitch:1.2.2'
    implementation  'com.github.zcweng:switch-button:0.0.3@aar'
    implementation  'com.github.marcoscgdev:FingerAuth:1.0.0'
    implementation  'com.erikagtierrez.multiple_media_picker:multiple-media-picker:1.0.3'
    implementation  'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.jaredrummler:colorpicker:1.0.1'
    implementation 'com.droidninja:filepicker:2.2.1'

    testImplementation 'junit:junit:4.12'
}
configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        def requested = details.requested
        if (requested.group == 'com.android.support') {
            if (!requested.name.startsWith("multidex")) {
                details.useVersion '25.3.0'
            }
        }
    }
}

Project Gradle 文件

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

buildscript {
    repositories {
        maven {
            url "https://jitpack.io"
        }
        jcenter()
        google()

    }
    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 {
        maven { url 'https://jitpack.io' }
        jcenter()
    }

}

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

Gradle-Wrapper-属性

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
安卓 android-studio android-gradle-plugin android-studio-3.0 android-sdk-tools

评论

0赞 Manoj Perumarath 5/24/2019
stackoverflow.com/questions/23359572/......
0赞 Encipherer 5/24/2019
我试过了,但它并没有解决我的问题
1赞 Suraj Bahadur 5/24/2019
转到位于 Android Studio 右侧的选项,然后执行 .之后,您将看到实际错误。gradleassembleDebug
0赞 Encipherer 5/24/2019
我尝试了@SurajBahadur,我遇到了Java JDK问题,但我仍然遇到同样的问题。
1赞 Zoe is on strike 5/24/2019
升级到 Android Studio 3.4 的可能重复项 - Aapt2InternalException:AAPT2:守护程序启动失败

答:

3赞 Ranjan Kumar 5/24/2019 #1

从 Android Studio 终端/ubuntu 机器 shell 运行以下命令。

gradlew clean
gradlew assembleDebug --debug

评论

0赞 Encipherer 5/24/2019
失败:生成失败,出现异常。* 出了什么问题:任务“:switchdatetime:compileDebugJavaWithJavac”执行失败。找不到工具 .jar。请检查 C:\Program Files\Java\jre1.8.0_202 是否包含有效的 JDK 安装。
0赞 Ranjan Kumar 5/24/2019
您的 java 路径似乎设置不正确。找出您的 java jdk 在您的系统上的位置。然后修改gradle.properties文件,内容如下:org.gradle.java.home=C:\\Program Files\\Java\\jdk1.8.0_45
0赞 Encipherer 5/24/2019
谢谢兄弟,这个解决方案解决了jdk问题,但我仍然无法进行构建,aapt.exe抛出错误说它在进行构建时停止工作
0赞 Ranjan Kumar 5/24/2019
错误是什么?共享“gradlew assembleDebug --debug”命令的转储。
0赞 Nikunj Paradva 5/24/2019 #2

这是临时解决方案。

使用 Gradle 版本

 classpath 'com.android.tools.build:gradle:3.3.2'

并更改为gradle-wrapper.propertiesdistributionUrl

https\://services.gradle.org/distributions/gradle-4.10.1-all.zip