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

Android: Port to NDK r23 #68

Closed
akien-mga opened this issue Jun 22, 2022 · 4 comments · Fixed by #69
Closed

Android: Port to NDK r23 #68

akien-mga opened this issue Jun 22, 2022 · 4 comments · Fixed by #69
Assignees
Labels
enhancement New feature or request

Comments

@akien-mga
Copy link
Member

akien-mga commented Jun 22, 2022

To be able to use NDK r23 for Godot 3.5, we need to change android.py as the location/names of some binaries have changed.

godotengine/godot#61691 is doing that port for Godot's SCons files, and we need to do similar changes here.

By trial and error so far I got to this:

diff --git a/android.py b/android.py
index 68917e9..4673bcc 100755
--- a/android.py
+++ b/android.py
@@ -76,7 +76,7 @@ class AndroidTargetTable:
     }
 
     host_triples = {
-        'armeabi-v7a': 'armv5-linux-androideabi',
+        'armeabi-v7a': 'armv7a-linux-androideabi',
         'arm64-v8a': 'aarch64-linux-android',
         'x86': 'i686-linux-android',
         'x86_64': 'x86_64-linux-android'
@@ -118,14 +118,14 @@ def setup_android_target_template(env: dict, opts: AndroidOpts, target: str):
     if not os.path.isdir(sdk_cmake_dir):
         print('Android CMake directory \'%s\' not found' % sdk_cmake_dir)
 
-    AR = path_join(tools_path, name_fmt % 'ar')
+    AR = path_join(tools_path, 'llvm-ar')
     AS = path_join(tools_path, name_fmt % 'as')
     CC = path_join(tools_path, name_fmt % 'clang')
     CXX = path_join(tools_path, name_fmt % 'clang++')
     DLLTOOL = ''
     LD = path_join(tools_path, name_fmt % 'ld')
     OBJDUMP = path_join(tools_path, name_fmt % 'objdump')
-    RANLIB = path_join(tools_path, name_fmt % 'ranlib')
+    RANLIB = path_join(tools_path, 'llvm-ar -s')
     CMAKE = path_join(sdk_cmake_dir, 'bin', 'cmake')
     STRIP = path_join(tools_path, name_fmt % 'strip')
 
@@ -181,7 +181,7 @@ def setup_android_target_template(env: dict, opts: AndroidOpts, target: str):
 
     LDFLAGS += [
         '-z', 'now', '-z', 'relro', '-z', 'noexecstack',
-        '-ldl', '-lm', '-llog', '-lc', '-lgcc',
+        '-ldl', '-lm', '-llog', '-lc',
         '-Wl,-rpath-link=%s,-dynamic-linker=/system/bin/linker' % path_link,
         '-L' + path_link
     ]
@@ -303,7 +303,7 @@ def setup_android_cross_template(env: dict, opts: AndroidOpts, target: str, host
     env['_android-%s_CXX' % target] = 'c++'
     env['_android-%s_CXXCPP' % target] = 'cpp'
     env['_android-%s_LD' % target] = 'ld'
-    env['_android-%s_RANLIB' % target] = 'ranlib'
+    env['_android-%s_RANLIB' % target] = 'ar -s'
     env['_android-%s_STRIP' % target] = 'strip'
 
     is_darwin = sys.platform == 'darwin'
@@ -356,12 +356,12 @@ def setup_android_cross_mxe_template(env: dict, opts: AndroidOpts, target: str,
 
     env['_android-%s_AR' % target] = path_join(mxe_bin, name_fmt % 'ar')
     env['_android-%s_AS' % target] = path_join(mxe_bin, name_fmt % 'as')
-    env['_android-%s_CC' % target] = path_join(mxe_bin, name_fmt % 'gcc')
+    env['_android-%s_CC' % target] = path_join(mxe_bin, name_fmt % 'clang')
     env['_android-%s_CXX' % target] = path_join(mxe_bin, name_fmt % 'g++')
     env['_android-%s_DLLTOOL' % target] = path_join(mxe_bin, name_fmt % 'dlltool')
     env['_android-%s_LD' % target] = path_join(mxe_bin, name_fmt % 'ld')
     env['_android-%s_OBJDUMP' % target] = path_join(mxe_bin, name_fmt % 'objdump')
-    env['_android-%s_RANLIB' % target] = path_join(mxe_bin, name_fmt % 'ranlib')
+    env['_android-%s_RANLIB' % target] = path_join(mxe_bin, name_fmt % 'ar -s')
     env['_android-%s_STRIP' % target] = path_join(mxe_bin, name_fmt % 'strip')
 
     mingw_zlib_prefix = '%s/opt/mingw-zlib/usr' % opts.mxe_prefix

Which works for a bit but now I'm down to this error:

make[3]: Entering directory '/root/mono-configs/android-armeabi-v7a-release/mono/mini'
 /usr/bin/mkdir -p '/root/mono-installs/android-armeabi-v7a-release/lib'
 ../../doltlibtool   --mode=install /usr/bin/install -c   libmonosgen-2.0.la libmono-ee-interp.la '/root/mono-installs/android-armeabi-v7a-release/lib'
libtool: install: /usr/bin/install -c .libs/libmonosgen-2.0.so /root/mono-installs/android-armeabi-v7a-release/lib/libmonosgen-2.0.so
/usr/bin/install: cannot stat '.libs/libmonosgen-2.0.so': No such file or directory
make[3]: *** [Makefile:1681: install-libLTLIBRARIES] Error 1

And indeed //root/mono-installs/android-armeabi-v7a-release/mono/mini/.libs only has libmonosgen-2.0.a and not .so, so something must have changed that makes it default to static instead of shared.

If you're interested/have time, your help would be welcome too @madmiraal to make sure we can build the Mono toolchain for Android. This repo pretty much needs similar changes as done in godotengine/godot#61691 I suppose.

Here's my current build-containers WIP update: godotengine/build-containers#109
And for this repo we'll want to build CI once ported too:

diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 528bb5b..3bc2d90 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -35,7 +35,7 @@ env:
   # platform/android/java/app/config.gradle
   ANDROID_PLATFORM: android-32
   ANDROID_API: 19
-  ANDROID_NDK_VERSION: 21.4.7075529
+  ANDROID_NDK_VERSION: 23.2.8568313
   # platform/iphone/detect.py
   IOS_VERSION_MIN: 10.0
 

I already updated to platform 32 in fcf205c.

@madmiraal
Copy link
Contributor

If you're interested/have time, your help would be welcome too @madmiraal to make sure we can build the Mono toolchain for Android. This repo pretty much needs similar changes as done in godotengine/godot#61691 I suppose.

I'll have a look and see what I can do. It's worth noting that this is an open issue on the mono repository too: mono/mono#18776.

@neikeq
Copy link
Contributor

neikeq commented Jun 24, 2022

I tried to upgrade in the past and got stuck on the same problem. These were my changes: 006930f

Do we actually need to do this for the Mono builds? Can they stay as they are now, independently of what the Godot builds use?

@akien-mga
Copy link
Member Author

Do we actually need to do this for the Mono builds? Can they stay as they are now, independently of what the Godot builds use?

That's a good question. I expected that it would be better to use the same NDK version for both, but it's worth a try.

I'll try a build of Mono with NDK r21 and then Godot with NDK r23 and then we can check if the binaries actually work or if we run into some weird binary incompatibility.

@akien-mga
Copy link
Member Author

I'll try a build of Mono with NDK r21 and then Godot with NDK r23 and then we can check if the binaries actually work or if we run into some weird binary incompatibility.

Done: https://downloads.tuxfamily.org/godotengine/testing/3.5-rc-android-scoped%2bndk23/mono/

That seems to work well from a quick test (I could export and run the Dodge the Creeps C# demo on Android with this build). So I guess there's no emergency, if that works that should be good enough for now.

akien-mga added a commit to godotengine/build-containers that referenced this issue Jun 25, 2022
Keeping NDK r21 for building Mono itself as it's not compatible yet
with NDK r22+ (see godotengine/godot-mono-builds#68).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants