godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
87.14k stars 19.57k forks source link

Failed to sign apk when exporting from Godot.app on macOS #81240

Open pgdanes opened 10 months ago

pgdanes commented 10 months ago

Godot version

v4.1.1.stable.official [bd6af8e0e]

System information

Godot v4.1.1.stable - macOS 13.5.0 - Vulkan (Compatibility) - Apple M2 - Apple M2 (8 Threads)

Issue description

Exporting android project fails to sign using apksigner when running godot from applications folder via Godot.app

All located 'apksigner' tools in /Users/pdanes/Library/Android/sdk/build-tools failed to execute

However, when running godot executable from terminal via /Applications/Godot.app/Contents/MacOS/Godot or open Godot.app it succeeds.

Steps to reproduce

Using Application directory Godot.app

  1. Run Godot.app via Applications directory
  2. Export android project via Project > Export > (select android export settings) > Export APK

Output:

All located 'apksigner' tools in /Users/pdanes/Library/Android/sdk/build-tools failed to execute

Above also happens when using One Click Deploy

Using the terminal 1.a.Run godot from terminal by opening /Applications/Godot.app/Contents/MacOS/Godot 1.b. Run godot from terminal by running open /Applications/Godot.app

  1. Select same project
  2. Export android project via Project > Export > (select android export settings) > Export APK

Output:

Signing binary using: 
/Users/pdanes/Library/Android/sdk/build-tools/33.0.2/apksigner sign --verbose --ks <REDACTED> --ks-pass pass:<REDACTED> --ks-key-alias <REDACTED> /path/to/apk/export/game.apk
Signed

Minimal reproduction project

N/A

I tested with a blank project setup to the bare minimum of requirements to export to android and have the same issue.

pgdanes commented 10 months ago

This seems to be due to path variable that Godot opens with by default

Running Godot.app through Finder/Spotlight and then executing

print_debug(OS.get_environment("path"))

outputs:

/usr/bin:/bin:/usr/sbin:/sbin

Whereas, running through terminal would pick up my entire path variable, most importantly: /opt/homebrew/opt/openjdk/bin

I'm not sure whether the mac editor should be picking up the entire path? Or would be if I had installed openJDK outside of homebrew?

akien-mga commented 10 months ago

That's by design when running from Finder, macOS doesn't give access to shell environment stuff.

I guess there might be a way to register this in the global PATH for all applications?

But AFAIK it's a macOS intentional limitation and not a Godot bug. CC @bruvzg

bruvzg commented 10 months ago

But AFAIK it's a macOS intentional limitation and not a Godot bug.

It is a macOS limitation, apps ignore all shell environment variables, there's no way to change it globally. But an app can change its environment itself. So I guess we can add common paths like hombrew and macports to the PATH or add an editor setting to do it manually (trying to parse shell configs is probably gonna be overkill).

bruvzg commented 10 months ago

Whereas, running through terminal would pick up my entire path variable, most importantly: /opt/homebrew/opt/openjdk/bin

Usually, JDK on macOS should be installed in /Library/Java/JavaVirtualMachines and operate via /usr/bin/java wrapper, so it's not dependent on PATH. I guess in this particular case, it's probably an issue with incomplete JDK install.

pgdanes commented 10 months ago

Whereas, running through terminal would pick up my entire path variable, most importantly: /opt/homebrew/opt/openjdk/bin

Usually, JDK on macOS should be installed in /Library/Java/JavaVirtualMachines and operate via /usr/bin/java wrapper, so it's not dependent on PATH. I guess in this particular case, it's probably an issue with incomplete JDK install.

Yeah this seems the case, reinstalling through brew outputs this line as help afterwards:

For the system Java wrappers to find this JDK, symlink it with
  sudo ln -sfn /opt/homebrew/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk

Ran the command provided by homebrew and retested Godot.app opened from Finder and it exports fine.

It might still be worth adding homebrew/other package manager paths in the editors environment? Or expanding on the error from apksigner (if it even reports any more info)?

Alex2782 commented 10 months ago

@manake did you install the JDK correctly via .msi file? I might try it on Windows 10 later for comparison.

https://docs.godotengine.org/en/latest/tutorials/export/exporting_for_android.html https://adoptium.net/de/temurin/releases/?variant=openjdk11&os=windows

for macOS there is a solution if you do not install it as described in the doc. This is badly comparable with Windows.

For the system Java wrappers to find this JDK, symlink it with
  sudo ln -sfn /opt/homebrew/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
Calinou commented 10 months ago

Please don't derail the discussion on whether this feature is needed or not. We need to fix the issue regardless, or improve the documentation.

phaitonican commented 2 months ago

same error on my nixos either maybe i do something wrong idk