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 NDK 25 LTS (r25b) #7240

Merged
merged 22 commits into from Jan 16, 2023
Merged

Update NDK 25 LTS (r25b) #7240

merged 22 commits into from Jan 16, 2023

Conversation

AGulev
Copy link
Contributor

@AGulev AGulev commented Dec 23, 2022

Defold updated from NDK r20 to NDK r25b - the latesNDK version at the moment.
Now minimum Android version API is 19 (Android 4.4)

Fix #7160

@AGulev AGulev requested a review from JCash December 23, 2022 15:10
@AGulev
Copy link
Contributor Author

AGulev commented Dec 23, 2022

PR checklist (remove before merging)

  • Prepared the PR for release notes
    • Proper description of feature or fix (see example x?)
    • Added a #fixes ### if it fixes an issue
    • Assigned issue to a project
  • Added documentation for public API changes
  • Is this a new feature?
    • Added engine and/or editor unit tests
    • Added or updated manual entry

@AGulev
Copy link
Contributor Author

AGulev commented Dec 23, 2022

@@ -41,51 +36,6 @@ def glob_files(patterns, cwd=None):
os.chdir(oldcwd)
return out

# Original from wafadmin/Build.py install_files:
# I couldn't get the original code to work as I needed, so I made a small change to it.
def package_install_files(self, path, files, env=None, chmod=Constants.O644, relative_trick=False, cwd=None):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

new waf doesn't have this function
it is possible to implement it using default waf functionality

@@ -642,7 +642,7 @@
:path ["android" "version_code"]}
{:type :integer,
:help "minimum API Level required for the application to run (android:minSdkVersion)",
:default 16,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Minimum android version increased to 19

@@ -20,7 +20,7 @@ def build(bld):
target = 'crashext_null')

if 'android' in bld.env['PLATFORM']:
sig_handler = 'backtrace_libunwind.cpp'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

New backtrace unwinder implemented for Android. It uses clang libunwind

Copy link
Contributor

Choose a reason for hiding this comment

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

ANd, now we have two files using the libunwind library.
I think you need to rename one.

Note that "lib" is implicit for library names. I.e. "libunwind" == "the unwind library"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we use libunwind from NDK on Android and modified libunwind from Google for macos (because it's a bit better and can get symbols from DWARF).
What do you think is the best name backtrace_libunwind_ndk.cpp?

bld.install_files('${PREFIX}/%s-%s/lib/%s/' % (APPNAME, VERSION, bld.env.PLATFORM), bld.env.cstlib_PATTERN % 'BulletCollision')
bld.install_files('${PREFIX}/%s-%s/lib/%s/' % (APPNAME, VERSION, bld.env.PLATFORM), bld.env.cstlib_PATTERN % 'BulletDynamics')
bld.install_files('${PREFIX}/%s-%s/lib/%s/' % (APPNAME, VERSION, bld.env.PLATFORM), bld.env.cstlib_PATTERN % 'LinearMath')
bld.install_files('${PREFIX}/%s-%s/include' % (APPNAME, VERSION), bld.path.ant_glob(['**/*.h']), cwd=bld.path.find_dir(packagedir), relative_trick=True)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

it works with folders hierarhy this way

@@ -605,7 +605,7 @@ def install_sdk(self):
host = 'darwin' # our packages are still called darwin

# Android NDK
download_sdk(self, '%s/%s-%s-x86_64.tar.gz' % (self.package_path, PACKAGES_ANDROID_NDK, host), join(sdkfolder, PACKAGES_ANDROID_NDK))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the original file on google's side doesn't use-x86_64 postfix, I removed it on our side as well

@@ -63,7 +62,7 @@ if [ ! -e "${TARGET_PATH}/${ANDROID_NDK_BASENAME}.tar.gz" ]; then
# Cleanup the package, shrinking 2.9GB down to 1.6GB (extracted)
echo "Cleaning NDK" ${TMP}/${ANDROID_NDK}

(cd ${TMP} && rm -rf ${ANDROID_NDK}/prebuilt)
# keep: (cd ${TMP} && rm -rf ${ANDROID_NDK}/prebuilt) -- it's easier to rebuild packages using NDKs cmake
Copy link
Contributor Author

Choose a reason for hiding this comment

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

it is a pretty small folder (~7mb), but having it helps to rebuild packages easier

Copy link
Contributor

Choose a reason for hiding this comment

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

But for those things, we could as easily require the developer to have the NDK installed, and ANDROID_HOME etc setup?

We'll support that soon anyways so that they don't have to create/install this package. So I think that it's still something to think about, since the Docker disc space is still an issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can do removing of that folder on extender side in Dockerfile then in my PR

ANDROID_NDK_ROOT=${DYNAMO_HOME}/ext/SDKs/android-ndk-r${ANDROID_NDK_VERSION}

ANDROID_VERSION=16 # Android 4.1
ANDROID_GCC_VERSION='4.9'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

no more gcc tools in ndk25

;;

arm64-android)
export LDFLAGS="$LDFLAGS -llog"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this flag is needed for rebuilding protobuf for android

