Tag Archives: Error:Execution failed for tas

Error:Execution failed for task’:app:processDebugResources’. Personally resolved

 
Personal problem scenario: While compiling the ListView list, R reported an error while initializing data in the main class, and the resource file could not be found
Personal problem: There is a problem with the image placed in the Drawable folder under the RES resource. (Goole took a look and realized that everyone has different questions.)
Drawable official document
 
Drawable Resources
SEE ALSO

    2D Graphics

A drawable resource is A general concept for A graphic that can be drawn to the screen and which you can retrieve with APIs such as getDrawable(int) or apply to another XML resource with Attributes such as android:drawable and android:icon. There are several different types of drawables:
 
Bitmap: the simplest Drawable, a PNG or JPEG image.Nine Patch: an extension to the PNG format allows it to specify information about how to stretch it and place things inside of it.Shape: contains simple drawing commands instead of a raw bitmap, allowing it to resize better in some cases.Layers: a compound drawable, which draws multiple underlying drawables on top of each other.States: a compound drawable that selects one of a set of drawables based on its state.Levels: a compound drawable that selects one of a set of drawables based on its level.Scale: a compound drawable with a single child drawable, whose overall size is modified based on the current level.
 
(1) person when writing code is in a hurry, there is no ready ahead of the corresponding image, to find the pictures of a few Zhang Xihuan in computer, copy and paste under the drawable, R resource file in your code, display, the introduction of resource R file error, an error found reasons: after examining locat drawable image size is too large;
(2) and remove the big picture, and try to find a few icon in the diagram, the result still R file Error, locat in display Error: Execution failed for task ‘: app: processDebugResources’. The official document was searched with the problem and it was finally found that the image resource file under the Drawable folder was incorrect. After the deletion, the program runs normally and the list shows success.
Error: Execution failed for task ‘: app: processDebugResources’ – the cause of the problem may be different, everyone for locat hints, in combination with the official API documentation, to find the corresponding solution.
 
Appendix summary of solutions to problems occurring in the build project (long-term update)
1) third-party dependency conflict the | dependency library version is inconsistent with the SDK version
Solution – Add to build.gradle:

android{
	configurations.all {
        resolutionStrategy.eachDependency { DependencyResolveDetails details ->
            def requested = details.requested
            if (requested.group == 'com.android.support') {
                if (requested.name.startsWith("appcompat-v7")) {
                    details.useVersion '25.3.0'
                }
                if (requested.name.startsWith("appcompat-v4")) {
                    details.useVersion '25.3.0'
                }

                if (requested.name.startsWith("recyclerview-v7")) {
                    details.useVersion '25.3.0'
                }
            }
        }
    }

}

Force all dependent libraries to use the same version without having to look up each one.
2) Mandatory version number
Sometimes a third-party Lib USES a higher version of support package, and there may be a problem with it. You don’t want to introduce a problem because of this Lib, and you don’t want to automatically upgrade the current support package because of it.
Gradle’s default mechanism, however, is to use the higher version if it has a higher version, which puts it in a dilemma: using the Lib will upgrade the Supprot package, but not using it will make it impossible to implement certain functions. Fortunately, Configations provides the ability to force a version specified.
First, configure a Task in root build.Gradle to view the current version information of the support library.

subprojects {
    task allDeps(type: DependencyReportTask) { }
}

Now force the version number of the Support library:

    configurations.all {
        // 指定某个库的版本
        resolutionStrategy.force "com.android.support:appcompat-v7:26.1.0"
    }

3) Change the name of the output APK

static def releaseTime() {
    return new Date().format("yyyy-MM-dd", TimeZone.getTimeZone("UTC"))
}
android {
        ... ...
    buildTypes {
        ... ...
    }
    android.applicationVariants.all { variant ->
        variant.outputs.all { output ->
            def outputFile = output.outputFile
            if (outputFile != null && outputFile.name.endsWith('.apk')) {
                def fileName = outputFile.name.replace("app",
                        "${defaultConfig.applicationId}_${defaultConfig.versionName}_${releaseTime()}" )
                outputFileName = fileName
            }
        }
    }

}

The Task above can name APK as “package name + version name + production time”.