Home > Mobile >  How to switch all the modules in a project from debug to release in Android Studio?
How to switch all the modules in a project from debug to release in Android Studio?

Time:01-31

I opened enter image description here

EDIT1:

Tried to run switchToRelease task from the answer, but got the following error:

Build file 'D:\dev\repos\Vulkan\android\build.gradle' line: 24

Execution failed for task ':switchToRelease'.
> No signature of method: org.gradle.api.internal.StartParameterInternal.getEnabledProjects() is applicable for argument types: () values: []

CodePudding user response:

You can create a Gradle task to switch all the modules at once. Here are the steps:

Open the build.gradle file for your project. Add the following code:

task switchToRelease {
    doLast {
        for (project in gradle.startParameter.getEnabledProjects().toList()) {
            project.buildType = "release"
        }
    }
}

CodePudding user response:

Alternative Answer:-

You can switch all the modules at once by using the command line. Here are the steps:

  1. Open a terminal window in Android Studio.

  2. Change the current directory to your project's root directory.

  3. Run the following command:

    ./gradlew assembleRelease
    

This command will build all the modules in your project with the release build type, which is typically optimized for performance and doesn't include debug information.

  • Related