The error org.gradle.execution.TaskSelectionException: Task 'wrapper' not found in project ':app'
occurs in Gradle projects when the wrapper
task is not defined in the build.gradle
file of the specified project. This task is typically used to generate Gradle wrapper files, which are essential for ensuring consistent Gradle versions across different environments. To resolve this, you need to add the wrapper
task to your build.gradle
file.
Here are some common causes for the org.gradle.execution.TaskSelectionException: Task 'wrapper' not found in project ':app'
error:
Missing Wrapper Task in build.gradle
: The wrapper
task might not be defined in your build.gradle
file. Ensure you have the following block in your root project’s build.gradle
:
task wrapper(type: Wrapper) {
gradleVersion = '7.0'
}
Running the Command in a Subproject: The wrapper
task is typically defined in the root project. If you run the command from a subproject directory, it won’t find the task. Navigate to the root project directory and run the command again.
Deleted or Moved Wrapper Script: The gradlew
script or the gradle
directory might have been deleted or moved. Ensure these are present in your project root.
Renamed Project Directory: If the project directory has been renamed, the paths might not align correctly. Verify that the directory structure matches the expected configuration.
Gradle Version Compatibility: Ensure that the Gradle version specified in the wrapper
task is compatible with your project setup.
These steps should help you resolve the error.
Here’s a step-by-step troubleshooting guide:
Open build.gradle
File:
build.gradle
file.Check for wrapper
Task:
wrapper
task in the build.gradle
file.Add wrapper
Task:
build.gradle
file:task wrapper(type: Wrapper) {
gradleVersion = '7.0' // or your desired Gradle version
}
Save and Close:
build.gradle
file.Run the Wrapper Task:
./gradlew wrapper
Verify:
gradle-wrapper.properties
file is generated or updated in the gradle/wrapper
directory.Rebuild Project:
This should help you resolve the ‘task wrapper not found’ error.
Here are some best practices to prevent the org.gradle.execution.TaskSelectionException: Task 'wrapper' not found in project ':app'
error in future Gradle projects:
Consistent Project Structure: Ensure that your project structure is consistent and follows Gradle conventions. The wrapper
task should be defined in the root project, not in subprojects.
Define Wrapper Task: Explicitly define the wrapper
task in your root build.gradle
file if it’s missing. Add the following snippet:
task wrapper(type: Wrapper) {
gradleVersion = '7.0'
}
Run Commands from Root Directory: Always run Gradle commands from the root project directory to ensure that the wrapper
task is accessible.
Check Task Availability: Use gradle tasks
to list all available tasks and verify that the wrapper
task is listed.
Use Absolute Task Path: When running tasks from subprojects, use the absolute task path (e.g., :wrapper
) to ensure the task is correctly referenced.
Implementing these practices will help maintain a smooth Gradle build process and avoid common errors.
The ‘org.gradle.execution.TaskSelectionException: Task ‘wrapper’ not found in project ‘:app” error occurs when the wrapper task is missing from the build.gradle
file.
To resolve this, add the wrapper task to your build.gradle
file with the correct Gradle version specified. Ensure that the wrapper task is defined in the root project and not in subprojects.
Running commands from the root directory and checking task availability can also help prevent this error.
Proper Gradle configuration is crucial for a smooth build process.