Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 77cde5b

Browse files
Jayanth-LTGRCdev
authored andcommitted
Add android support, Update README.md
Compiles and runs fine on Android platform
1 parent c2ec46f commit 77cde5b

File tree

2 files changed

+57
-4
lines changed

2 files changed

+57
-4
lines changed

README.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,16 @@ $ cd godot-cpp
7676
$ scons platform=<your platform> generate_bindings=yes
7777
$ cd ..
7878
```
79+
For android:
80+
Download latest Android NDK from official website and set NDK path.
81+
```
82+
$ export PATH="$PATH:/PATH-TO-ANDROID-NDK/toolchains/llvm/prebuilt/linux-x86_64/bin/"
83+
$ scons platform=android generate_bindings=yes
84+
```
85+
you can also specify architecture by enabling bits=64 (or 32) default is 64
86+
7987

80-
> Replace `<your platform>` with either `windows`, `linux` or `osx`.
88+
> Replace `<your platform>` with either `windows`, `linux`, `osx` or `android`.
8189
8290
> Include `use_llvm=yes` for using clang++
8391
@@ -189,6 +197,19 @@ $ link /nologo /dll /out:bin\libtest.dll /implib:bin\libsimple.lib src\init.obj
189197
*macOS*
190198
For OSX you need to find out what compiler flags need to be used.
191199
200+
*Android*
201+
```
202+
$ cd SimpleLibrary
203+
$ aarch64-linux-android29-clang -fPIC -o src/init.os -c src/init.cpp -g -O3 -std=c++14 -Igodot-cpp/include -Igodot-cpp/include/core -Igodot-cpp/include/gen -Igodot-cpp/godot_headers
204+
$ aarch64-linux-android29-clang -o bin/libtest.so -shared src/init.os -Lgodot-cpp/bin -l<name of the godot-cpp>
205+
```
206+
> use `armv7a-linux-androideabi29-clang` for 32 bit armeabi-v7a library
207+
208+
> This creates the file `libtest.so` in your `SimpleLibrary/bin` directory.
209+
210+
> You will need to replace `<name of the godot-cpp>` with the file that was created in [**Compiling the cpp bindings library**](#compiling-the-cpp-bindings-library)
211+
212+
192213
### Creating `.gdnlib` and `.gdns` files
193214
follow [godot_header/README.md](https://github.com/GodotNativeTools/godot_headers/blob/master/README.md#how-do-i-use-native-scripts-from-the-editor) to create the `.gdns`
194215

SConstruct

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ opts.Add(EnumVariable(
2929
'platform',
3030
'Target platform',
3131
host_platform,
32-
allowed_values=('linux', 'osx', 'windows'),
32+
allowed_values=('linux', 'osx', 'windows', 'android'),
3333
ignorecase=2
3434
))
3535
opts.Add(EnumVariable(
@@ -73,16 +73,23 @@ opts.Add(BoolVariable(
7373
'Generate GDNative API bindings',
7474
False
7575
))
76+
opts.Add(EnumVariable(
77+
'android_api_level',
78+
'Target Android API Level',
79+
'29',
80+
('29', '28', '27', '26')
81+
))
7682

77-
env = Environment()
83+
env = Environment(ENV = os.environ)
7884
opts.Update(env)
7985
Help(opts.GenerateHelpText(env))
8086

8187
is64 = sys.maxsize > 2**32
8288
if (
8389
env['TARGET_ARCH'] == 'amd64' or
8490
env['TARGET_ARCH'] == 'emt64' or
85-
env['TARGET_ARCH'] == 'x86_64'
91+
env['TARGET_ARCH'] == 'x86_64' or
92+
env['TARGET_ARCH'] == 'arm64-v8a'
8693
):
8794
is64 = True
8895

@@ -119,6 +126,31 @@ if env['platform'] == 'linux':
119126
env.Append(CCFLAGS=['-m32'])
120127
env.Append(LINKFLAGS=['-m32'])
121128

129+
# Add android target as it works for both armeabi-v7a and arm64-v8a architectures
130+
elif env['platform'] == 'android':
131+
# Use clang by default on android(NDK provides only clang)
132+
env['use_llvm'] = 'yes'
133+
if env['use_llvm']:
134+
if(env['bits'] == '64'):
135+
env['CXX'] = 'aarch64-linux-android' + env['android_api_level'] + '-clang++'
136+
elif(env['bits'] == '32'):
137+
env['CXX'] = 'armv7a-linux-androideabi' + env['android_api_level'] +'-clang++'
138+
139+
env.Append(CCFLAGS=['-fPIC', '-g', '-std=c++14', '-Wwrite-strings'])
140+
env.Append(LINKFLAGS=["-Wl,-R,'$$ORIGIN'"])
141+
142+
if env['target'] == 'debug':
143+
env.Append(CCFLAGS=['-Og'])
144+
elif env['target'] == 'release':
145+
env.Append(CCFLAGS=['-O3'])
146+
147+
if env['bits'] == '64':
148+
env.Append(CCFLAGS=['-m64'])
149+
env.Append(LINKFLAGS=['-m64'])
150+
elif env['bits'] == '32':
151+
env.Append(CCFLAGS=['-m32'])
152+
env.Append(LINKFLAGS=['-m32'])
153+
122154
elif env['platform'] == 'osx':
123155
# Use Clang on macOS by default
124156
env['CXX'] = 'clang++'

0 commit comments

Comments
 (0)