CMake Android prebuild cpufeatures missing

I’m trying to build for Android using CMake,

gradle.properties:
PROP_BUILD_TYPE = cmake

gradle.build cmake section:
arguments “-DGEN_COCOS_PREBUILT=ON”, “-DUSE_COCOS_PREBUILT=OFF”

The output folder I set contains these prebuilt libraries after I do a build (android/x86 and android/armeabi-v7a):
libcocos2d.a
libcocos2d_android.a
libflatbuffers.a
libpvmp3dec.a
librecast.a
libtinyxml2.a
libtremolo.a
libunzip.a
libxxhash.a

Once they’re built, I change the line in build.gradle to:
arguments “-DGEN_COCOS_PREBUILT=OFF”, “-DUSE_COCOS_PREBUILT=ON”

but I get this error on build:
cocos2d\cocos\math/MathUtil.cpp:114: error: undefined reference to ‘android_getCpuFamily’
cocos2d\cocos\math/MathUtil.cpp:114: error: undefined reference to ‘android_getCpuFeatures’

because of this:

– can’t find cocos prebuilt library: cpufeatures

I’m not sure what is going on. Could someone test this please and let me know if it actually works for you, just in case it’s an issue specific to my build process.

EDIT: So, I can see that libcpufeatures.a is being built (with GEN_COCOS_PREBUILT=ON), but it is never copied to the output library folder. Is this happening for anyone else??

Ok, I literally just found the problem after I edited my above post.

libcpufeatures.a is being built into:
.externalNativeBuild/cmake/debug/${ANDROID_ABI}/

while the rest of the libraries are being built into:
.externalNativeBuild/cmake/debug/${ANDROID_ABI}/lib/

So, when the copy happens, it copies everything from ${ANDROID_ABI}/lib/, which does not contain the libcpufeatures.a

I presume this is a bug, so I’ll check it into the issue tracker.

Sorry, it’s my fault. I think just add this:

        set_target_properties(cpufeatures	
            PROPERTIES	
            ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"	
            LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"	
        )

into

else()
         include(AndroidNdkModules)
         android_ndk_import_module_cpufeatures()
         # here
         set(CPUFEATURES_LIBRARIES cpufeatures)
     endif()

The reason is we used custom AndroidNdkModules.cmake times ago, we deleted it when reducing the cmake modules inside cocos2d-x, for those modules are installed with cmake.

1 Like

Yep, that fixed it! Thank you very much!

@drelaptop Help
After add that still error

cocos2d-x-3/external/webp/prebuilt/android/armeabi-v7a/libwebp.a(libwebpdsp_la-cpu.o):cpu.c:function AndroidCPUInfo: error: undefined reference to ‘android_getCpuFamily’

cocos2d-x-3/external/webp/prebuilt/android/armeabi-v7a/libwebp.a(libwebpdsp_la-cpu.o):cpu.c:function AndroidCPUInfo: error: undefined reference to ‘android_getCpuFeatures’

could you find cpufeatures static lib existed at your ${CMAKE_BINARY_DIR}/lib directory?

Hi, @drelaptop

I don’t know where is ${CMAKE_BINARY_DIR}/lib.

But, after I set -DUSE_WEBP=OFF and error is gone.

this is a common cmake concept, please refer

https://cmake.org/cmake/help/v3.12/variable/CMAKE_BINARY_DIR.html?highlight=cmake_binary_dir

google is your good friend when you touch something new.

Yes, I can find it in ${CMAKE_BINARY_DIR}/lib directory.