godotengine / godot

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

All located 'apksigner' tools in /home/apollo/Android/Sdk/build-tools failed to execute #95070

Closed farm-er closed 1 month ago

farm-er commented 2 months ago

Tested versions

4.2.2(stable)

System information

Distributor ID: Ubuntu Description: Ubuntu 22.04.4 LTS Release: 22.04

Issue description

editor/export/editor_export_platform.h:179 - Code Signing: All 'apksigner' tools located in Android SDK 'build-tools' directory failed to execute. Please check that you have the correct version installed for your target sdk version. The resulting APK is unsigned. All located 'apksigner' tools in /home/apollo/Android/Sdk/build-tools failed to execute

i followed the docs to export and debug my game on android but i get this error every time I'm trying to export for days now. tried installing all version of build-tools and changing the keystore and some solutions out there but nothing works

Steps to reproduce

just exporting to android following the steps in the docs

Minimal reproduction project (MRP)

tried it with all my projects

farm-er commented 2 months ago
# java environment variables
export JAVA_HOME=/usr/lib/jvm
export PATH=$PATH:$JAVA_HOME/bin

# android sdk environment variables
export ANDROID_HOME=~/Android/Sdk
export PATH=$PATH:$ANDROID_HOME/cmdline-tools:$ANDROID_HOME/cmdline-tools/latest/bin:$ANDROID_HOME/platform-tools

these are path variables but after i tweaked in them

i will provide anything that can help solving the issue

kus04e4ek commented 2 months ago

You should open an issue in godotengine/godot-docs, #87346 was cherry-picked for 4.2.2 and docs no longer list the correct information about requirements, use requirements from 4.3 docs to export your game

farm-er commented 2 months ago

i will try the 4.3 requirements

farm-er commented 2 months ago

Tried it again and I will more info: -- the errors: Screenshot from 2024-08-03 21-43-54 Screenshot from 2024-08-03 21-44-40

-- the export page: Screenshot from 2024-08-03 21-44-11 Screenshot from 2024-08-03 21-44-18 b.com/user-attachments/assets/f2f1a6e4-5510-43d3-a21d-ca193364092e) Screenshot from 2024-08-03 21-44-23 -- android studio packages:

Screenshot from 2024-08-03 21-46-15 Screenshot from 2024-08-03 21-46-26 Screenshot from 2024-08-03 21-46-37 Screenshot from 2024-08-03 21-46-49 Screenshot from 2024-08-03 21-47-10 Screenshot from 2024-08-03 21-47-16 Screenshot from 2024-08-03 21-47-21c516-4142-840a-1b31067acd11)

note: -- I can't some messages when i start the project that says we couldn't find build-tools version for something i don't remember I will add it if i find it. -- and after exporting usually i get like three messages in the logs like the former stating something like godot tried all build-tools version but nothing works

kus04e4ek commented 2 months ago

Try running /home/apollo/Android/Sdk/build-tools/34.0.0/apksigner --version. If it fails, check if Android Studio uses the same Android SDK path as Godot or try reinstalling 34.0.0 version of Build-Tools

farm-er commented 2 months ago

no it gives me 0.9

kus04e4ek commented 2 months ago

What does ls -l /home/apollo/Android/Sdk/build-tools/34.0.0/apksigner prints for you?

farm-er commented 2 months ago
-rwxrwxr-x 1 apollo apollo 2959 Aug  2 14:51 /home/apollo/Android/Sdk/build-tools/34.0.0/apksigner

you're thinking about permissions ?

kus04e4ek commented 2 months ago

you're thinking about permissions ?

Yes, they are the same as the ones I have and I can export just fine. At this point, I'm not really sure how to help you. Try reinstalling 34.0.0 version of Build-Tools and try to use Godot 4.3 RC2. Do you use Flatpak or something simillar instead of downloading Godot from the site?

farm-er commented 2 months ago

No I downloaded it from the site. this one https://godotengine.org/download/linux/. Yeah i don't know either how to help myself :). Maybe try a different version like 4.1 because 4.3 RC2 looks like has a lot of issues. -- Tried version 4.3 RC2 and got the same error. -- Reinstalled build-tools 34.0.0 with 4.3 RC2 and didn't work. I'm suspecting maybe something related to the JDK. Can we inspect the source of the error from the code?

kus04e4ek commented 2 months ago

I'm suspecting maybe something related to the JDK.

Don't think that's it, Godot just basically checks if /home/apollo/Android/Sdk/build-tools/34.0.0/apksigner --version fails.

Can we inspect the source of the error from the code?

You can build from source with this diff and see the output in console:

