官方提供的中文文档
http://cn.cocos2d-x.org/article/index?type=cocos2d-x&url=/doc/cocos-docs-master/manual/framework/native/v2/getting-started/setting-up-development-environments/linux-environment-setup/how-to-run-helloworld-and-tests-on-linux/zh.md
下面是一个博主写的博客
http://xuzhiwei.blog.51cto.com/978424/1401434
根据这个博客说的,我要配置下环境,我就按他来弄,而已
小弟开发环境是ubuntu
1配置环境
moziqi@moziqi:~$ cd /home/moziqi/software/cocos2d-x-3.5 moziqi@moziqi:~/software/cocos2d-x-3.5$ ./start.py bash: ./start.py: 没有那个文件或目录 moziqi@moziqi:~/software/cocos2d-x-3.5$ ./setup.py Setting up cocos2d-x... ->Check environment variable COCOS_CONSOLE_ROOT ->Search for environment variable COCOS_CONSOLE_ROOT... ->COCOS_CONSOLE_ROOT not found -> Add COCOS_CONSOLE_ROOT environment variable... ->Added COCOS_CONSOLE_ROOT=/home/moziqi/software/cocos2d-x-3.5/tools/cocos2d-console/bin ->Check environment variable COCOS_TEMPLATES_ROOT ->Search for environment variable COCOS_TEMPLATES_ROOT... ->COCOS_TEMPLATES_ROOT not found -> Add COCOS_TEMPLATES_ROOT environment variable... ->Added COCOS_TEMPLATES_ROOT=/home/moziqi/software/cocos2d-x-3.5/templates ->Configuration for Android platform only, you can also skip and manually edit "/home/moziqi/.bashrc" ->Check environment variable NDK_ROOT ->Search for environment variable NDK_ROOT... ->NDK_ROOT not found ->Search for command ndk-build in system... ->Command ndk-build not found ->Please enter the path of NDK_ROOT (or press Enter to skip):/home/moziqi/software/android-ndk-r9d -> Add NDK_ROOT environment variable... ->Added NDK_ROOT=/home/moziqi/software/android-ndk-r9d ->Check environment variable ANDROID_SDK_ROOT ->Search for environment variable ANDROID_SDK_ROOT... ->ANDROID_SDK_ROOT not found ->Search for command android in system... ->Command android not found ->Please enter the path of ANDROID_SDK_ROOT (or press Enter to skip):/home/moziqi/software/android-studio/adt-bundle-linux-x86_64-20140702/sdk -> Add ANDROID_SDK_ROOT environment variable... ->Added ANDROID_SDK_ROOT=/home/moziqi/software/android-studio/adt-bundle-linux-x86_64-20140702/sdk ->Check environment variable ANT_ROOT ->Search for environment variable ANT_ROOT... ->ANT_ROOT not found ->Search for command ant in system... ->Command ant not found ->Please enter the path of ANT_ROOT (or press Enter to skip):/home/moziqi/software/apache-ant-1.9.4 ->Error: "/home/moziqi/software/apache-ant-1.9.4" is not a valid path of ANT_ROOT. Ignoring it. A backup file "/home/moziqi/.bashrc.backup" is created for "/home/moziqi/.bashrc". Please execute command: "source /home/moziqi/.bashrc" to make added system variables take effect moziqi@moziqi:~/software/cocos2d-x-3.5$ source /home/moziqi/.bashrc moziqi@moziqi:~/software/cocos2d-x-3.5$
2.使用cocos2dx 创建一个项目
moziqi@moziqi:~$ cd /home/moziqi/software/cocos2d-x-3.5 moziqi@moziqi:~/software/cocos2d-x-3.5$ cocos -h /home/moziqi/software/cocos2d-x-3.5/tools/cocos2d-console/bin/cocos.py 1.5 - cocos console: A command line tool for cocos2d-x Available commands: run Compiles & deploy project and then runs it on the target luacompile minifies and/or compiles lua files deploy Deploy a project to the target package Manage package for cocos compile Compiles the current project to binary framework Manage frameworks for the project new Creates a new project jscompile minifies and/or compiles js files Available arguments: -h, --help Show this help information -v, --version Show the version of this command tool Example: /home/moziqi/software/cocos2d-x-3.5/tools/cocos2d-console/bin/cocos.py new --help /home/moziqi/software/cocos2d-x-3.5/tools/cocos2d-console/bin/cocos.py run --help moziqi@moziqi:~/software/cocos2d-x-3.5$ cocos new -h usage: cocos new [-h] [-p PACKAGE_NAME] -l {cpp,lua,js} [-d DIRECTORY] [-t TEMPLATE_NAME] [--ios-bundleid IOS_BUNDLEID] [--mac-bundleid MAC_BUNDLEID] [-e ENGINE_PATH] [--portrait] [--no-native] [PROJECT_NAME] Creates a new project positional arguments: PROJECT_NAME Set the project name optional arguments: -h, --help show this help message and exit -p PACKAGE_NAME, --package PACKAGE_NAME Set a package name for project -l {cpp,lua,js}, --language {cpp,lua,js} Major programming language you want to use, should be [cpp | lua | js] -d DIRECTORY, --directory DIRECTORY Set generate project directory for project -t TEMPLATE_NAME, --template TEMPLATE_NAME Set the template name you want create from --ios-bundleid IOS_BUNDLEID Set a bundle id for ios project --mac-bundleid MAC_BUNDLEID Set a bundle id for mac project -e ENGINE_PATH, --engine-path ENGINE_PATH Set the path of cocos2d-x/cocos2d-js engine --portrait Set the project be portrait. lua/js project arguments: --no-native No native support. moziqi@moziqi:~/software/cocos2d-x-3.5$ cocos new -p com.mo.coco -l cpp -d /home/moziqi/software/android-studio-work/cocos2dx test3.5 Running command: new > Copy template into /home/moziqi/software/android-studio-work/cocos2dx/test3.5 > Copying cocos2d-x files... > Rename project name from 'HelloCpp' to 'test3.5' > Replace the project name from 'HelloCpp' to 'test3.5' > Replace the project package name from 'org.cocos2dx.hellocpp' to 'com.mo.coco' > Replace the mac bundle id from 'org.cocos2dx.hellocpp' to 'com.mo.coco' > Replace the ios bundle id from 'org.cocos2dx.hellocpp' to 'com.mo.coco' moziqi@moziqi:~/software/cocos2d-x-3.5$
一般都是正常运行OK的,就在对于的目录生成一个目录
我一开始报错,说ant路径没有,后面手动按博主那样说的,加上在那个文件上,再次编译
source /home/moziqi/.bashrc
=========================================
配置到这里,我搞不懂为什么
/bin/sh: 1: /home/moziqi/software/apache-ant-1.9.4/ant: not found
Error running command, return code: 127
Traceback (most recent call last):
File "build_native.py", line 43, in <module>
build(opts.build_mode)
File "build_native.py", line 28, in build
raise Exception("Build dynamic library for project [ " + app_android_root + " ] fails!")
Exception: Build dynamic library for project [ /home/moziqi/software/android-studio-work/cocos2dx/test3.5/proj.android/../ ] fails!
moziqi@moziqi:~/software/android-studio-work/cocos2dx/test3.5/proj.android$
后来,查看源码,修改build_native.py文件
#!/usr/bin/python # build_native.py # Build native codes # # Please use cocos console instead import sys import os, os.path import shutil from optparse import OptionParser def build(build_mode): current_dir = os.path.dirname(os.path.realpath(__file__)) cocos_root = os.path.join(current_dir, "../cocos2d") app_android_root = os.path.join(current_dir, "../") if build_mode is None: build_mode = 'debug' elif build_mode != 'release': build_mode = 'debug' command = 'cocos compile -p android -s %s -m %s' % (app_android_root, build_mode) #这里是报错的地方,我把他注释了。 # if os.system(command) != 0: # raise Exception("Build dynamic library for project [ " + app_android_root + " ] fails!") # -------------- main -------------- if __name__ == '__main__': parser = OptionParser() parser.add_option("-n", "--ndk", dest="ndk_build_param", help='it is not used', action="append") parser.add_option("-p", "--platform", dest="android_platform", help='it is not used') parser.add_option("-b", "--build", dest="build_mode", help='the build mode for java project,debug[default] or release.Get more information,please refer to http://developer.android.com/tools/building/building-cmdline.html') (opts, args) = parser.parse_args() print "Please use cocos console instead.\n" build(opts.build_mode)
===========================================================================================
目前遇到这个问题,不知道怎么解决