Pre-built libs for android not compiles with NDK 14+

From 3.15 release:

Android SDK Tools 25.3.0+ removes ant script and android tool, which leads to that cocos command can not generate apk files with Eclipse projects(proj.android). Currently, cocos command will do nothing if using SDK Tools 25.3.0+, you can use these two methods to fix it:

  • copy tools folder from old Android SDK version
  • use Android Studio to build the app

It seems google doesn’t want developers continue to use Eclipse to develope Android applications, so i suggest to switch to use Android Studio.

I used first option 1 before, so copied tools folder from old SDK(25.2.5).
With this solution I can generate pre-built libs for android using:

cocos gen-libs -p android --ap android-19 --app-abi x86:armeabi-v7a

And later configure project in android studio to compile my game really fast. Worked well.

But today I wiped all android folder with any SDK’s, tool and other files, just was needed some free space on my SSD drive.

After all, later I re-installed all(re-downloaded all in android studio) with the latest versions.
For sure, finally I replaced tools as I did before. After that I executed command to generate pre-built libs and it completed successfully.

But when I’ve tried to build my game in android studio, with familiar setup, without any changes in my code(also it worked perfect for iOS currently) I got the following errors:

47

Any ideas how to fix it? Again, on iOS all works perfect, with pre-build libs too.

I have:

build.gradle(Module: MyGame):

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion '26.0.1'
    defaultConfig {
        applicationId "com.test"
        minSdkVersion 19
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"

        ext {
            cocospath = "/Volumes/MacData/Cocos2d-x"
        }

        externalNativeBuild {

            ndkBuild {
                targets "MyGame"
                arguments "NDK_MODULE_PATH=$cocospath:$cocospath/cocos:$cocospath/external:$cocospath/cocos/prebuilt-mk"
                arguments "-j" + Runtime.runtime.availableProcessors()
                abiFilters "armeabi-v7a"
                //abiFilters "x86"
                //abiFilters "x86", "armeabi-v7a"

            }
        }

    }
    sourceSets.main {
        java.srcDir "src"
        res.srcDir "res"
        jniLibs.srcDir "libs"
        manifest.srcFile "AndroidManifest.xml"
        assets.srcDir "assets"
    }
    externalNativeBuild {
        ndkBuild {
            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
            }
        }
    }
    productFlavors {
    }
}

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

task cleanAssets(type: Delete) {
    delete 'assets'
}
task copyAssets(type: Copy) {
    from '../../Resources', '../../MyGame.spritebuilder/Resources_iOS'
    into 'assets'
}

clean.dependsOn cleanAssets
preBuild.dependsOn copyAssets

build.gradle(Module: libcocos2dx):

apply plugin: 'com.android.library'

