Strange, did you ran test project I posted above? What version of NDK, Android Studio are you using? Did you download cocos2d-x with that pull request merged? Did you build precompiled libs?
android studio 2.2.3
NDK 13.1.334577 (using android studio SDK manager)
Yes I cloned from Git then download-deps, submodule update and build precompiled libs
Your project gives error in setting.gradle
This is a gradle script error and I have to say itās very strange.
I just back to this. Just ported my game to C++ and so I have some stable build for iOS. Now I want to build it for android. But now Iām getting āThe android command is no longer available.ā while trying to execute command: ācocos gen-libs -p androidā.
That has nothing to do with gen-libs. Check out these issues: https://github.com/cocos2d/cocos2d-x/issues/17424 and https://github.com/cocos2d/cocos2d-console/issues/404
i have posted a Q&A about exactly your problem : why "cocos compile -p android" gives "The android command is no longer available." error - Stack Overflow
you have updated SDK tools, you need to revert back to previous version until this issue is resolved.
Ok, Iāve downgraded to 25.2.3 and able to build libs:
cocos gen-libs -p android --ap android-16 --app-abi armeabi-v7a
Then Iāve downloaded project from this post: How to link prebuilt Cocos2D X C++ library to Android Studio project? - #11 by piotrros
Fixed paths for my cocos2d-x in several files and got this:
Error while executing '/Volumes/MacData/Android/SDK/ndk-bundle/ndk-build' with arguments {NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=/Users/KAMIKAZE/Desktop/ProjectName/proj.android-studio/app/jni/Android.mk NDK_APPLICATION_MK=/Users/KAMIKAZE/Desktop/ProjectName/proj.android-studio/app/jni/Application.mk APP_ABI=armeabi-v7a NDK_ALL_ABIS=armeabi-v7a NDK_DEBUG=0 APP_PLATFORM=android-9 NDK_OUT=/Users/KAMIKAZE/Desktop/ProjectName/proj.android-studio/app/build/intermediates/ndkBuild/release/obj NDK_LIBS_OUT=/Users/KAMIKAZE/Desktop/ProjectName/proj.android-studio/app/build/intermediates/ndkBuild/release/lib NDK_MODULE_PATH=/Volumes/MacData/Cocos2d-x:/Volumes/MacData/Cocos2d-x/cocos:/Volumes/MacData/Cocos2d-x/external:/Volumes/MacData/Cocos2d-x/cocos/prebuilt-mk -j4 APP_SHORT_COMMANDS=false LOCAL_SHORT_COMMANDS=false -B -n}
Android NDK: /Volumes/MacData/Cocos2d-x/cocos/editor-support/spine/prebuilt-mk/Android.mk: Cannot find module with tag 'editor-support/spritebuilder/prebuilt-mk' 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:
Build command failed.
Error while executing '/Volumes/MacData/Android/SDK/ndk-bundle/ndk-build' with arguments {NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=/Users/KAMIKAZE/Desktop/ProjectName/proj.android-studio/app/jni/Android.mk NDK_APPLICATION_MK=/Users/KAMIKAZE/Desktop/ProjectName/proj.android-studio/app/jni/Application.mk APP_ABI=armeabi-v7a NDK_ALL_ABIS=armeabi-v7a NDK_DEBUG=1 APP_PLATFORM=android-9 NDK_OUT=/Users/KAMIKAZE/Desktop/ProjectName/proj.android-studio/app/build/intermediates/ndkBuild/debug/obj NDK_LIBS_OUT=/Users/KAMIKAZE/Desktop/ProjectName/proj.android-studio/app/build/intermediates/ndkBuild/debug/lib NDK_MODULE_PATH=/Volumes/MacData/Cocos2d-x:/Volumes/MacData/Cocos2d-x/cocos:/Volumes/MacData/Cocos2d-x/external:/Volumes/MacData/Cocos2d-x/cocos/prebuilt-mk -j4 APP_SHORT_COMMANDS=false LOCAL_SHORT_COMMANDS=false -B -n}
Android NDK: /Volumes/MacData/Cocos2d-x/cocos/editor-support/spine/prebuilt-mk/Android.mk: Cannot find module with tag 'editor-support/spritebuilder/prebuilt-mk' 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:
/Volumes/MacData/Cocos2d-x/cocos/prebuilt-mk/Android.mk
My config:
Also, very strange thing. I downloaded your project and edited pathās for my location of cocos2d-x.
Next, when I opened it in AS I got an error:
And when I clicked āDetailsā¦ā:
Why is that? Where it finds you account pathās? I canāt find itā¦ to fix.
Bash profile:
# Add environment variable COCOS_CONSOLE_ROOT for cocos2d-x
export COCOS_CONSOLE_ROOT=/Volumes/MacData/Cocos2d-x/tools/cocos2d-console/bin
export PATH=$COCOS_CONSOLE_ROOT:$PATH
# Add environment variable COCOS_X_ROOT for cocos2d-x
export COCOS_X_ROOT=/Volumes/MacData
export PATH=$COCOS_X_ROOT:$PATH
# Add environment variable COCOS_TEMPLATES_ROOT for cocos2d-x
export COCOS_TEMPLATES_ROOT=/Volumes/MacData/Cocos2d-x/templates
export PATH=$COCOS_TEMPLATES_ROOT:$PATH
# Add environment variable NDK_ROOT for cocos2d-x
export NDK_ROOT=/Volumes/MacData/Android/SDK/ndk-bundle
export PATH=$NDK_ROOT:$PATH
# Add environment variable ANT_ROOT for cocos2d-x
export ANT_ROOT=/usr/local/Cellar/ant/1.9.7/bin
export PATH=$ANT_ROOT:$PATH
# Add environment variable ANDROID_SDK_ROOT for cocos2d-x
export ANDROID_SDK_ROOT=/Volumes/MacData/Android/SDK
export PATH=$ANDROID_SDK_ROOT:$PATH
export PATH=$ANDROID_SDK_ROOT/tools:$ANDROID_SDK_ROOT/platform-tools:$PATH
Open settings.gradle file and fix libcocos2dx path. Itās definitely āmyā path
By the way āpierdolyā means āunnecessary thingsā in English
That path was fixed after downloading, as long as other. So, itās like something elseā¦ hmm maybe because Iām using http://github.com/newnon/cocos2d-x
Itās canāt find /prebuilt-mk/ but this folder should be or not?
Where did you get āspritebuilderā in editor-support directory? I donāt have such a directory. Isnāt it connected with SpriteBuilder-X? Try fresh and clean cocos2d-x copy. Most probably you havenāt added spritebuilder in Android.mk.
Yes for SBX. https://github.com/newnon/cocos2d-x/tree/v3.13.1/cocos/editor-support/spritebuilder
I canāt imagine cocos2d-x without it. But SBX canāt work with official repo, there are too many changes in newnon/cocos2d-x for support of SBX, which canāt be easy mergedā¦ and I donāt think cocos2d-x team really want or interested in it.
Later I will try just to compile with official repo, if it works will see, what I need to fix in my project from newnon/cocos2d-x.
Open cocos/prebuilt-mk/Android.mk
and add missing spritebuilder module there.
Iāve tried that finally and everything works. My project structure is identical to @piotrros one except for
targets āMyGameā
arguments āNDK_MODULE_PATH=$cocospath:$cocospath/cocos:$cocospath/external:$cocospath/cocos/prebuilt-mk:$cocospath/extensionsā
arguments ā-jā + Runtime.runtime.availableProcessors()
which my gradle doesnāt like; but thatās no problem because iāve left all the
$(call import-add-path,${COCOS2DX_ROOT})
$(call import-add-path,${COCOS2DX_ROOT}/external)
$(call import-add-path,${COCOS2DX_ROOT}/cocos)
$(call import-add-path,${COCOS2DX_ROOT}/cocos/audio/include)
so it works the same.
Debug is working, both on emulator and devices.
Only thing Iām still missing is complete project structure. I mean the include dirs, cocos/ā¦/*.h
Those arenāt shown in android studio, even if the debugger finds them. Nothing particularly important, anyway, just for the sake of curiosityā¦
This solution uses prebuilt libraries so you wonāt be able to see files in cocos directory.
Hmm, I have already there:
$(call import-module, editor-support/spine/prebuilt-mk)
$(call import-module, editor-support/spritebuilder/prebuilt-mk)
But what Iāve found , than in folder: ../Cocos2d-x/cocos/editor-support/cocosbuilder/
- there is āprebuilt-mk
ā, but not in ../Cocos2d-x/cocos/editor-support/spritebuilder
folder. Anyway libs was build ok for android and iOS. How prebuilt-mk
folder generated? For some reason itās not generated for spritebuilder, but ok for cocosbuilder folderā¦
Ok, temporary I just copied it from cocosbuilder and modified it accordingly to fit spritebuilder names.
Now, Iāve problem with:
Error:(1508, 25) error: no member named 'stoi' in namespace 'std'
How this can be? For iOS again all compiles ok.
Also additional question: in Application.mk
Iāve found line APP_ABI := armeabi
, but itās should be armeabi-v7a? Isnāt it? Because Iām compiling for it using:
cocos gen-libs -p android --ap android-16 --app-abi armeabi-v7a
- is that right by the way?
Sure it builds fine for iOS, because .mk files are for Android. You should recreate āprebuilt-mkā for spritebuilder. Iām not sure how to do this (these .mk can be pretty hard to make). Anyway, I had the similar problem with latest audio engine change - it was working, but I couldnāt make prebuilt libs. The author of this pull request, @dumganhar, may be able to help you, as he fixed that problem.
As for the error no member named 'stoi' in namespace 'std'
: is it in spritebuilder itself or somewhere else?
APP_ABI
may be armeabi-v7a
, armeabi
itās just the default setting. armeabi
is backward compatible so I donāt think itād be any issue. You wonāt be able to debug precompiled lib anyway. Also if you specify it in gen-libs
it should override that value.
Yea, I just copied it from cocosbuilder and fixed names inside.
This in source code of my game. And I āfixedā this by replacing with atoi
. Donāt know why compiler for android canāt find stoi
ā¦
In gen-libs
yes, but Iām talking about Application.mk
for my game. I just saw that armeabi
like old, and better to use armeabi-v7a
there?
And finally Iāve made it. Lol after 5 days of trying. Thanks for help. Ohh, this android environment is so crapā¦ really want go back and develop games only for iOS, where everything is just works. But anyway, I need my game on both platformsā¦
Yes, android has a problem with some std built-in functions like stoi
.
Application.mk for game, well, just as I said, I think itās overrided be gradle.
Cocos uses armeabi
as default, but I personally use armeabi-v7a
. armeabi
devices are very old, for sure below android 4.0, which I donāt support anyway (cuz google services and facebook). armeabi-v7a
give the ease of debugging on all my devices.
I see, and so how to change cocos to configure it to use armeabi-v7a? Or this is it:
cocos gen-libs -p android --ap android-16 --app-abi armeabi-v7a
?
This is it.