unity-builder icon indicating copy to clipboard operation
unity-builder copied to clipboard

Android build target lacks the third option of exporting an Android Studio project

Open skjalgsm opened this issue 2 years ago • 5 comments

With the option to set androidAppBundle to true we can choose wheter or not the filename is appended with either .aab or .apk https://github.com/game-ci/unity-builder/blob/main/dist/index.js line 308.

This makes an exported Android Studio project to end up in {proj_path}/build/Android/Android.apk when it should be exported to {proj_path}/build/Android/.

So I humbly ask that you either change the androidAppBundle option to androidExportType that takes in "androidPackage", "androidAppBundle", "androidStudioProject" or that you introduce a new option called exportAsGoogleProject which supersedes the androidAppBundle and exports as a project.

This is done in Unity by setting

EditorUserBuildSettings.exportAsGoogleAndroidProject = true; EditorUserBuildSettings.androidBuildSystem = AndroidBuildSystem.Gradle;

As well as

buildOptions |= BuildOptions.AcceptExternalModificationsToPlayer;

skjalgsm avatar Jun 01 '22 02:06 skjalgsm

I think "change the androidAppBundle option to androidExportType" is a good idea. However, that would be a breaking change, so it would probably have to wait until v3.0.0.

In the meantime, I think "introduce a new option called exportAsGoogleProject" is also a good idea.

I don't have the bandwidth to try to make either of these changes, but we're open to PRs.

davidmfinol avatar Jun 01 '22 05:06 davidmfinol

I suggest we introduce androidExportType in addition to the androidAppBundle option, and take precedence over it.

That way we have a forward change. Removing androidAppBundle can be part of v3.0.0 as a breaking change.

I'm not a big fan of the exportAsGoogleProject suggestion personally.

webbertakken avatar Jun 01 '22 10:06 webbertakken

I dont know js or github actions very well, so I am out of my depth here.

But would that essentially mean just adding this to input:

  static get androidExportType() {
    return Input.getInput('androidExportType') || ''; //default should be 'androidPackage' in V3 and androidAppBundle can be removed
  }

and changing the build-parameters parseBuildFile to

  static parseBuildFile(filename, platform, androidExportType, androidAppBundle) {
    if (Platform.isWindows(platform)) {
        return `${filename}.exe`;
    }
    if (Platform.isAndroid(platform)) {
        switch(androidExportType) {
            case `androidPackage`:
                return `${filename}.apk`;
            case `androidAppBundle`:
                return `${filename}.aab`;
            case `androidStudioProject`:
                return filename;
        }
        return androidAppBundle ? `${filename}.aab` : `${filename}.apk`;
    }
    return filename;
}

Or would maybe the androidStudioProject return an empty `` since its not a fileName but a directory?

And then the caller to be const buildFile = this.parseBuildFile(Input.buildName, Input.targetPlatform, Input.androidExportType, Input.androidAppBundle);

skjalgsm-statespace avatar Jun 01 '22 16:06 skjalgsm-statespace

Basically yes. And in Javascript you'd use Yarn, ESLint and Prettier (and pre-commit hook builds the dist files, the dist files are the ones that the action runs). The process is described in CONTRIBUTING.md

For example; Instead of inline comments we'd use a comment above the relevant part and the last return would have a TODO - remove in v3.0.0 above it. And you'd have to add a default case instead of a separate return. These are mostly things that ESLint and Prettier will point out or auto-format for you.

webbertakken avatar Jun 01 '22 16:06 webbertakken

I created a WIP PR that covers this issue: https://github.com/game-ci/unity-builder/pull/418 I didn't introduce androidExportType, but I added both bundle flag and export flag. If export is enabled, filename doesn't include .aab or .apk anymore, thus giving us backwards support and matching settings in Unity Editor itself. Let me know your thoughts. Use blubblub/[email protected] to test the action.

Legoless avatar Jul 28 '22 09:07 Legoless

Done by #505

davidmfinol avatar Feb 14 '23 05:02 davidmfinol