Cocos2d-x Android long compile (seems console bug)

@nite @slackmoehrle

Hi, there was some time ago topic that at some point android build compiling for 30-40 minutes thru console command, we also noticed that but didnt made a lot of attention till now.

Now when I’m compiling build thru console it seems that build get compiled 2 times, it ussualy happens when u have 2 ABI targets, like first compile for one ABI and then for second ABI , but in our case we have only one ABI and I’m assuming there is somewhere in gradle NDK support or in cocos console issue, like somewhere is code which making build to make full compile twice - as in console I see that it compiling same files 2 times.

1 Like

What’s the build command? If you use ./gradlew build it’s completely normal, because it builds for debug and release. If you are using the cocos command line tool, it shouldn’t because you specify the output configuration.

I’m using this one:
cocos run -p android -j 2 --android-studio -m release

So I’m then assuming cocos making dev and release builds even specified only release, but maybe someone can confirm if have same behaviour

-j 2 means you are only using 2 cores in your system.

What kind of system do you have? i7 quad core?

In any case, you want this to be the sum of physical and logical core you have in the system.

For example: if you have an i7-8700k, You have 4 physical cores and 4 logical cores. Which means you -j variable should be 8!

But this is not the problem, as far as I understand @energyy correct. His issue is, that the cpp sources will be compiled twice.

yeap, issue is that build get compiled twice and build takes to compile 30-40minutes , but before it was 15 minutes.

Oh… :frowning: Not sure how that happening. This is a dumb question but are you sure you only have 1 ABI defined?

Yes, we setting armeabi-v7a in Application.mk and in gradle - not sure maybe it trying to make external ndk build from gradle and after that Application.mk compile. have a try to compie android project from scratch how much time it will take

There is example log.

Like on top of log u see that build is completed like it building apk and then by some reason it starting to compile again. in left side u see that ABI is same armeabi-v7a:

https://drive.google.com/open?id=1GLC2U5phkck8TYao1430oFPsrByaGNfR

Now checking new project build.gradle, isn’t there is wrong statment for if:

