Recently learning how to pack the APK on your Mac, cocos2dx the process of installing the JDK and ant today.
First, open the terminal and enter "Java-version"
When you click Enter, the following prompt appears:
The JDK is not installed on our Mac, clicking "More Info" will open the browser, then download the corresponding version of the JDK, here to select "Accept License agreement" before you can download
After the download, install, here directly next to the
After the installation, we re-enter the command to view the results, has been successfully installed
Next is ant, below we still enter the command "Ant-version" in the terminal, also is not installed
We can download the latest version from the official website http://ant.apache.org/bindownload.cgi, here to download the first item, extract the folder can be
Next open the terminal again, get root permission, we enter "sudo-s" command, and then enter the administrator password to
When you click Enter, the terminal's prompt will become "bash-3.2#"
We then enter the command "chmod +W/ETC/BASHRC" to modify the permissions of the BASHRC file, and then enter the command "VI/ETC/BASHRC" to modify the file
Press "I" key to enter insert state, insert the following two lines in the file
The path here is the directory where we just placed Ant.
At this point we press "ESC" key to exit the edit state, and then enter ": wq!" (the command in quotation marks), click Enter, save and exit.
Finally, we shut down the terminal. Then, re-open the terminal and enter "Ant-version" again to see the following output, indicating that our ant configuration was successful
Now that we have the JDK and ant configured, we can then use Eclipse to package the COCOS2DX project that we developed.
First of all, we need to prepare the following content
Configure environment variables, open "terminal", enter "Pico. Bash_profile" command
When you click Enter, you can see the following:
Configure environment variables and file paths according to your own directory structure.
Note: You need to fill in your current catalog file
Export android_sdk_root= Here is the SDK file path example:/USERS/VICKY/DESKTOP/ANDROID/ADT/SDK
Export android_ndk_root= Here is the android-ndk-r10d file path example:/users/vicky/desktop/android/android-ndk-r10d
Export cocos2dx_root= Here is the cocos2d-x-3.13.1 file path example:/users/vicky/desktop/cocos2d-x-3.13.1
Export ndk_root= Here is the android-ndk-r10d file path example:/users/vicky/desktop/android/android-ndk-r10d
Export ant_root= Here is an example of the apache-ant-1.9.7 file path (the bin sub file that requires the current file):/users/vicky/desktop/android/apache-ant-1.9.7/bin
Export path= $PATH: $ANDROID _sdk_root
Export path= $PATH: $ANDROID _ndk_root
After configuring, enter "Ctrl + X" to save the content, then enter "Y" OK, click Enter, the environment variable is configured.
Then, when we create the COCOS2DX project in Xcode, open Eclipse, and then right-click in the package Exp and select Import ...
In the pop-up window, select "Existing Android Code into Workspace"
Next, select the Android project directory in the COCOS2DX project that we created
After that, the same method is used to import the COCOS2DX directory under the cocos2d-x-2.2.6 directory, which is LIBCOCOS2DX
After the import is successful, the directory structure is as follows
Next, right-click on the item we imported and find the property "Properties" below
After entering the property interface, first select "Project References", tick "LIBCOCOS2DX"
Then select "Java Build Path", select "Projects" tab, "Add ..." and tick "LIBCOCOS2DX" and click "OK"
Then select the "Order and Export" tab and tick "LIBCOCOS2DX"
Next, select "Environment" under "C + + Build" and click "Add ..." to add "Cplus_include_path" and "Value" to be set according to your actual directory.
(Note: These items are not arbitrarily incremented, while others are added "Ndk_root", in addition: C_include_path (for C header files) and Cplus_include_path for C + + header files environment variable is the search path that indicates the header file, and the header file indicated by the two environment variables is searched before the system default path after the-I specified path.
Library_path indicates the library search path, which indicates that the path is searched before the system default path after the path is specified in-L. )
For example:
Next Select Android Add Library
After compiling it, we're done with the preparation, and then we're ready to pack.
First, right-click on our project, then select "Export", select "Exporting Android Application"
Next, identify your project without problems and go directly to the next
And then, if you're going to test it yourself, fill in the information with the second option.
The next is the same, just fill in the above a few items will be
Finally, choose a storage location and click "Finish" to start building the APK.
You'll need to wait a little while, and then you'll see the generated apk in the directory you just set up.
And then we can put the APK on the phone.
The final explanation: the packaged apk does not run, first of all to ensure that the resources in the project, to ensure that Android can find
In addition, some of the errors I encountered are posted:
Jar error, run once
Cocos2d-x 3.2 Import to eclipse appears after the import Org.cocos2dx.lib cannot be resolved error
Here is the solution, take up this method.
One, then we will set a reference to Cocos2d-x
Right-click Project->build path->link source->browse-> Select Address
F:\android\cocos2d\cocos2d-2.1rc0-x-2.1.2\cocos2dx\platform\android\java\src
The Folder name is filled in as a name that does not conflict with SRC, such as COCOS2DX-SRC, and then determines
Method Two, can also import libcocos2dx
1. Right-click the Import project, select the path where the LIBCOCOS2DX is located, "... \cocos2d\cocos\platform\android\java "
2. "Add", "Library", "Android", "Properties", right-click, will automatically display the lib you just added and add it.
Clean->refresh.
COCOS2DX using Eclipse package Android APK installation package in Mac platform detailed tutorial