Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the logic to sign prebuilt Godot Android apks #44645

Merged
merged 1 commit into from
Jan 1, 2021

Conversation

m4gr3d
Copy link
Contributor

@m4gr3d m4gr3d commented Dec 24, 2020

The previously used tool, jarsigner has been deprecated in favor of apksigner which is bundled with the Android SDK.
The logic is refactored accordingly and a few editor settings have been deprecated in the process as they're no longer necessary.

Note: As a side effect, specifying the Android SDK path is now required. The docs will be updated to reflect that change.

Fixes #44587

3.2 backport

@m4gr3d
Copy link
Contributor Author

m4gr3d commented Dec 24, 2020

@godotengine/android This is being opened as a draft as the PR (especially the commands' names and extensions) still needs to be validated on Linux and Windows machines (I only have a mac with me at the moment).

In addition, a couple Android editor settings are being deprecated for which I'd like feedback on.

@mbrlabs
Copy link
Contributor

mbrlabs commented Dec 24, 2020

I tested this on Windows 10 and in all my build-tools versions (25-30) apksigner is a Java program (jar file) with a Windows batch script called apksigner.bat. Since this looks for an .exe it can't find the tool.

static String get_apksigner_path() {
String exe_ext = "";
if (OS::get_singleton()->get_name() == "Windows") {
exe_ext = ".exe";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should be changed to: exe_ext = ".bat";

Copy link
Member

@Calinou Calinou Dec 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the executable extension optional on Windows thanks to its PATHEXT environment variable?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but what this code does is actually try to find the tool, so you need the whole path incl. file extension.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Calinou there were a few bugs not too long ago where the lack of the proper extension caused issues on Windows machines (see #43671). Do you know under what conditions PATHEXT takes effect?

@mbrlabs Thanks for checking! I've updated the extension to .bat. Can you take another look.

Copy link
Contributor

@mbrlabs mbrlabs Dec 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@m4gr3d Yes, that fixed it. I also exported an APK & did a quick install via the editor -> works.

@mbrlabs
Copy link
Contributor

mbrlabs commented Dec 24, 2020

Not sure if this is related since this works now on Windows, but after quick-installing to an Android device i get this error in the Godot console:

editor\progress_dialog.cpp:231 - Condition "!tasks.has(p_task)" is true.
Installing to device (please wait...): Samsung SM-G973F

@m4gr3d
Copy link
Contributor Author

m4gr3d commented Dec 25, 2020

Not sure if this is related since this works now on Windows, but after quick-installing to an Android device i get this error in the Godot console:

editor\progress_dialog.cpp:231 - Condition "!tasks.has(p_task)" is true.
Installing to device (please wait...): Samsung SM-G973F

@mbrlabs It was an unrelated bug, but this PR surfaced it. I've fixed the issue so the error should be gone now.

@m4gr3d
Copy link
Contributor Author

m4gr3d commented Dec 25, 2020

@pouleyKetchoupp @RandomShaper Any chance you can validate this PR (and #44646) on a Linux machine?

@m4gr3d m4gr3d marked this pull request as ready for review December 26, 2020 18:00
@akien-mga
Copy link
Member

Note: As a side effect, specifying the Android SDK path is now required. The docs will be updated to reflect that change.

That's annoying :( But I guess there's no other way forward.
And at least that removes the requirement on getting a somewhat compatible version of the JDK installed manually to get jarsigner.

Comment on lines 1925 to 1942
// There are additional versions directories we need to go through.
da->list_dir_begin();
String sub_dir = da->get_next();
while (!sub_dir.empty()) {
if (!sub_dir.begins_with(".") && da->current_is_dir()) {
// Check if the tool is here.
String tool_path = build_tools_dir.plus_file(sub_dir).plus_file(apksigner_command_name);
if (FileAccess::exists(tool_path)) {
apksigner_path = tool_path;
break;
}
}
sub_dir = da->get_next();
}
da->list_dir_end();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How confident are we that the SDK structure will stay the same? Parts of it have changed every now and then causing breakage in build scripts, and it would be annoying to have users unable to export APKs because apksigner moved someplace else and our hardcoded detection logic can't find it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That directory structure has been stable for the past 4 years (since revision 24.0.3), so I don't expect it to change soon.

Nonetheless, we can add a setting entry specific to the apksigner command, and only use the hardcoded logic above as a fallback in case the setting is not specified.
As we move more toward AAB and custom build, that setting will be less and less relevant (since we leverage the gradle build process instead for these).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess let's go without extra setting for now and see how it evolves.

@akien-mga
Copy link
Member

Needs a rebase.

@akien-mga
Copy link
Member

akien-mga commented Jan 1, 2021

String::empty() was renamed to String::is_empty(), so this needs to be changed here (not in the 3.2 PR).

The previously used tool, `jarsigner` has been deprecated in favor of `apksigner` which is bundled with the Android SDK.
The logic is refactored accordingly and a few editor settings have been deprecated in the process as they're no longer necessary.

Note: As a side effect, specifying the Android SDK path is now required. The docs will be updated to reflect that change.
@akien-mga akien-mga merged commit 3433780 into godotengine:master Jan 1, 2021
@akien-mga
Copy link
Member

Thanks!

@m4gr3d m4gr3d deleted the update_apk_signing_logic branch January 1, 2021 22:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

APK can not upload to google play when set target SDK to 30
5 participants