The links of the full article:
4. Re-coding and Optimizing 64-bit Cocos¶
4.1 Compile the 64-bit third party software¶
These libraries contained in cocos2d-x are 32-bit, in order to compile 64-bit engine, we should download and compile these third party software in 64-bit mode.
Configure 64-bit compile environment:
#export CC="$NDK/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-gcc –sysroot=$NDK/platforms/android-L/arch-arm64"
#cd ~/libfreetype #./configure --host=aarch64-linux –disable-shared #make #cd ./objs/.libs/
The static library libfreetype.a is we need.
#cd ~/webp #./configure --host=aarch64-linux #make #cd ./src/.libs/
The static library libwebp.a is we need.
#cd ~/tiff #./configure --host=aarch64-linux #make #cd ./libtiff/.libs/
The static library libtiff.a is we need.
#cd ~/libfreetype #./configure --host=aarch64-linux #make #cd ./.libs/
The static library libpng.a is we need.
#cd ~/jpeg #./configure --host=aarch64-linux #make #cd ./.libs/
The static library libjpeg.a is we need.
#cd ~/libcurl #./configure --host=aarch64-linux #make #cd ./lib/.libs/
The static library libcurl.a is we need.
#cd ~/libwebsocket #./configure --host=aarch64-linux #make #cd ./objs/.libs/
The static library libwebsocket.a is we need.
4.2 Re-coding and Optimizing Cocos2d-x and apps¶
In order to compile 64-bit apps, we need change some code in cocos2d-x and apps, such as libraries, code and configuration options. In addition, for improving performance, we make some optimization in cocos2d-x engine.
Add 64bit libraries to cocos2d-x engine, libjpeg.a as a example:
#cp ~/libjpeg.a ~/cocos2d-x/external/jpeg/prebuilt/android/arm64-v8a/
By the same method to add other 64-bit third party libraries, similar as the following screen shot:
Change the Android.mk in cocos for compiler can identify the neon instruction:
Change the Application.mk in tests/cpp-tests/proj.android/jni, because of the older 64bit NDK can not identify the v register:
In the 64-bit mode, the variable intptr_t is long type, so we can not assign a int pointer to a long pointer. We should modify those error codes.
In order to obtain better performance in 64-bit mode, we optimize the math algorithm in the cocos2d-x engine, rewrite the related those code using arm64-v8a neon instruction. Detail please refer to the committed patches on the upstream (cocos2d-x project)
4.3 Build 64-bit Cocos2d-x and apps¶
To build 64-bit cocos2d-x and apps, we should use ndk-r10b and 64-bit SDK, add APP_ABI='arm64-v8a' in the compiling options:
#android list targets
#cd ~/build #python android-build.py -n "APP_ABI='arm64-v8a'" -p 20 cpp-tests
In the directory of libs, we can see arm64-v8a which include 64-bit shared library libcpp_tests.so; the 64-bit CppTests-debug.apk in directory of bin.
To be continued...