Error while compiling native build

Hello everyone,
I’m getting the following error while compiling native build.
error 1:
Build command failed. Error while executing process D:\AndroidStudio\Android\Sdk\ndk\16.1.4479499\ndk-build.cmd with arguments {NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=D:\Projects\CoffeeHallowScream\nativebuild\jsb-default\frameworks\runtime-src\proj.android-studio\app\jni\Android.mk NDK_APPLICATION_MK=D:\Projects\CoffeeHallowScream\nativebuild\jsb-default\frameworks\runtime-src\proj.android-studio\app\jni\Application.mk APP_ABI=x86_64 NDK_ALL_ABIS=x86_64 NDK_DEBUG=0 APP_PLATFORM=android-21 NDK_OUT=D:/Projects/CoffeeHallowScream/nativebuild/jsb-default/frameworks/runtime-src/proj.android-studio/app/build/intermediates/ndkBuild/release/obj NDK_LIBS_OUT=D:\Projects\CoffeeHallowScream\nativebuild\jsb-default\frameworks\runtime-src\proj.android-studio\app\build\intermediates\ndkBuild\release\lib NDK_TOOLCHAIN_VERSION=clang NDK_MODULE_PATH=D:\Projects\Scream\nativebuild\jsb-default\frameworks\cocos2d-x;D:\Projects\Scream\nativebuild\jsb-default\frameworks\cocos2d-x\cocos;D:\Projects\Scream\nativebuild\jsb-default\frameworks\cocos2d-x\external -j4 NDK_DEBUG=0 D:/Projects/CoffeeHallowScream/nativebuild/jsb-default/frameworks/runtime-src/proj.android-studio/app/build/intermediates/ndkBuild/release/obj/local/x86_64/libcocos2djs.so} Android NDK: WARNING: Unsupported source file extensions in D:\Projects\CoffeeHallowScream\nativebuild\jsb-default\frameworks\cocos2d-x/cocos/Android.mk for module cocos2dx_static Android NDK: ../external/sources/edtaa3func/edtaa3func.h renderer/memop/RecyclePool.hpp

error 2:
Build command failed. Error while executing process D:\AndroidStudio\Android\Sdk\ndk\16.1.4479499\ndk-build.cmd with arguments {NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=D:\Projects\Multi-resolution-adaption\build\jsb-link\frameworks\runtime-src\proj.android-studio\app\jni\Android.mk NDK_APPLICATION_MK=D:\Projects\Multi-resolution-adaption\build\jsb-link\frameworks\runtime-src\proj.android-studio\app\jni\Application.mk APP_ABI=x86_64 NDK_ALL_ABIS=x86_64 NDK_DEBUG=1 APP_PLATFORM=android-21 NDK_OUT=D:/Projects/Multi-resolution-adaption/build/jsb-link/frameworks/runtime-src/proj.android-studio/app/build/intermediates/ndkBuild/debug/obj NDK_LIBS_OUT=D:\Projects\Multi-resolution-adaption\build\jsb-link\frameworks\runtime-src\proj.android-studio\app\build\intermediates\ndkBuild\debug\lib NDK_TOOLCHAIN_VERSION=clang NDK_MODULE_PATH=C:\CocosDashboard_1.0.18\resources\.editors\Creator\2.4.4\resources\cocos2d-x;C:\CocosDashboard_1.0.18\resources\.editors\Creator\2.4.4\resources\cocos2d-x\cocos;C:\CocosDashboard_1.0.18\resources\.editors\Creator\2.4.4\resources\cocos2d-x\external -j4 NDK_DEBUG=1 D:/Projects/Multi-resolution-adaption/build/jsb-link/frameworks/runtime-src/proj.android-studio/app/build/intermediates/ndkBuild/debug/obj/local/x86_64/libcocos2djs.so} Android NDK: WARNING: Unsupported source file extensions in C:\CocosDashboard_1.0.18\resources\.editors\Creator\2.4.4\resources\cocos2d-x/cocos/Android.mk for module cocos2dx_static Android NDK: ../external/sources/edtaa3func/edtaa3func.h renderer/memop/RecyclePool.hpp

clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [D:/Projects/Multi-resolution-adaption/build/jsb-default/frameworks/runtime-src/proj.android-studio/app/build/intermediates/ndkBuild/release/obj/local/armeabi-v7a/libcocos2djs.so] Error 1
NDK path: D:\AndroidStudio\Android\Sdk\ndk\19.2.5345600
SDK path: D:\AndroidStudio\Android\Sdk
How can I resolve this?
Thank you

I can ask engineering to review this topic. What version of Creator are you using?

We have dealt with similar issues before, and this is caused by a bug in the native engine.
According to the error message, because the .hpp file was introduced by android.mk and cannot be recognized (this may be a limitation of android studio), the problem can be solved by removing the introduction of .hpp

1 Like

Thank you for your reply.
when I run gulp init I’m getting following error:
ReferenceError: primordials is not defined at fs.js:40:5 at req_ (D:\Projects\CoffeeHallowScream\HallowScream\cocos2d-x\node_modules\natives\index.js:143:24) at Object.req [as require] (D:\Projects\CoffeeHallowScream\HallowScream\cocos2d-x\node_modules\natives\index.js:55:10) at Object.<anonymous> (D:\Projects\CoffeeHallowScream\HallowScream\cocos2d-x\node_modules\vinyl-fs\node_modules\graceful-fs\fs.js:1:37) at Module._compile (internal/modules/cjs/loader.js:1085:14) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10) at Module.load (internal/modules/cjs/loader.js:950:32) at Function.Module._load (internal/modules/cjs/loader.js:790:12) at Module.require (internal/modules/cjs/loader.js:974:19) at require (internal/modules/cjs/helpers.js:93:18)
is this required or can I directly click compile engine in developer panel?
Thank you

Hi, you can try to copy the native engine (cocos-2dx) from the editor’s installation directory, and then come to modify the native engine’s code, you don’t need to execute the gulp command anymore. (Remember to specify the native engine path on the Creator’s editor)

@muxiandong I also have another question in native build, like if there are multiple scenes, all the resources of all the scenes will be present locally right when we install the apk file?
Like for the web platform we had a loading text while opening another scene since it used to take some time to download the resource but in native also it happens and it takes some to load, is this the actual behaviour or is it not fetching from local?
Thank you

Thank you. Will check this out.
I upgraded to 2.4.6 version and it works there.

@maheshn
You can use director.preloadScene to preload the scene resources, and then use loadscene to load the scene when you want to switch to the specified scene.
This preload scene, however, may only some shorten the time and may be constrained by different platforms.
Of course, we recommend you to consider using prefabricated bodies to make different scenes to be loaded as prefabricated bodies.
https://docs.cocos.com/creator/api/en/classes/Director.html#preloadscene