Cocos, CMake, and Android

So, I am now finally turning my attention to the Android build. But as usual it looks like I am missing something.

I have used CMake to create the iOS, OSX, and Win32 builds without issue.

There is an proj.android folder from when the original project was created. But this is obviously not up to date.

So what CMake command line do I use to create the latest project?

I checked the docs and it suggests two changes to make to gradle files which I did. Then I loaded the project into android studio but it fails…

The NDK is however installed.

Pointers…?

So I get a little closer… even though NDK is installed it’s not in my local.properties

But now it’s really helpful…

Updated gradle and it now gets further… however

That folder is up-to-date, in the sense that it’s just configuration files and source files (both C++ and Java). The changes in here aren’t directly related to CMake, but rather to your Android project.

Android Studio will automatically update the temporary build files using CMake any time it detects a changes in one of your build configuration files (like CMakeLists.txt or gradle.build etc).

The ndk.dir field in local.properties is deprecated, and the NDK should be set in your /app/build.gradle file, exactly as it is indicating in the log. For example:

...

repositories {
    google()
}

android {
    compileSdkVersion PROP_COMPILE_SDK_VERSION.toInteger()
    ndkVersion "22.0.7026061"

    defaultConfig {
...

It will automatically find the correct version of the NDK, as long as it is exactly where it expects it to be, in [android sdk folder]/sdk/ndk/[ndk folder named as version number, must match ndkVersion in build.gradle].

Now, the warning you see with the 32-bit architecture is related to this in gradle.properties:

# List of CPU Archtexture to build that application with
# Available architextures (armeabi-v7a | arm64-v8a | x86)
# To build for multiple architexture, use the `:` between them
# Example - PROP_APP_ABI=armeabi-v7a:arm64-v8a:x86
PROP_APP_ABI=armeabi-v7a:arm64-v8a

If you add “x86” to that list, then you must also add the 64 bit version, but, it won’t work with Cocos2d-x because the x86_64 3rd party libraries are missing. There are very few x86/x86_64 devices out there, so personally, I don’t think you should be concerned about that. If you really want to support the x86_64 architecture, then you’ll have to build the 3rd party libraries from source yourself.

To get rid of that warning, just change it to this:
PROP_APP_ABI=armeabi-v7a:arm64-v8a

Thanks I think I’m there… possibly the documentation needs a tweak to cover the above?

It builds and deploys… just go to get it to run now! :slight_smile:

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