Integrating cocos2dx on Android studio project

I have created a new android project on Android Studio, now i want to open cocos2dx project on the button click of Android button, but i am not able to Integrate cocos2dx project into android project, if someone know the steps please help me out…

  1. Make sure your environment variables are set correctly.

  2. Run cocos new PROJECT_NAME -p PACKAGE_NAME -l LANGUAGE -d PROJECT_DIRECTORY

  3. Then go to project folder and compile using following code.
    cocos compile -p android --android-studio

  4. You might get BUILD FAILED error. Don’t worry.

  5. Open Android Studio. Select Open existing project option. Select proj.android folder. Then try to run on a device. It will get compiled.

I think, that was not the question. The original poster wanted to include cocos2d-x within an Android app - not create a new cocos2d-x project.

Creating a new cocos2dx project automatically includes cocos2dx library I guess.

Thank you for your reply, but this is the way of exporting cocos2dx project on Android studio.
But i want to add cocos2dx into proper Android project.

Is there any steps regarding for that…???

Yes you are right.
Do you have any idea how to add cocos2dx project into Android project

Sadly not. I know it for libgdx, but I can’t find a good solution for cocos2d-x yet. I think cocos2d-x was never designed to be a “submodule” within an app.

@slackmoehrle have a look at it

Sorry, you have an existing Android app and you want to add Cocos2d-x to it?

yes… i want the same

Anyone got any reply…?

I could just use cocos new ... so that you can see the structure of a Cocos2d-x app and then add the libraries and source files to your project that cocos new.. produces and that you need. Probably using the pre-built libraries is best (cocos gen-libs ...).

M tried but m not able to run successfully, Application is crashing, i thing m not able to connnect the NDK portion, android.mk or Application.mk file…
Some native methods from cocos2dxHelper class is also crashing

couldn’t find “libMyGame.so” this error i am getting

I think we need more info. Just saying it crashes doesn’t help see the integration.

Ok…
First i am importing libcocos2dx from cocos2dx folder as a library. den i am trying to export Cocos2dxActivity… After that it is crashing and giving error “”" No implementation found for void org.cocos2dx.lib.Cocos2dxHelper.nativeSetAudioDeviceInfo(boolean, int, int) (tried Java_org_cocos2dx_lib_Cocos2dxHelper_nativeSetAudioDeviceInfo and Java_org_cocos2dx_lib_Cocos2dxHelper_nativeSetAudioDeviceInfo__ZII)"""

@alokdwivedi_12345 When you create a new cocos project using
cocos new -p com.yourcompany.yoursupergame -l cpp YOURPROJECTNAME
It creates a folder with a win32 project, android project, android studio project, IOS etc.
You can open the android studio project and edit the appActivity.java . AFAIK i dont think you can just
import org.chukong.cocos2dx //this package name is fictitious (Made up)
and call its functions from within java. Cocos2dx is mainly a c++ based project and the java parts were added for compatibility with android. When editing your game, edit the c++ functions in the folder called classes.It is still possible to call the c++ using java through JNI

Definitely take a look at all the files in proj.Android. It contains everything you need.