Cocos2d-x 3.15 wrong logic in Android gradle - causing critical bug

@nite
@slackmoehrle

Hi, today we discovered bug with cocos2d-x 3.15 on Android 4.3 similar to this one:

Our compile parameters:

Cocos2d-x 3.15
NDK: 13b
Android minsdk version: 15
Android target sdk version(PROP_TARGET_SDK_VERSION): 22
APP_PLATFORM := android-15 in Application.mk

So issue is due introduced new variable PROP_TARGET_SDK_VERSION which is used to set :slight_smile:

targetSdkVersion PROP_TARGET_SDK_VERSION

and

 externalNativeBuild {
            ndkBuild {
                if (!project.hasProperty("PROP_NDK_MODE") || PROP_NDK_MODE.compareTo('none') != 0) {
                    // skip the NDK Build step if PROP_NDK_MODE is none
                    targets 'MyGame'
                    arguments 'NDK_TOOLCHAIN_VERSION=4.9'
                    arguments 'APP_PLATFORM=android-'+PROP_TARGET_SDK_VERSION
                    
                    def module_paths = [project.file("../../cocos2d").absolutePath,
                                        project.file("../../cocos2d/cocos").absolutePath,
                                        project.file("../../cocos2d/external").absolutePath]
                    if (Os.isFamily(Os.FAMILY_WINDOWS)) {
                        // should use '/'
                        module_paths = module_paths.collect {it.replaceAll('\\\\', '/')}
                        arguments 'NDK_MODULE_PATH=' + module_paths.join(";")
                    }
                    else {
                        arguments 'NDK_MODULE_PATH=' + module_paths.join(':')
                    }
                    
                    arguments '-j' + Runtime.runtime.availableProcessors()
                    abiFilters.addAll(PROP_APP_ABI.split(':').collect{it as String})
                }
            }
        }

Same variable cannot be used in Target SDK and ndkBuild as it should have different version in ndkBuild (it owerwriting in Application.mk set APP_PLATFORM:=15 to APP_PLATFORM:=22 )

Please revise your logic.

I’m assuming PROP_TARGET_SDK_VERSION should set minSDK version not targetSDK version!

1 Like

@zhangxm please review this

@energyy yep, targetSdkVersion should not be used to set APP_PLATFORM. As the doc says, it does

This attribute informs the system that you have tested against the target version and the system should not enable any compatibility behaviors to maintain your app's forward-compatibility with the target version. The application is still able to run on older versions (down to minSdkVersion).

So i think we should remove the line

arguments 'APP_PLATFORM=android-'+PROP_TARGET_SDK_VERSION

Will you please remove the line and have a test? And could you please paste your cocos command? Thanks.

yes, we already tested - and it worked.

But in cocos2d-x case I don’t see reason to create such variable: PROP_TARGET_SDK_VERSION if u using it only for targetSdkVersion - best would be to create variable for minSdkversion and put it as argument in APP_PLATFORM also as this should match.

Yep, you are right. I think there is not need to have PROP_TARGET_SDK_VERSION. minSdkversion can be set in gradle and in Application.xml. I think it is ok just set it in these two files.

@energyy cocos2d-x supports Android 10+, so the minSdkVersion should be 10, but cocos2d-x needs 13+ to generate APK since it uses android:configChanges="orientation|keyboardHidden|screenSize" in AndroidManifest.xml.

So, may be should use PROP_BUILD_SDK_VERSION instead.

I created a github issue for it.