Gradle 3.5.0 fails to build cocos2dx

Re-opening Android Studio: Native build fails after and upgrade because no solution was found and the topic was closed with a ‘temporary solution’ of downgrading.

Upgrading to gradle 3.5.0 (which is desirable in order to specify an ndk version to build against) results in the error

make: *** No rule to make target `cocos2dcpp'.  Stop.

Does anyone have any idea as to why gradle 3.5.0 breaks the current build? (using the steps given at Cocos2d-x Android Studio NDK build C++ DEBUG - WORKS!)

Have you tried Android Gradle plugin v3.5.1, along with with Gradle version 5.4.1? You may need to delete all build and cache folders if you’ve built it previously, otherwise you get some really strange errors. Other than that, it’s building and creating the APK fine for my own project.

It’s hard to tell from the error message you provided, I’m building with gradle 3.5.0 under cocos2d-x 3.17.2 without any error. Try ‘Sync project with gradle files’ button on the right top corner.

I have indeed cleared out builds and intermediates and tried 3.5.1 instead of 3.5.0 to no avail.
I know it is an error that doesn’t give much information but based on the linked topic it is happening to numerous others.

I hope to at least leave this topic open to anyone experiencing the issue that might find a fix (that isn’t downgrading)

What is the PROP_BUILD_TYPE set to in gradle.properties?

The cocos2dcpp library or file does not exist anywhere in the Cocos2d-x build files, so it’s definitely something in your build scripts that’s causing the issue. Search for it yourself in all *txt, *.mk, *.gradle files, and if you do find it, then you would have found your problem.

I don’t see any mention of PROP_BUILD_TYPE anywhere in the project.

Based on the link in the OP post, cocos2dcpp is set up as a target for externalNativeBuild, as below:

externalNativeBuild {
            ndkBuild {
                targets 'cocos2dcpp'
                arguments 'NDK_MODULE_PATH=../..:../../cocos2d/cocos:../../cocos2d/external'
                arguments '-j' + Runtime.runtime.availableProcessors()
                abiFilters 'armeabi-v7a' , 'arm64-v8a'
            }
        }

And defined in Android.mk as

LOCAL_MODULE := cocos2dcpp_shared
{snip}
LOCAL_MODULE_FILENAME := libcocos2dcpp

According to the build setup topic libcocos2dcpp is treated as cocos2dcpp in the gradle config.
This works correctly with Gradle 3.4.X but seems to not do so with 3.5.X

Which version of Cocos2d-x are you using? The contents you pasted look like they’re from an older release of Cocos2d-x.

The latest (3.17.2) has something similar to this:

        externalNativeBuild {
            if (PROP_BUILD_TYPE == 'ndk-build') {
                ndkBuild {
                    targets 'MyGame'
                    arguments 'NDK_TOOLCHAIN_VERSION=clang'
                    arguments '-j' + Runtime.runtime.availableProcessors()

                    def module_paths = [project.file("../../cocos2d").absolutePath,
                                        project.file("../../cocos2d/cocos").absolutePath,
                                        project.file("../../cocos2d/external").absolutePath]
                    if (OperatingSystem.current().isWindows()) {
                        module_paths = module_paths.collect {it.replaceAll('\\\\', '/')}
                        arguments 'NDK_MODULE_PATH=' + module_paths.join(";")
                    }
                    else {
                        arguments 'NDK_MODULE_PATH=' + module_paths.join(':')
                    }
                }
            }
            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"
                    cppFlags "-frtti -fexceptions -fsigned-char"
                    version "3.10.2"
                }
            }
        }

Thanks, I took a look at this and compared the setup for current v3.17 code but there wasn’t much difference bar the platform checks and I didn’t find anything useful.

I dug really far into this and resolved it by chance, it appears that pre-3.5.0 it was acceptable to specify the ndkBuild target as targets 'cocos2dcpp' while in the Android.mk specifying the LOCAL_MODULE as cocos2dcpp_shared.

This however stopped working in 3.5.0 and the following change fixes the build:

LOCAL_MODULE := cocos2dcpp_shared
LOCAL_MODULE_FILENAME := libcocos2dcpp

to

LOCAL_MODULE := cocos2dcpp
LOCAL_MODULE_FILENAME := libcocos2dcpp

Hope it helps anyone who had migrated an old project to gradle in the past (way before 3.17)

6 Likes

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.