@mars3142 I fully agree with you: everything including external libraries and cocos2d-x should be build from source code (no prebuilds *.dll, *.lib, *.a, at all in cocos2d-x\external only source code). External libraries source code should be committed to cocos2d-x repo (or added as git submodule)
I would like to add to wish list also:
Building external libraries (from source code) should be configured for all platforms (Android/Win32/macOs/iOS) and unified (currently different platform e.g. Linux and Android use different versions of external libs).
There should be easy way to reuse one build of external libraries and cocos2d-x between many games (currently “cocos gen-libs” + can be used for that)
Full CMake support for all platform
I would like to have structure like below (with source code only):
dev
…\cocos2d-x
…\cocos2d-x\external
…\my_game_1
…\my_game_2
…
…\my_Game_N
…\CMakeLists.txt
and work with CMake only
$ mkdir build_android
$ cd build_android
$ cmake …
$ cmake --build --target my_game_1 . # build cocos2d-x and \cocos2d-x\external and my my_game_1
$ cmake --build --target my_game_2 . # reuse already compiled android cocos2d-x and \cocos2d-x\external build my_game_2 only
Also make it easier to remove unused third-party libraries.
There should be #ifdef FEATURE_X around all code that requires the library in the manner that Chipmunk and others that currently allow disabling and then removing the library binary as well (from CMake or mk/project/solution).
Probably one or a few required, and those should be noted alongside the optional ones.
Edit: note that this is what cocos2d-lite is meant to achieve, at least in part, yet I think it’d be useful if not too much work to at minimum document how to do this on macOS/OSX and Windows for iOS/Android or all target platforms. I’ve also done this in a hack-y manner, which is not releasable, so it can be done. I mainly did this to get access to GLFW 3.2 before it was supported.
If you install the NDK with Android Studio, if will be located within the Android SDK ndk-bundle folder. This folder is local.properties file in the proj.android folder.
Can you help me with gen-libs? It generates prebuilt libraries just fine, they work for iOS, but for android (switching from older cocos2d-x version) I’m getting following errors when trying to compile the app:
Traceback (most recent call last):
File "/Users/piotr/sdk/ndk-bundle/build/import_abi_metadata.py", line 18, in <module>
import argparse
zipimport.ZipImportError: can't decompress data; zlib not available
Android NDK: WARNING: Ignoring unknown import directory: /Users/piotr/Documents/pierdoly/cocos2d-x-3.17_git/cocos/prebuilt-mk
Android NDK: /Users/piotr/Documents/projekty/gry/Bee/proj.android-studio/Bee/jni/Android.mk: Cannot find module with tag './prebuilt-mk' in import path
Android NDK: Are you sure your NDK_MODULE_PATH variable is properly defined ?
Android NDK: The following directories were searched:
Android NDK:
*** Android NDK: Aborting. . Stop.
Here’s Android.mk file (I’ve removed most of cpp files to reduce size):
Same problem trouble me, why we only have a gen-libs to gen prebuilt libraries, but didn’t have a option to use them. for example --use-libs, we will easy to use them if existed that option.
So how to use the prebuilt libs? I think we have to create a Android.mk to add the prebuilt libs, and include engine header files. and then use it in Gradle, it’s same as using 3rd-party prebuilt libs, a common issue to use libs by Android.mk, not a special Cocos2d-x problem.
In other side, we support cmake for the android native build in coming 3.17 release, also GitHub v3 latest code, CMake build supply another way to generate libs, and use those libs, just enable/disable option, not need to do hard works. Refer to cmake/readme to know how to use it. the gradle configs is,
// prebuilt root must be defined as a directory which you have right to access or create if you use prebuilt
// set "-DGEN_COCOS_PREBUILT=ON" and "-DUSE_COCOS_PREBUILT=OFF" to generate prebuilt, like "cocos gen-libs"
// set "-DGEN_COCOS_PREBUILT=OFF" and "-DUSE_COCOS_PREBUILT=ON" to use prebuilt, like "--use-libs"
// default behavior is both OFF, neither gen-libs nor use-libs.
arguments "-DCOCOS_PREBUILT_ROOT=/Users/laptop/cocos-prebuilt"
arguments "-DGEN_COCOS_PREBUILT=OFF", "-DUSE_COCOS_PREBUILT=ON"
and please set PROP_BUILD_TYPE=cmake to enable cmake native build, refer to this in gradle.properties
# android native code build type
# none, native code will never be compiled.
# cmake, native code will be compiled by CMakeLists.txt
# ndk-build, native code will be compiled by Android.mk
PROP_BUILD_TYPE=ndk-build
Some notes about Windows versions (win32 and win10):
(would be great to have it include in a next update)
on Win10 & Win32:
add Box2D libs from 3.15 in cocos2dx-3.17/external (for Win32 need to configure the lib for recent version of SDK and Visual studio, also setted as dll instead of static lib but not sure of what I do)
add in project .vcxproj: code “4068” in DisableSpecificWarnings (debugs & releases nodes) (to avoid pragma mark warnings)
on Win10:
get the proj.win10 back (for now I copy a directory from a cocos2dx-3.15 proj.win10 generated project)
remove all libbullet references in the yourproject.sln and App/yourproject.vcxproj files (seems that some ref are also in libcocos on Win32)
on Win32:
add “$(EngineRoot);” in the 2 AdditionalIncludeDirectories (debug & release) (to get rid of some cocos-ext include issues)
change project properties-> c/c++ -> Debug Information Format C7 compatible(/Z7)
ie in vcxproj <DebugInformationFormat>OldStyle</DebugInformationFormat>
for issues of kind “Internal Compiler Error: failed to write injected code block to PDB”
build-cfg.json is not supported, so could be deleted, in the .vcxproj file, use instead:
xcopy “$(ProjectDir)…\Resources\your_path_one” “$(OutDir)” /D /E /I /F /Y
xcopy “$(ProjectDir)…\Resources\your_path_two” “$(OutDir)” /D /E /I /F /Y
replace libcurl_impl.lib; by libcurl.lib; in release AdditionalDependencies in vcxproj