Android application embedded cocos2dx game project

Android environment construction of cocos2dx ( Windows / Mac )

I use the cocos2dx3.15 version.

The following steps are performed on the Windows platform.

Create Cocos2d-x project

Unzip the cocos2dx3.15 zip file you just downloaded to the folder you specify.

Go to the directory cocos2d-x-3.15/tools/cocos2d-console/bin/cocos.py

Open the terminal and run the cocos.py script to create the file

python cocos.py new test -p com.coco2dx.org -l cpp -d ~/Desktop

Parameter Description:

  • test is the project name
  • -pfollowed by the package name
  • -lFollowed by the development language type, there are three types of cpp, lua, js
  • -dfollowed by the directory where the project is stored

Compile the libcocos2dlua.so file

eclipse (not very recommended, Google has abandoned eclipse)

  • Create an empty android project (mine is TestAndroidCC)
  • Go to proj.android of the cocos2dx project you just created目录下(我的是:D:\workspace\Cocos2dx_Pro\JXKJ_GAME\frameworks\runtime-src\proj.android)
  • Open the terminal, execute cocos compile -p android -android (because cocos cancels the way to execute build_native.py script compilation, use the cocos command uniformly, the environment configuration can directly execute the cocos command, if the cocos2dx command is not found, it indicates the environment configuration problem) or you can execute python D:\cocos2d-x\cocos2d-x-3.15\tools\cocos2d-console\bin\cocos.py compile -p android -android
  • After the compilation is complete, find the libcocos2dlua.so file (in the libs/armeabi directory)
  • Copy the folder where the so file you just compiled is located to the libs folder in the TestAndroidCC directory
  • Copy the resource directory (res and src folders) of cocos2dx to the assets directory of TestAndroidCC
  • Copy the org file in the cocos2dx3.15 engine D:\cocos2d-x\cocos2d-x-3.15\cocos\platform\android\java\src directory to the TestAndroidCC/src directory
  •  

  • Create a new Activity file in the same level directory of MainActivity.java (the name is defined by yourself, mine is GameActivity) and inherit Cocos2dxActivity (don't forget to import the package import org.cocos2dx.lib.Cocos2dxActivity;)
  • Add the configuration of the new Activity in AndroidManifest.xml, add the registration of a new GameActivity
  • Refer to the AndroidManifest.xml file of the cocos2dx game project and make changes to the AndroidManifest.xml of TestAndroidCC
  •  

     

  • Add a button in the activity_main.xml layout, and then add an event for the button in MainActivity
  •  

  • Compile and run TestAndroidCC, I use the night god simulator

Android Studio

  • Create an empty android project (mine is TestAndroid)
  • Go to proj.android-studio of the cocos2dx project you just created目录下(我的是:D:\workspace\Cocos2dx_Pro\JXKJ_GAME\frameworks\runtime-src\proj.android-studio)
  • Open the terminal and execute cocos compile -p android --android-studio (because cocos cancels the way to compile the build_native.py script, use the cocos command uniformly, the environment configuration can be directly executed the cocos command, if the cocos2dx command is not found, There is a problem with the environment configuration) or you can execute python D:\cocos2d-x\cocos2d-x-3.15\tools\cocos2d-console\bin\cocos.py compile -p android --android-studio
  • After waiting for the compilation to complete, find the libcocos2dlua.so file (after a long search, I found it in D:\workspace\Cocos2dx_Pro\JXKJ_GAME\frameworks\runtime-src\proj.android-studio\app\build\intermediates\transforms\mergeJniLibs\debug\ folders\2000\1f\main\lib)
  • Create a new jniLibs folder in the app/src/main directory (the name must be this one letter can't be bad), copy the folder where the so file just compiled (armeabi folder) is located to the jniLibs folder
  • Import the Module in the TestAndroid project, right-click the project file - new - Module - Import Eclipse ADT Project and import the D:\cocos2d-x\cocos2d-x-3.15\cocos\platform\android\java directory, the module of libcocos2dx is imported successfully
  • Add a reference to libcocos2dx to TestAndroid, right-click the project file - app - Dependencies to add libcocos2dx
  •  

  • Copy the resource directory (res and src folders) of cocos2dx to the src/main/assets directory of TestAndroid (if there is no assets folder: right-click the app folder under the TestAndroid project - new - Folder - Assets Folder is created)
  •  

  • Create a new Activity file in the same level directory of MainActivity.java (the name is defined by yourself, mine is GameActivity) and inherit Cocos2dxActivity (don't forget to import the package import org.cocos2dx.lib.Cocos2dxActivity;)
  • Add the configuration of the new Activity in AndroidManifest.xml, add the registration of a new GameActivity
  • Refer to the AndroidManifest.xml file of the cocos2dx game project and make changes to the AndroidManifest.xml of TestAndroidCC
  •  

  • Add a button in the activity_main.xml layout, and then add an event for the button in MainActivity
  •  

  •  

  • Compile and run, I use the night god simulator
  •  

     

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325282988&siteId=291194637