game-ci / unity-builder

Build Unity projects for different platforms
https://github.com/marketplace/actions/unity-builder
MIT License
851 stars 251 forks source link

Keystore & password #34

Closed Haelle closed 3 years ago

Haelle commented 4 years ago

Is there a way to pass the keystore file in the parameters ? And also the password ? (using github secrets)

Should it be in the customParameters ?

webbertakken commented 4 years ago

@Haelle thanks for your request!

I do not know your current context. Could you tell us a bit more about what you are trying to do? Links to official documentation of related tools would be very helpful too.

Technically you could pass anything in customParameters but it depends on the build method what happens to it.

What would be your suggested approach or desired API?

Haelle commented 4 years ago

To deploy to the Google PlayStore you need to sign your application. It's done with a keystore.

In Unity you can then set your keystore in the Publishing menu.

And everytime you want to build your app you need to provide the password of the keystore via the Editor actually.

So for instance via Unity Cloud build you can provide in their web interface the keystore and the password (cannot show sorry). Here is the info in the FAQ section Android, 2rd question

I've never worked with the command line tool, so currently I have no idea how you're doing the command line build... I suppose there is a way to sign the app (as Unity Cloud Build does it !)

marco-perin commented 4 years ago

Looking at here, the GabLeRoux unity3d library lets you specify the keystore by binary64 formatting it and putting it in a repos' secret variable

dabo248 commented 4 years ago

@Haelle did you find a solution for this?

webbertakken commented 4 years ago

Feel free to open a PR with your suggested approach. You're free to make any additions to the builder method, as long as it's usable for everyone.

Haelle commented 4 years ago

This is in pending on my side, I'll come back to it later

webbertakken commented 4 years ago

@Haelle did you work this out? Anything we can reuse for everyone?

Haelle commented 4 years ago

No sorry CI is postponed indefinitely for the moment

davidmfinol commented 4 years ago

Added these parameters: androidAppBundle, androidKeystoreName, androidKeystoreBase64, androidKeystorePass, androidKeyaliasName, androidKeyaliasPass

I tested with my personal project, but maybe someone else can test with their project to confirm? You would pass through GitHub Secrets in your workflow like this:

      - uses: webbertakken/unity-builder@6ece6447b229baedca54df3aae22fc3d097bc4f3
        with:
          unityVersion: ${{ matrix.unityVersion }}
          targetPlatform: ${{ matrix.targetPlatform }}
          buildsPath: builds
          androidAppBundle: true
          androidKeystoreName: keystore.keystore
          androidKeystoreBase64: ${{ secrets.ANDROID_KEYSTORE_BASE64 }}
          androidKeystorePass: ${{ secrets.ANDROID_KEYSTORE_PASS }}
          androidKeyaliasName: ${{ secrets.ANDROID_KEYALIAS_NAME }}
          androidKeyaliasPass: ${{ secrets.ANDROID_KEYALIAS_PASS }}
louis030195 commented 4 years ago

@davidmfinol did you successfully built & sign android? I had working Android build then added the android signing options in order to publish to Google Play and it fails:

UnityException: Can not sign the application Unable to sign the application; please provide passwords!

https://github.com/louis030195/niwrad/runs/1221825955?check_suite_focus=true#step:4:3197

However i properly set my secrets etc.

Run webbertakken/unity-builder@v1.2 with: customParameters: -niwradMode offline projectPath: . unityVersion: 2019.4.11f1 targetPlatform: Android buildMethod: Editor.Builds.BuildOptions androidAppBundle: true androidKeystoreName: .keystore androidKeystoreBase64: androidKeystorePass: androidKeyaliasName: androidKeyaliasPass: buildsPath: builds kubeContainerMemory: 800M kubeContainerCPU: 0.25 kubeVolumeSize: 5Gi versioning: Semantic env: UNITY_LICENSE:

https://github.com/louis030195/niwrad/runs/1221825955?check_suite_focus=true#step:4:1

What is actually "androidKeystoreName" ? Since you store the b64 keystore in your secrets ...

I generated my keys using unity IDE btw (first tried CLI but better trust Unity ...)

FYI my Android build config

image

learned that you can't do arm64 with Mono, so IL2CPP has to be used and target API should be >=29 to publish to Google Play.

davidmfinol commented 4 years ago

I had working Android builds, but they've been broken for a while now, since the Android images don't have the Android NDK properly set. Are you able to get past that error?

The androidKeystoreName is the name of the file, while androidKeystoreBase64 is the contents of that file, encoded in base64.

Your workflow looks good to me. Are you applying the passwords in your Editor.Builds.BuildOptions method? If not, see https://github.com/finol-digital/Card-Game-Simulator/blob/e3d90591b5df4b0b4be9dc64a913da5084eeedad/Assets/Scripts/Cgs/Editor/BuildCgs.cs#L35 for how it can be done.

louis030195 commented 4 years ago

I had working Android builds, but they've been broken for a while now, since the Android images don't have the Android NDK properly set. Are you able to get past that error?

The androidKeystoreName is the name of the file, while androidKeystoreBase64 is the contents of that file, encoded in base64.

Your workflow looks good to me. Are you applying the passwords in your Editor.Builds.BuildOptions method? If not, see https://github.com/finol-digital/Card-Game-Simulator/blob/e3d90591b5df4b0b4be9dc64a913da5084eeedad/Assets/Scripts/Cgs/Editor/BuildCgs.cs#L35 for how it can be done.

I don't understand "The androidKeystoreName is the name of the file", you don't commit any keystore file anywhere, it's just base64 content ? What file are you referring to ?

I think this doc is much nicer, I hope something similar would be put on the unity-ci website https://gitlab.com/gableroux/unity3d-gitlab-ci-example#android-support Thanks for the build options, now I'm stuck at the same point as you : Android NDK, would be nice to automatically use an image with android ndk whenever it's required (building .aab ?).
Also wondering how it works for the api levels if the image can build for any sdk version ?

webbertakken commented 4 years ago

This is the PR that indended to do that (until i renamed master to main). It's a work in progress by @GabLeRoux

Feel free to contribute and help out.

Could you also elaborate on what's nicer about it exactly? Perhaps we could learn from that.

GabLeRoux commented 4 years ago

Also curious on that, but I happen to have gone through the unity-ci docs for github-actions today and I think that the main difference is the approach.

Right now, github-actions documentation provides parts of code that you need to assemble on your own to get things working where on unity3d-gitlab-ci-example's side, you simply grab the files, add them to your project and follow activation steps.

I think this can be easily solved by providing working files out of the box in the documentation and then do the more modular explanation on how things work and how they can customize it for people who want to go deeper.

I'd say most of the use cases are the following:

  1. I want automatic builds for my game for my platforms, ie; windows, linux, mac, webgl, ios, android
  2. I want to run tests in the cloud for edit and play mode
  3. If I have code coverage out of the box without efforts, why not. (replace code coverage with wathever feature we may have an example for that is easy to integrate).

Everything else is probably secondary.

webbertakken commented 4 years ago

Yea fully agree! Anyone is free to edit the docs or describe feature requests here.

I see you've already created one issue regarding improvements https://github.com/Unity-CI/Website/issues/46 @GabLeRoux, thanks!

davidmfinol commented 3 years ago

Since keystore & password are supported now, do we want to close this issue?

Or do we want to keep this issue open until the documentation is improved?

webbertakken commented 3 years ago

Yea lets close it. Anyone is free to add to the docs.