Ad

Execution Failed For Task ':app:mergeDebugResources' When Building Project On Jenkins

I'm trying to build an Android application with jenkins but I'm getting "Execution failed for task ':app:mergeDebugResources'" error each time I try it.

I saw that the problem could be that the path is too large and AAPT2 is displaying an error because of that. I tried moving the directory of my project and adding "multiDexEnabled true" on my build gradle but it seems that nothing of this works

Gradle version:

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

This is my build gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.calculator"
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }
    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'
}

And this is the error I get each time I try to build my project with Jenkins

Execution failed for task ':app:mergeDebugResources'.
> 8 exceptions were raised by workers:
  com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource compilation failed
  C:\Windows\System32\config\systemprofile\.gradle\caches\transforms-2\files-2.1\2e8dd75caf52c41c02aeae6cef700c6a\res\drawable-xxhdpi-v4\abc_text_select_handle_middle_mtrl_light.png: error: file not found.

  com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource compilation failed
  C:\Windows\System32\config\systemprofile\.gradle\caches\transforms-2\files-2.1\2e8dd75caf52c41c02aeae6cef700c6a\res\layout\abc_action_bar_up_container.xml: error: file not found.

  com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource compilation failed
  C:\Windows\System32\config\systemprofile\.gradle\caches\transforms-2\files-2.1\2e8dd75caf52c41c02aeae6cef700c6a\res\drawable-xhdpi-v4\abc_ab_share_pack_mtrl_alpha.9.png: error: file not found.

  com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource compilation failed
  C:\Windows\System32\config\systemprofile\.gradle\caches\transforms-2\files-2.1\2e8dd75caf52c41c02aeae6cef700c6a\res\anim\abc_tooltip_exit.xml: error: file not found.

  com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource compilation failed
  C:\Windows\System32\config\systemprofile\.gradle\caches\transforms-2\files-2.1\2e8dd75caf52c41c02aeae6cef700c6a\res\layout\abc_search_dropdown_item_icons_2line.xml: error: file not found.

  com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource compilation failed
  C:\Windows\System32\config\systemprofile\.gradle\caches\transforms-2\files-2.1\2e8dd75caf52c41c02aeae6cef700c6a\res\drawable-hdpi-v4\abc_ic_menu_share_mtrl_alpha.png: error: file not found.

  com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource compilation failed
  C:\Windows\System32\config\systemprofile\.gradle\caches\transforms-2\files-2.1\2e8dd75caf52c41c02aeae6cef700c6a\res\drawable\abc_btn_colored_material.xml: error: file not found.

  com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource compilation failed
  C:\Windows\System32\config\systemprofile\.gradle\caches\transforms-2\files-2.1\2e8dd75caf52c41c02aeae6cef700c6a\res\drawable-hdpi-v4\abc_textfield_search_default_mtrl_alpha.9.png: error: file not found.
Ad

Answer

Run following commands from your jenkins terminal.

    gradlew clean
    gradle assembleDebug

If above command does not work, then delete gradle folder.

    rm -rf C:\Windows\System32\config\systemprofile\.gradle

and then build using command

    gradle assembleDebug
Ad
source: stackoverflow.com
Ad