When we write a project's source code with Xcode, how do I import it into an Android phone? Let me give you a step-by-step explanation: First, we open the terminal, CD to the Cocos2d-x 3.2 folder (Note that you do not write the project folder, but the official project source code. http://cn.cocos2d-x.org/download/), and then execute the following command:./setup.py
at this point you will see it in the check ndk,android_sdk,ant path, if not previously set, then execute the following command:Vi/users/donliu/.bash_profile NOTE!!! VI after the path is your own, after the execution of the first command, he will tell you the address, directly copy and paste just fine. After the execution you will see that we have opened a file with VI, and now we are in the path of adding ndk,android_sdk,ant to it. Of course we have to download the first before joining, there may be some resources need to flip the wall (what do you not turn over the wall?) What kind of programmer do you do when you're not over the wall? )。 ant:http://ant.apache.org/android_sdk:https://developer.android.com/sdk/index.html?hl=indk:https:// Developer.android.com/tools/sdk/ndk/index.html another: If the NDK version is R10 compile when said not to find tool chain, then replace r9c it. After the download is complete, import the code into the file you just opened with VI (what you won't use vi?! Don't use VI you as what programmer! Use Google for yourself! ):
Export ANDROID_SDK_ROOT=/USERS/DONLIU/DESKTOP/COCOS2DXANDROID/ADT-BUNDLE-MAC-X86_64-20140702/SDK
Export ndk_root=/users/donliu/desktop/cocos2dxandroid/android-ndk-r9c
Export ant_root=/users/donliu/desktop/cocos2dxandroid/apache-ant-1.9.3
Note that the equals sign is followed by your own path. (Note that the path behind Android_sdk_root is not ADT, but the SDK inside). Well, that's how our previous work was finished. You don't have to repeat the above steps when packing later (nonsense we know!) Just tell me how to compile! )。 Okok, don't worry, don't worry. Next, we open the new SDK in the new eclipse, the upper left corner of the file,import,android existing Android Code into Workspace. Right browse, select the project source folder you write, enter the Proj.android folder inside, click Open, and then absolutely do not choose Copy projects into workspace, direct finish. This is on our left side of the package explorer and we can see project name projects. But there's a red fork on it, because of obsessive-compulsive disorder, we first kill the Red fork. Locate the project source folder in the Finder and enter cocos2d->cocos->platform->android->java->src->org-> COCOS2DX Copy the entire Lib folder to the project source folder under PROJ.ANDROID->SRC->ORG->COCOS2DX. Let him lib and CPP appear in a directory. OK, we turn off the finder, cut back to eclipse, right-click on the whole project and then the magical scene appears: The Red fork is gone! becomes an exclamation mark. Okay, we're starting to ignore the exclamation mark. You kill every warning when you write a program? What the? Yes? Well, kneel to the great God. Next, open the Jni folder to find Android.mk, double-click it, and on the right you see that there is a line:
Local_src_files
We make changes to the code behind it. By default, only the following:
Hellocpp/main.cpp \
.. /.. /classes/appdelegate.cpp \
.. /.. /classes/helloworldscene.cpp
But obviously you can't have just a few under classes. cpp (what, you just wrote something in Helloworldscene? All right. ), so we change it to all of your classes. CPP (Note: Do not write. h), the format is the same as he gave. For example, mine is:
local_src_files:= hellocpp/main.cpp \
.. /.. /classes/appdelegate.cpp \
.. /.. /classes/select.cpp \
.. /.. /classes/game.cpp \
.. /.. /classes/wall.cpp \
.. /.. /classes/ball.cpp
Remember to save when you're done. Let's add resource in the next step. Open your project source folder in the Finder and copy all the resources in the resource to the Proj.android->assets folder (create one without this folder). Again, cut back to eclipse and refresh. Then we open the Application.mk under the JNI folder and change its contents to the following:
app_stl:= gnustl_static
App_cppflags:=-frtti-dcc_enable_chipmunk_integration=1-dcocos2d_debug=1-std=c++ 11-fsigned-char
Remember to save! I have a tune for a long time no result a look is because did not save! Crying blind ... OK, to the most critical step, compile! Open terminal, CD to project folder, execute the following command: Cocos compile-p Android Enter to start compiling. The compilation process will be slow, you can make a cup of coffee waiting for a moment ... If the
[Armeabi] compile++ thumb:cocos2dcpp_shared <= main.cpp
[Armeabi] compile++ thumb:cocos2dcpp_shared <= AppDelegate.cpp
This place error, must be because your android.mk inside write wrong, good check.
If the check is not wrong, then carefully look at the error hint, change the corresponding CPP source code, the author also encountered a note is not clear.
And so on after the end of the terminal, found that the final error without tube, as long as there is a:
[Armeabi] Install:libcocos2dcpp.so = libs/armeabi/libcocos2dcpp.so
As long as there is this, the compilation is successful. We cut back to eclipse, refresh the project, check Libs->armeabi under the libcocos2dcpp.so, if any, OK, directly to the computer plug-in Android right-click Project, Run as->android application Then choose your own phone to start testing it!
There might have been no previous packs of APK, and here's how to pack it up as an apk.
Right item, Export,android->export Android application Click Next, Default is right click on the project, continue next, here is a keystore selection, The first time you pack a classmate choose Create new KeyStore, and then browse to a random folder (nonsense to remember where to put it), Password and confirm fill, Next.
Then the students will fill it out, note that validity to be more than 25, next.
The rest is needless to say. Fill in the application name directly finish is OK. The generated apk can be installed directly on your Android phone.
Cocos2d-x 3.2 Project source code package from Mac to Android tutorial