Cocos2d-x Android Studio NDK build C++ DEBUG - WORKS!

nice! well done!

I found it here and tried it immediately.
I get the following error, but does anyone know the cause?

make: *** [D:/cocos2dProjects/MyGame/proj.android-studio/app/build/intermediates/ndkBuild/debug/obj/local/armeabi-v7a/libcocos2dxinternal.a] Error
87

    at com.android.build.gradle.tasks.ExternalNativeBuildTaskUtils.executeBuildProcessAndLogError(ExternalNativeBuildTaskUtils.java:233)
    at com.android.build.gradle.tasks.ExternalNativeBuildTask.executeProcessBatch(ExternalNativeBuildTask.java:231)
    at com.android.build.gradle.tasks.ExternalNativeBuildTask.build(ExternalNativeBuildTask.java:163)
    at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:75)

I am very sorry for the sentence using the Google translation because it is Japanese and I am not good at English.
Thank you for your consideration.

Is that a full stack trace?

gradlew assembleDebug --stacktrace

↑This way, is it wrong?

I output the log in text, but I copied only the last one and pasted it because it is long.

I am sorry that I am unfamiliar with English.
Thank you.

You can add --debug as well. If output log is too long you should post it on pastebin for example.

It works!!! It helps me a lot!! I can debug now. Thanks a lot!

Warning:(499) warning: ignoring old commands for target `/Users/admin/Desktop/HelloCpp/proj.android-studio/app/build/intermediates/ndkBuild/release/obj/local/armeabi-v7a/objs/bullet_static/BulletMultiThreaded/SpuLibspe2Support.o’
Error:Execution failed for task ‘:HelloCpp:externalNativeBuildDebug’.

Unexpected native build target MyGame. Valid values are: extension, audioengine, cpufeatures, box2d, cocos2dandroid, spine, network, cocos2dcpp, flatbuffers, ui, recast, cocos2dxinternal, cocos3d, cocosbuilder, bullet, cocostudio, cocosdenshion``

It don’t work. How do I set? thanks!

I think this is issue, you probably using older cocos2d-x version where compiled lib was called “cocos2dcpp” not “MyGame”

Upgrade your cocos;) to 3.13.1+ or change in gradle that line

targets 'MyGame'
to

targets 'cocos2dcpp'

Target name should match with in Android.mk defined (without _shared)

LOCAL_MODULE := cocos2dcpp_shared

1 Like

nice! It works!! Thanks!!!:thumbsup::thumbsup:

@energyy, appreciate your work. Using these instructions I have a project compiling and debugging from Android Studio.

What I cannot see is the C++ files in my cocos2d-x project. Can you advise me please?

Thanks again!

I have it all compiling, running. Have set the debug type to “Native” and set the symbols directory and yet when I press “debug” it does not hit any breakpoints at all…

Is really frustrating please help … here is my setup:

So I have done: edit configurations -> select app “HelloCpp” – Debug tab - > Native -> symbols directory:

  "C:\dev\firebase\cocos2dx-cpp-sample\sample_project\proj.android-studio\app\.externalNativeBuild\ndkBuild\debug\armeabi-v7a"

In build.gradle for the app I have:

apply plugin: 'com.android.application'
android {
    compileSdkVersion 25
    buildToolsVersion '25.0.2'

defaultConfig {
    applicationId "org.cocos2dx.hellocpp"
    minSdkVersion 21
    targetSdkVersion 25
    versionCode 1
    versionName "1.0"

    externalNativeBuild {
        ndkBuild {
            arguments '-j' + Runtime.runtime.availableProcessors()
        }
    }

    ndk {
        abiFilters 'x86','armeabi-v7a'
    }
}

externalNativeBuild {
    ndkBuild {
        path 'jni/Android.mk'
    }
}

sourceSets.main {
    java.srcDir "src"
    res.srcDir "res"
    jniLibs.srcDir "libs"
    manifest.srcFile "AndroidManifest.xml"
    assets.srcDir "assets"
}

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

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile project(':libcocos2dx')
    compile 'com.google.firebase:firebase-auth:10.2.0'
    compile 'com.google.android.gms:play-services-base:10.2.0'
}

apply plugin: 'com.google.gms.google-services'

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

clean.dependsOn cleanAssets
preBuild.dependsOn copyAssets

I solved this by upgrading to 3.15 and downgrading the NDK to 13.b. Only took most of the day to figure it out… the joys of open source. :thumbsdown:

Break points are not caught. No compilation error, successful, working apk is generated. Any ideas?

have u used 3.15 version?
now it should work more stable.

Unable to create prebuilt libraries usin 3.15.1.

cocos gen-libs -p android --app-abi x86

NDK build mode: release
running: ‘“C:\ProgramData\Microsoft\AndroidNDK64\android-ndk-r11c\ndk-build” -C C:\cocos2d-x-3.15.1\tools\simulator\frameworks\runtime-src\proj.android -j4 APP_ABI=“armeabi” NDK_MODULE_PATH=C:\cocos2d-x-3.15.1;C:\cocos2d-x-3.15.1\cocos;C:\cocos2d-x-3.15.1\external;C:\cocos2d-x-3.15.1\cocos\scripting NDK_TOOLCHAIN_VERSION=4.9’

Android NDK: WARNING: APP_PLATFORM android-19 is larger than android:minSdkVersion 9 in ./AndroidManifest.xml
Android NDK: WARNING: Ignoring unknown import directory: C:\cocos2d-x-3.15.1
Android NDK: C:\cocos2d-x-3.15.1\cocos/ui/Android.mk: Cannot find module with tag ‘extensions’ in import path
Android NDK: Are you sure your NDK_MODULE_PATH variable is properly defined ?
Android NDK: The following directories were searched:
Android NDK:
make: Entering directory C:/cocos2d-x-3.15.1/tools/simulator/frameworks/runtime-src/proj.android' C:\cocos2d-x-3.15.1\cocos/./Android.mk:329: *** Android NDK: Aborting. . Stop. make: Leaving directoryC:/cocos2d-x-3.15.1/tools/simulator/frameworks/runtime-src/proj.android’
Error running command, return code: 2.
Error running command, return code: 14.

I already use 3.15.1

1 Like

For those who are still having trouble with debugging, setting Run->Edit configuration - select your project -> go to tab debugger -> set debuger type to native works for me.

Not working for me. Here are the values:
targets 'MyGame'
From my Android.mk
LOCAL_MODULE := MyGame_shared
LOCAL_MODULE_FILENAME := libMyGame

But I still get the following error:

Error:Execution failed for task ‘:WordBounce:externalNativeBuildDebug’.

Unexpected native build target MyGame. Valid values are:

Funnily enough, the list of valid values is also empty. And… I am able to build successfully from the command line using the following command, it only fails when I try to compile from Android-Studio, Weird!!:
cocos compile -p android --android-studio --stacktrace

Can someone please help?

Thanks,

Worked on mobile, was not working on Emulator!!! Please ignore.

Best,

It’s completely logical, because the default configuration for cocos2d-x is arm-based and the emulator is x86. You need to add x86 to the ABI, to use it within the emulator.

1 Like