diff --git a/platform/android/export/export_plugin.cpp b/platform/android/export/export_plugin.cpp
index 5fd0039fb72..3c72c69b2b9 100644
--- a/platform/android/export/export_plugin.cpp
+++ b/platform/android/export/export_plugin.cpp
@@ -2215,10 +2215,13 @@ String EditorExportPlatformAndroid::get_apksigner_path(int p_target_sdk, bool p_
            // we only check to see if it executes on export because it is slow to load
            err = OS::get_singleton()->execute(apksigner_path, args, &output, &retval, false);
            if (err || retval) {
+               print_line(vformat("'%s' failed with errors '%d' and '%d'.", apksigner_path, (int)err, retval));
                failed = true;
            } else {
                break;
            }
+       } else {
+           print_line(vformat("'%s' not found.", apksigner_path));
        }
    }
    if (i == versions.size()) {
farm-er commented 2 months ago

I need to clone the repo and compile it then build with changes ?

kus04e4ek commented 2 months ago

I need to clone the repo and compile it then build with changes ?

Yeah

akien-mga commented 2 months ago

What is the output of java --version? You need to use Java 17 to use build-tools 34. Your distro might be using Java 11 by default, you can change it with update-alternatives or similar.

farm-er commented 2 months ago

Sorry I'm late. the output of java --version is

openjdk 17.0.12 2024-07-16
OpenJDK Runtime Environment Temurin-17.0.12+7 (build 17.0.12+7)
OpenJDK 64-Bit Server VM Temurin-17.0.12+7 (build 17.0.12+7, mixed mode, sharing)
GreatTusk commented 2 months ago

I can reproduce this issue on

Godot v4.3.stable - Debian GNU/Linux 12 (bookworm) 12 - X11 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 3070 (nvidia) - 11th Gen Intel(R) Core(TM) i5-11400F @ 2.60GHz (12 Threads)

The workaround that worked for me was launching Godot directly from the terminal.

$ ./Godot_v4.3-stable_linux.x86_64 

This is the only way I could get it to sign my game's APK.

farm-er commented 2 months ago

Cool i will try it here and with other versions

works on Godot_v4.2.2-stable_linux.x86_64 by opening it from the terminal

kus04e4ek commented 2 months ago

Don't know why I didn't thought about it earlier, but what output do you get when you open this project?

farm-er commented 2 months ago

same error

kus04e4ek commented 2 months ago

same error

This projects prints a number and an array to the console when you open it, what are the values?

GreatTusk commented 1 month ago

same error

This projects prints a number and an array to the console when you open it, what are the values?

I replaced the Android SDK path in the script with the one on my local machine, and it printed 127 [""]. When I manually ran apksigner with the --version flag in my SDK (at /build-tools/34.0.0), it returned 0.9. Do you think the issue could be related to the version of apksigner?

GreatTusk commented 1 month ago

same error

This projects prints a number and an array to the console when you open it, what are the values?

I replaced the Android SDK path in the script with the one on my local machine, and it printed 127 [""]. When I manually ran apksigner with the --version flag in my SDK (at /build-tools/34.0.0), it returned 0.9. Do you think the issue could be related to the version of apksigner?

OK, I tested this again, but this time opening Godot from the terminal, and it printed 0 ["0.9\n"]. The previous result I got was when I opened Godot by clicking its icon on my GNOME dock. It seems like this could be a permissions issue.

GreatTusk commented 1 month ago

I'm suspecting maybe something related to the JDK.

Don't think that's it, Godot just basically checks if /home/apollo/Android/Sdk/build-tools/34.0.0/apksigner --version fails.

Can we inspect the source of the error from the code?

You can build from source with this diff and see the output in console:

diff --git a/platform/android/export/export_plugin.cpp b/platform/android/export/export_plugin.cpp
index 5fd0039fb72..3c72c69b2b9 100644
--- a/platform/android/export/export_plugin.cpp
+++ b/platform/android/export/export_plugin.cpp
@@ -2215,10 +2215,13 @@ String EditorExportPlatformAndroid::get_apksigner_path(int p_target_sdk, bool p_
          // we only check to see if it executes on export because it is slow to load
          err = OS::get_singleton()->execute(apksigner_path, args, &output, &retval, false);
          if (err || retval) {
+             print_line(vformat("'%s' failed with errors '%d' and '%d'.", apksigner_path, (int)err, retval));
              failed = true;
          } else {
              break;
          }
+     } else {
+         print_line(vformat("'%s' not found.", apksigner_path));
      }
  }
  if (i == versions.size()) {

I did this and observed the following output when running the built executable by double-clicking it (there are two results because I have two versions of build-tools installed):

editor/export/editor_export_platform.h:179 - Code Signing: All 'apksigner' tools located in Android SDK 'build-tools' directory failed to execute. Please check that you have the correct version installed for your target sdk version. The resulting APK is unsigned.
'/home/myuser/Android/Sdk/build-tools/34.0.0/apksigner' failed with errors '0' and '127'.
'/home/myuser/Android/Sdk/build-tools/30.0.3/apksigner' failed with errors '0' and '127'.
  All located 'apksigner' tools in /home/f776/Android/Sdk/build-tools failed to execute

Please note that errors '0' corresponds to OK in the Error enum and that '127' is the value of retval (error code in UNIX for command not found).

Once again, running the executable from the terminal results on the export being signed successfully:

Signing binary using: 
/home/mysuer/Android/Sdk/build-tools/34.0.0/apksigner sign --verbose --ks <REDACTED> --ks-pass pass:<REDACTED> --ks-key-alias <REDACTED> ./sign.apk
Signed

According to a comment to this post in Stack Overflow, 127 can be returned if a file does not have executable permissions. However, I confirmed that my apksigner file does indeed have executable permissions (-rwxrwxrwx). The output also shows that EditorExportPlatformAndroid::get_apksigner_path successfully finds the paths for all apksigner versions, so it seems that Godot is able to locate apksigner when running outside of the terminal.

In my inexperienced opinion, since apksigner works correctly from the terminal but fails with error code 127 when double-clicking the executable, this suggests that the issue might be related to how OS.execute() behaves depending on the environment in which Godot is launched.

Anton13654 commented 1 month ago

I was getting the same error. I checked the box "build with gradle", I have successfully built the apk. After that, I unchecked "build with gradle" and started the build again, and everything was successfully built without gradle. IMPORTANT: I already had gradle before installed because I was developing Android apps in Android studio and used gradle there

Swarkin commented 1 month ago

I have the "failed to execute" error as well and running as admin works for windows.