if (!project.hasProperty(“PROP_NDK_MODE”) || PROP_NDK_MODE.compareTo(‘none’) != 0) {

This statment exists in build.gradle in two places same and if correctly understanding in first scenario it building build thru gradle and in second it building using Android.mk - so i’m assuming that why it get compiled 2 times or I’m wrongly understood it?

import org.apache.tools.ant.taskdefs.condition.Os

apply plugin: 'com.android.application'

android {
    compileSdkVersion PROP_COMPILE_SDK_VERSION.toInteger()
    buildToolsVersion "25.0.0"

    defaultConfig {
        applicationId "com.funlab.audiocricker"
        minSdkVersion PROP_MIN_SDK_VERSION
        targetSdkVersion PROP_TARGET_SDK_VERSION
        versionCode 1
        versionName "1.0"

        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_APP_PLATFORM
                    
                    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})
                }
            }
        }
    }

    sourceSets.main {
        java.srcDir "src"
        res.srcDir "res"
        manifest.srcFile "AndroidManifest.xml"
        assets.srcDir "../../Resources"
    }

    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
                path "jni/Android.mk"
            }
        }
    }

    signingConfigs {

       release {
            if (project.hasProperty("RELEASE_STORE_FILE")) {
                storeFile file(RELEASE_STORE_FILE)
                storePassword RELEASE_STORE_PASSWORD
                keyAlias RELEASE_KEY_ALIAS
                keyPassword RELEASE_KEY_PASSWORD
            }
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            if (project.hasProperty("RELEASE_STORE_FILE")) {
                signingConfig signingConfigs.release
            }

            externalNativeBuild {
                ndkBuild {
                    arguments 'NDK_DEBUG=0'
                }
            }
        }

        debug {
            externalNativeBuild {
                ndkBuild {
                    arguments 'NDK_DEBUG=1'
                }
            }
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile project(':libcocos2dx')
}

@yinjimmy can you also take a look

hi, any news @yinjimmy ?

Which cocos version do you check?
What about the APK, it contains one or two architecture ?

APP_ABI := armeabi-v7a in proj.android-studio/app/jni/Android.mk

PROP_APP_ABI=armeabi in proj.android-studio/gradle.properties for abiFilters.addAll(PROP_APP_ABI.split(':').collect{it as String})

You may need to change the PROP_APP_ABI=armeabi-v7a too.

1

I changed APP_ABI := armeabi-v7a in proj.android-studio/app/jni/Android.mk

still compile armeabi

[armeabi] Compile++ arm  : cocostudio_static <= WidgetReader.cpp
$ time cocos run -p android -j 2 --android-studio -m release

|real|4m13.077s|
|---|---|
|user|0m2.373s|
|sys|0m0.584s|

2

I changed the PROP_APP_ABI=armeabi-v7a in proj.android-studio/gradle.properties

Compile armeabi-v7a

[armeabi-v7a] Compile++ arm  : cocostudio_static <= WidgetReader.cpp
$ time cocos run -p android -j 2 --android-studio -m release

|real|4m41.589s|
|---|---|
|user|0m2.076s|
|sys|0m0.580s|

so, maybe you need to check your gradle file .

my book:

  • 2.8 GHz Intel Core i7
  • 16 GB 1600 MHz DDR3
  • SSD

I just checked empty Hello World project compile on 3.16 cocos, it’s really doing it only once. We using cocos2d-x 3.14 with gradle from 3.16 version. Maybe u know what could cause double compile in our case, some issue between cocoss 3.14 and console compile 3.16 or due gradle config?

Our gradle.build:

import org.apache.tools.ant.taskdefs.condition.Os




buildscript {
    repositories {
        jcenter()
        maven { url 'https://maven.fabric.io/public'
        }
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.3'
        // The Fabric Gradle plugin uses an open ended version to
        // react quickly to Android tooling updates
        classpath 'io.fabric.tools:gradle:1.+'
    }
}


apply plugin: 'com.android.application'
apply plugin: 'io.fabric'




repositories {
    jcenter()
    maven { url 'https://maven.fabric.io/public' }

    flatDir{
        dirs 'heyzap'
    }
}



android {
    compileSdkVersion PROP_COMPILE_SDK_VERSION.toInteger()
    buildToolsVersion "25.0.0"

    defaultConfig {
        applicationId "com.mygmae.test"
        minSdkVersion PROP_MIN_SDK_VERSION
        targetSdkVersion PROP_TARGET_SDK_VERSION
        versionCode 9
        versionName "1.4.1"
        multiDexEnabled true

        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_APP_PLATFORM

                    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})
                }
            }
        }
    }

    dexOptions {
    javaMaxHeapSize "4g"
    }


    lintOptions {
        checkReleaseBuilds false
        // Or, if you prefer, you can continue to check for errors in release builds,
        // but continue the build even when errors are found:
        abortOnError false
    }


    sourceSets.main {
        java.srcDir "src"
        res.srcDir "res"
        manifest.srcFile "AndroidManifest.xml"
        assets.srcDir "../../Resources"
        jniLibs.srcDirs = ['libs']

    }

    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
                path "jni/Android.mk"
            }
        }
    }

    dexOptions {
        javaMaxHeapSize "4g"
    }

    splits {
        abi {
            enable true
            reset()
            include 'armeabi-v7a'
            universalApk false
        }
    }

    signingConfigs {

        release {
            if (project.hasProperty("RELEASE_STORE_FILE")) {
                storeFile file(RELEASE_STORE_FILE)
                storePassword RELEASE_STORE_PASSWORD
                keyAlias RELEASE_KEY_ALIAS
                keyPassword RELEASE_KEY_PASSWORD
            }
        }
    }


    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            if (project.hasProperty("RELEASE_STORE_FILE")) {
                signingConfig signingConfigs.release
            }

            externalNativeBuild {
                ndkBuild {
                    arguments 'NDK_DEBUG=0'
                }
            }
        }

        debug {
            externalNativeBuild {
                ndkBuild {
                    arguments 'NDK_DEBUG=1'
                }
            }
        }
    }
}



crashlytics {
    enableNdk true
    androidNdkOut 'build/intermediates/ndkBuild/release/obj/local'
    androidNdkLibsOut 'build/intermediates/ndkBuild/release/obj/local'
  //  androidNdkOut 'build/intermediates/ndkBuild/debug/obj/local'
  //  androidNdkLibsOut 'build/intermediates/ndkBuild/debug/obj/local'
}



dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile fileTree(include: ['*.jar'], dir: 'heyzap')
    compile project(':libcocos2dx')
    compile 'com.android.support:multidex:1.0.1'
    //facebook
    compile(name: 'AudienceNetwork-4.26.1', ext: 'aar')
    compile(name: 'unity-ads-2.1.1', ext: 'aar')






    // Crashlytics Kit
    compile('com.crashlytics.sdk.android:crashlytics:2.6.8@aar') {
        transitive = true
    }
    // NDK Kit
    compile('com.crashlytics.sdk.android:crashlytics-ndk:1.1.6@aar') {
        transitive = true
    }
}

which cocos console version you use? I used 3.16.

also 3.16 configured on mac

what not use cocos2d-x 3.16 ?
Any issue with it?
I’ll try cocos console 3.16 with project cocos project 3.14 (3.16 gradle).

We not using for now 3.16 due it was crashing for 25% users on IOS due this bug:

omg :smiley: I think found where was issue :))

.cocos-project.json had

{
    "engine_version": "cocos2d-x-3.14.1", 
    "project_type": "cpp"
}

In this case ] cocos console had hardcoded instructions for 3.14.1 to compile against NDK folder, but as we have manually replaced build.gradle file from 3,15 version which was using gradle NDK compile. in our case cocos console compiled in old version against NDk after that compiled second time based on gradle setup. So maybe need to make this clear or somehow make more checks for cocos console.

To fix that issue I just manually changed :slight_smile:
“engine_version”: “cocos2d-x-3.14.1” to “engine_version”: “cocos2d-x-3.16” , so it’s not running now extra compile steps seems.

2 Likes