android {
    compileSdkVersion 26
    buildToolsVersion '26.0.1'

    defaultConfig {
        minSdkVersion 19
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
    }

    sourceSets.main {
        aidl.srcDir "../java/src"
        java.srcDir "../java/src"
        manifest.srcFile "AndroidManifest.xml"
    }

    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

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

proj.android-studio/app/jni/Android.mk:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

LOCAL_MODULE := MyGame_shared
LOCAL_MODULE_FILENAME := libMyGame

LOCAL_SRC_FILES := hellocpp/main.cpp \
                   ../../../Classes/AppDelegate.cpp \
                   and all other like
                   ../../../Classes/FmodManager.cpp


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

LOCAL_STATIC_LIBRARIES := cocos2dx_static
LOCAL_SHARED_LIBRARIES := fmod

include $(BUILD_SHARED_LIBRARY)

$(call import-add-path, $(LOCAL_PATH)/../../../Classes/FMOD)
$(call import-module,./android)

$(call import-module,./prebuilt-mk)

proj.android-studio/app/jni/Application.mk:

APP_STL := gnustl_static

APP_CPPFLAGS := -frtti -DCC_ENABLE_CHIPMUNK_INTEGRATION=1 -std=c++11 -fsigned-char
APP_LDFLAGS := -latomic

APP_ABI := armeabi-v7a x86

#APP_STL := c++_static stlport_shared
#NDK_TOOLCHAIN_VERSION=clang

ifeq ($(NDK_DEBUG),1)
  APP_CPPFLAGS += -DCOCOS2D_DEBUG=1
  APP_OPTIM := debug
else
  APP_CPPFLAGS += -DNDEBUG
  APP_OPTIM := release
endif

Also:

37
45


Looking also for option 2.
I want just to generate pre-built libs for android with all latest updates…
I don’t get how to use android studio to build pre-built libs? Or any other way?

UPD:

As I see, almost all this functions is legacy:

image gone for some reason, forum bug: !_23|690x462

But not Tremolo/misc.c:189: error: undefined reference to 'stderr'

I’m using all latest SDK’s, that probably because of that. My game code was compiled before without any problems with some old SDK, but I don’t remember which kind. Anyway I think this is a bug…
@zhangxm can you please take a look?

Also, when I’m building with:

cocos gen-libs -p android --ap android-19 --app-abi x86:armeabi-v7a

it’s not compiling, but with android-19 it is… strange. But the errors are the same as when compiling project in studio:

Cocos2d-x/cocos/./2d/CCActionGrid3D.cpp:509: error: undefined reference to ‘rand’
Cocos2d-x/cocos/./2d/CCActionGrid3D.cpp:510: error: undefined reference to ‘rand’
Cocos2d-x/cocos/./2d/CCActionGrid3D.cpp:513: error: undefined reference to ‘rand’
Cocos2d-x/cocos/./2d/CCActionTiledGrid.cpp:87: error: undefined reference to ‘rand’
Cocos2d-x/cocos/./2d/CCActionTiledGrid.cpp:278: error: undefined reference to ‘srand’
Cocos2d-x/cocos/./2d/CCActionTiledGrid.cpp:603: error: undefined reference to ‘srand’
Cocos2d-x/cocos/./platform/CCFileUtils.cpp:274: error: undefined reference to ‘atof’
Cocos2d-x/cocos/./platform/CCFileUtils.cpp:283: error: undefined reference to ‘atof’

and many same type of errors in other classes.

By downgrading to NDK 13.1.3 - without any changes in any files - I was able to compile my project.
So this is problem with latest NDK. Is anyone has the same issue?
@piotrros @energyy ?

I’m using NDK 13.1.3, yet still can’t get this working.

I’ve ran exactly the same command and the error is: “Ant (Eclipse project) is not supported from Android SDK Tools 25.3.0.”.

1 Like

@zhangxm With NDK 14+ hack with replacement tools folders will not work and this topic about that.

What command did you use to build prebuilt lib with NDK 14+?

@zhangxm cocos gen-libs -p android --android-studio --ap android-19 --app-abi x86:armeabi-v7a

@slackmoehrle For some reason my uploaded images in this thread are gone. Can you recover it?

Do you have any idea why they are missing? I looked at the file names and they are not even on the file system

It were in my posts for sure when I’ve created and posted. It’s just a screen-shoots made on macOS. Nothing special. Just your server problems I think.

UPD: @slackmoehrle also I saw in other forum threads some images were gone, a little bit old threads and some fresh. But when I’ve created this topic and added images - all was ok, but some days after they are gone.

@zhangxm Any progress? It’s really can be done? Can I use all latest SDK and tools with something like:
cocos gen-libs -p android --android-studio --app-abi armeabi-v7a --ap android-19 ?

Using pre-built libs I believe should be n1 options for developing. Moreover you can provide them already build, so user can download them and for example generate template as before with -binary flag and easily will compile project and very fast.

I wanted to write a simple tutorial for SBX and pre-built libs but it’s currently not possible to use them for android without hacks(replace tools folder and use oldest NDK). I just want to use all latest and without hacks.

I will need to look into the image issue.

@piotrros do you have any updates? Or anyone have any updates? @zhangxm ? Can you please tell me is any progress about this?

Not, i am busy with Creator for CPP, i think i will try to fix it in v3.17. I will ask the QA, they tested gen-libs command before releasing v3.16.

@anon98020523 the QA tested with cocos gne-libs without issue. Why you need to add --android-studio --ap android-19 ?

What they tested?
Because you advised to do so.

They just use the command cocos gen-libs. And they copy tools folder from older Android SDK.

Gen libs for android? Which parameters?

I’m using
cocos gen-libs -p android --ap android-19 --app-abi x86:armeabi-v7a

With all latest updates in android studio 3.0, but for sure replaced tools folder hack I got that errors as in 1st my post.

They just use cocos gen-libs without any parameter. We use Android Studio 2.3.3 since 3.0 is not released that time. We will use Android 3.0 in next version.