How to change build system to gradle from script

I am now build project by gradle from unity, and I have a question :how to do the follow by the script:

  1. change build system to Gradle;
  2. let Custom Gradle Template and User Proguard File checked;
  3. let use existing keystore checked and set keystore path;

Hope for your reply, Thank you very much.

You can accomplish somewhat of your requirement using ‘PlayerSettings’ and ‘EditorUserBuildSettings’ classes

Here’s an example

using UnityEditor;

public class CustomBuildSettings:MonoBehaviour
    [MenuItem("Tools/Change Build System")]
    private static void Init()
        //Switch to android build target if not
        if(EditorUserBuildSettings.activeBuildTarget!= BuildTarget.Android)
            EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.Android, BuildTarget.Android);

        //Change build system to gradle
        EditorUserBuildSettings.androidBuildSystem = AndroidBuildSystem.Gradle;