MANIFEST_MERGE_TOOL: "{{env.MANIFEST_MERGE_TOOL}}"
PATH: "{{env.ANDROID_NDK25_BIN_PATH}}:{{env.PATH}}"
NDK_LD: "{{env.ANDROID_NDK25_BIN_PATH}}/ld.lld"
NDK_CXX: "{{env.ANDROID_NDK25_BIN_PATH}}/armv7a-linux-androideabi{{env.ANDROID_NDK25_API_VERSION}}-clang++"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Taking into account specific aspects of how ProcessBuilder works, it’s important to use absolute path for the compiler. If a relative path is used, then subprocesses of the compiler are looking for the InstalledDir in PATH variable and may find a wrong one (from another SDK). For the absolute path InstalledDir detects from it.

MANIFEST_MERGE_TOOL: "{{env.MANIFEST_MERGE_TOOL}}"
PATH: "{{env.ANDROID_NDK25_BIN_PATH}}:{{env.PATH}}"
NDK_LD: "{{env.ANDROID_NDK25_BIN_PATH}}/ld.lld"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

To make sure the compiler uses the linker I expected I use absolute path for -fuse-ld.
It’s not obvious from the official clang documentation that it is possible to use absolute path, but here is a mention about this possibility.

@AGulev AGulev added breaking change Issue introducing a breaking change android Issue related to the Android platform labels Dec 23, 2022
Copy link
Contributor

@JCash JCash left a comment

Choose a reason for hiding this comment

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

LGTM, only issue is with the name of the new crash handler file.

@@ -872,8 +868,7 @@ def _strip_executable(bld, platform, target_arch, path):
if 'android' in platform:
HOME = os.environ['USERPROFILE' if sys.platform == 'win32' else 'HOME']
ANDROID_HOST = 'linux' if sys.platform == 'linux' else 'darwin'
build_tool = getAndroidBuildtoolName(target_arch)
strip = "%s/toolchains/%s-%s/prebuilt/%s-x86_64/bin/%s-strip" % (ANDROID_NDK_ROOT, build_tool, ANDROID_GCC_VERSION, ANDROID_HOST, build_tool)
strip = "%s/toolchains/llvm/prebuilt/%s-x86_64/bin/llvm-strip" % (ANDROID_NDK_ROOT, ANDROID_HOST)
Copy link
Contributor

Choose a reason for hiding this comment

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

Does the 64 bit stripnowwork on armv7` executables?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can't find docs for it (it's always isn't so easy) but I tested it and it works

@@ -0,0 +1,172 @@
// Copyright 2020-2022 The Defold Foundation
Copy link
Contributor

Choose a reason for hiding this comment

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

Now it has the same name as the macos version, "libunwind" which is very confusing.

@@ -20,7 +20,7 @@ def build(bld):
target = 'crashext_null')

if 'android' in bld.env['PLATFORM']:
sig_handler = 'backtrace_libunwind.cpp'
Copy link
Contributor

Choose a reason for hiding this comment

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

ANd, now we have two files using the libunwind library.
I think you need to rename one.

Note that "lib" is implicit for library names. I.e. "libunwind" == "the unwind library"

@@ -63,7 +62,7 @@ if [ ! -e "${TARGET_PATH}/${ANDROID_NDK_BASENAME}.tar.gz" ]; then
# Cleanup the package, shrinking 2.9GB down to 1.6GB (extracted)
echo "Cleaning NDK" ${TMP}/${ANDROID_NDK}

(cd ${TMP} && rm -rf ${ANDROID_NDK}/prebuilt)
# keep: (cd ${TMP} && rm -rf ${ANDROID_NDK}/prebuilt) -- it's easier to rebuild packages using NDKs cmake
Copy link
Contributor

Choose a reason for hiding this comment

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

But for those things, we could as easily require the developer to have the NDK installed, and ANDROID_HOME etc setup?

We'll support that soon anyways so that they don't have to create/install this package. So I think that it's still something to think about, since the Docker disc space is still an issue.

Comment on lines +36 to +38
APP_ABI := arm64-v8a #armeabi-v7a
APP_CXXFLAGS := -std=c++11 -frtti -D__STDC_LIMIT_MACROS -D_THREAD_SAFE
APP_PLATFORM := android-9
APP_PLATFORM := android-19
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this file even used now that we use the libunwind from the NDK?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no, but I would like to keep it for now, because it will be useful for libunwind**stack** building
see Libunwind
in https://docs.google.com/document/d/1uguu07VuUvBRQvJ4T_NnrfNl7q8JHZD1LF7IuePkhy4/edit#heading=h.mfeghlxitqk0

@AGulev AGulev requested a review from JCash January 9, 2023 12:29
JCash
JCash previously approved these changes Jan 10, 2023
@AGulev
Copy link
Contributor Author

AGulev commented Jan 11, 2023

@JCash thank you for review!
This PR depends on extender's PR, pls take a look when you have time defold/extender#253

@AGulev AGulev self-assigned this Jan 13, 2023
@AGulev AGulev merged commit a9d41b8 into dev Jan 16, 2023
@AGulev AGulev deleted the update-to-ndk-r25-lts branch January 16, 2023 16:29
@AGulev AGulev removed the breaking change Issue introducing a breaking change label Jan 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
android Issue related to the Android platform
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update NDK (Android NDK r25 LTS (July 2022))
2 participants