How to export to gradle using BuildPipeline.BuildPlayer

I’m having a problem with exporting android project to gradle. I can do it manually with no problem. Open CMD and type gradle build. Everything is fine. What I try to achieve is to automate builds using Jenkins. I can build everything using BuildPipeline.BuildPlayer. Only problem is gradle, because unity is building apk and I would like only to export project to gradle so I can later add some stuff to gradle.build file. How I can do this using BuildPipeline.BuildPlayer?

I was stuck on this as well and couldn’t find anything in the docs.

The answer appears to be to include the BuildOptions.AcceptExternalModificationsToPlayer with the build options passed to BuildPipeline.BuildPlayer.

I’ve tested this myself and it worked.

I got the idea to try this from https://forum.unity3d.com/threads/unity-4-2-automate-export-of-google-android-project.194963/

For anyone here from the future: Try EditorUserBuildSettings.exportAsGoogleAndroidProject = true;