Android prebuilt library! How solve?!

What are the errors? You haven’t shown the actual errors, so there is no information to help diagnose the problem. Also, what are the contents of the main project gradle.build file, and the CMakeLists.txt file in the root folder of your game?

CMakeLists.txt and cocos2d in root is present
I only make a new cocos project and i edited:

gradle.properties

PROP_APP_ABI=armeabi-v7a:x86
PROP_BUILD_TYPE=cmake

MyGame

    else if (PROP_BUILD_TYPE == 'cmake') {
        cmake {
            targets 'MyGame'
            arguments "-DCMAKE_FIND_ROOT_PATH=", "-DANDROID_STL=c++_static", "-DANDROID_TOOLCHAIN=clang", "-DANDROID_ARM_NEON=TRUE", \
                      "-DUSE_CHIPMUNK=TRUE", "-DUSE_BULLET=TRUE", "-DGEN_COCOS_PREBUILT=OFF", "-DUSE_COCOS_PREBUILT=ON"
            cppFlags "-frtti -fexceptions"

Log errors is about 500 rows, if need i post here.

Have you already generated the pre-built libraries by first doing this:
"-DGEN_COCOS_PREBUILT=ON", "-DUSE_COCOS_PREBUILT=OFF"
then build it, then once the libraries are built, change it to this:
"-DGEN_COCOS_PREBUILT=OFF", "-DUSE_COCOS_PREBUILT=ON"

Also, have you defined a path for the pre-built libraries? Like this:
-DCOCOS_PREBUILT_ROOT=C:/Example/Libs"

Also, you don’t need to look at all 500 errors, just start at the top and figure out what is causing the issue. Can you at least paste the first 10 errors in the log, or upload it somewhere and provide a link to it?

I just tested it all by generating a new project, changing PROP_BUILD_TYPE=cmake in gradle.properties, building it, and it worked fine. The only thing I can think of that may be different is any fixes added to my copy of v3.17, one of which I can recall is for this issue:

and the diff is here if you want to merge it with your version:

Have you already generated the pre-built libraries by first doing this:
"-DGEN_COCOS_PREBUILT=ON", "-DUSE_COCOS_PREBUILT=OFF"
then build it, then once the libraries are built, change it to this:
"-DGEN_COCOS_PREBUILT=OFF", "-DUSE_COCOS_PREBUILT=ON"

Yes i make it.
My path of prebuilt is: /Applications/cocos2d-x/prebuilt/mac/Debug
Here only mac directory after using cmake.

My errors is all same a this:

-- can't find cocos prebuilt library: cpufeatures
... and others..

Riidio, did you even check the links I put in my previous post? It’s quite literally the fix for the issue of the missing cpufeatures library. Apply the fix, then rebuild, and see if that works for you.

After cmake:

cmake ../test_app1 -DGEN_COCOS_PREBUILT=ON
make prebuilt

I have only library for mac in (Cocos_Root)/prebuilt/

I think problem is here, no android library…

Riidio, the information you keep posting is vague, incomplete, and almost cryptic. I don’t know how to help you because of that, but maybe someone else here can actually decipher your posts.

What command is used to make android project with cmake? I have change this PROP_BUILD_TYPE=cmake and I am using cocos compile -p android but it looks like it is using build method ndk-build.

I’m not sure if that command works for the cmake build. Open the proj.android up in Android Studio, and compile it in there. Someone else here may know if that command you’re using is supposed to work, or if there is an alternative set of commands to use.

Thanks I will try with android studio now. One thing do we need some specific version of NDK ? or 14.1 will work?

I am confused by following. Can you paste your actual value here and show me?

LOCAL_STATIC_LIBRARIES += YourLibrary_static

and here

BLOCAL_C_INCLUDES += PATH_TO_YOUR_STATIC_LIB_HEADERS_ETC

and

$(call import-module, [PATH TO YOUR STATIC LIBRARY]) .

My problem is that I am unable to link libcocos2dx correctly. I am not sure what I am doing wrong. Thanks.

Well now I am stuck at this error.

Android NDK: Module MyGame_shared depends on undefined modules: cocos2dx_static
/Users/waqasahmad/Library/Android/sdk/ndk-bundle/build/core/build-binary.mk:706: *** Android NDK: Aborting (set APP_ALLOW_MISSING_DEPS=true to allow missing dependencies) . Stop.

This is my project mk file.

LOCAL_PATH := $(call my-dir)
COCOS_ROOT := /Users/waqasahmad/Documents/CocosBuilds/cocos2d-x

include $(CLEAR_VARS)

$(call import-add-path,$(COCOS_ROOT))
$(call import-add-path,$(COCOS_ROOT)/external)
$(call import-add-path,$(COCOS_ROOT)/cocos)
$(call import-add-path,$(COCOS_ROOT)/cocos/audio/include)

#$(call import-add-path,$(LOCAL_PATH)/…/…/…/cocos2d)
#$(call import-add-path,$(LOCAL_PATH)/…/…/…/cocos2d/external)
#$(call import-add-path,$(LOCAL_PATH)/…/…/…/cocos2d/cocos)
#$(call import-add-path,$(LOCAL_PATH)/…/…/…/cocos2d/cocos/audio/include)

LOCAL_MODULE := MyGame_shared

LOCAL_MODULE_FILENAME := libMyGame

LOCAL_SRC_FILES := $(LOCAL_PATH)/hellocpp/main.cpp
$(LOCAL_PATH)/…/…/…/Classes/AppDelegate.cpp
$(LOCAL_PATH)/…/…/…/Classes/HelloWorldScene.cpp

LOCAL_C_INCLUDES := $(LOCAL_PATH)/…/…/…/Classes

_COCOS_HEADER_ANDROID_BEGIN

_COCOS_HEADER_ANDROID_END

LOCAL_STATIC_LIBRARIES := cocos2dx_static

#LOCAL_STATIC_LIBRARIES += cocos2dx_static

_COCOS_LIB_ANDROID_BEGIN

_COCOS_LIB_ANDROID_END

include $(BUILD_SHARED_LIBRARY)

#$(call import-add-path, $(LOCAL_PATH)/…/…/…/cocos2d)
$(call import-add-path, $(COCOS_ROOT))
#$(call import-module, /Users/waqasahmad/Documents/CocosBuilds/cocos2d-x/cocos/platform/android/libcocos2dx)
$(call import-module, cocos)
#$(call import-module,(COCOS_ROOT)/cocos2d-x/cocos/Android.mk)

_COCOS_LIB_IMPORT_ANDROID_BEGIN

_COCOS_LIB_IMPORT_ANDROID_END

and my prebuilt folder is {COCOS_ROOT}/prebuilt.

@tink3r_t I don’t understand what you’re doing. In one post you mention that you’re going to use cmake, and then in another you show your Android.mk file contents, which is not used as part of the cmake build.

So, let’s just go with getting the CMake build work, since it is the better way moving forward. This also assumes you’re using Cocos2d-x 3.17. Download android-ndk-r16b.

Make sure you have CMake installed. If not, go to cmake.org, and download the relevant cmake-3.12.4 for your operating system. After it is installed, open a console window and run the command “cmake --version” to make sure you see that it’s working.

Create a new Cocos2d-x 3.17 project with this command:

cocos new gamename -p com.example.game -l cpp -d .

Do NOT change anything in the /gamename/CMakeLists.txt file just yet. Leave it as it is for the time being just to make sure it compiles before you put anything extra in it.

Open gradle.properties which is in your proj.android folder.

Set this:
PROP_BUILD_TYPE=cmake

You may need to also set PROP_BUILD_TOOLS_VERSION=28.0.3 assuming you have that version of the build tools downloaded already.

In Android Studio (preferably version 3.2), open up the proj.android project. In the Android Studio menu, click File->Project Structure->SDK Location, and set the paths to the SDK and the NDK.

Now, build your project. That’s pretty much it. If you need add more source files after you’re sure that this builds and runs, then you can do so in the /gamename/CMakeLists.txt file.

I want to use prebuilt libs with any method, (ndk-build or cmake) and no luck. While without prebuilt every thing works correctly. Problem is I don’t know how to link prebuilt libs for android.

Go here:

http://docs.cocos2d-x.org/cocos2d-x/en/installation/CMake-Guide.html#prebuilt-libraries-feature

Read. It’s explained in there. Also, open up build.gradle which is in the /[gamename]/app/ folder, and find this section:

            else if (PROP_BUILD_TYPE == 'cmake') {
                cmake {
                    targets 'MyGame'
                    arguments "-DCMAKE_FIND_ROOT_PATH=", "-DANDROID_STL=c++_static", "-DANDROID_TOOLCHAIN=clang", "-DANDROID_ARM_NEON=TRUE", \
                              "-DUSE_CHIPMUNK=TRUE", "-DUSE_BULLET=TRUE"
                    cppFlags "-frtti -fexceptions"
                    // 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,  this way build cocos2d-x libs
                    // set "-DGEN_COCOS_PREBUILT=OFF" and "-DUSE_COCOS_PREBUILT=ON" to use prebuilt, this way not build cocos2d-x libs
                    //arguments "-DCOCOS_PREBUILT_ROOT=/Users/laptop/cocos-prebuilt"
                    //arguments "-DGEN_COCOS_PREBUILT=OFF", "-DUSE_COCOS_PREBUILT=OFF"
                }
            }

The comments explain what to do.

First you set these:

arguments "-DCOCOS_PREBUILT_ROOT=/example/path/to/libs"
arguments "-DGEN_COCOS_PREBUILT=ON", "-DUSE_COCOS_PREBUILT=OFF"

For example, on Windows, you set the COCOS_PREBUILT_ROOT line this:

arguments "-DCOCOS_PREBUILT_ROOT=C:/Dev/Cocos2dLibs"

Now, build your project in Android Studio.

Then go back to the build.gradle file, and change this:

arguments "-DGEN_COCOS_PREBUILT=OFF", "-DUSE_COCOS_PREBUILT=ON"

Done. That line means you’re now going to use the pre-built libraries that you built with the previous command.

You are most likely to have an issue with cpufeatures lib missing, the fix for which is here:

For new project its working fine. But now

Do NOT change anything in the /gamename/CMakeLists.txt file just yet. Leave it as it is for the time being just to make sure it compiles before you put anything extra in it.

But how should I add more source files to it? Is there any way to add classes folder and it will automatically pick files up?

Open up the CMakeLists.txt file, and go through it. There are comments all over that file, and you’ll notice this:

# add cross-platforms source files and header files 
list(APPEND GAME_SOURCE
     Classes/AppDelegate.cpp
     Classes/HelloWorldScene.cpp
     )
list(APPEND GAME_HEADER
     Classes/AppDelegate.h
     Classes/HelloWorldScene.h
     )

If you’re not sure what to do with that, then you should read up on how CMake works. Also, it’s possible for you to grab all source files with a wildcard, but from what I recall, it is not recommended to use wildcards.

I have added all files. Any idea about this?

Unknown CMake command "cocos_build_app".

No, I’ve never come across that error before. Check that you are using Cocos2d-x 3.17, and that you haven’t made a typo in the CMakeLists.txt.

Read the output of CMake and see if it shows you any other errors, so it may not actually be the cocos_build_app that is the problem.

cocos_build_app exists in the cocos2d/cmake/Modules/CocosBuildHelpers.cmake file, so make sure that file exists, and open it and search for “cocos_build_app” to make sure it’s there.

Now work perfectly in android!
Thx Bro