Recorded using some issues cocos2d-js compiled android program encountered

The election of a good development platform is really important when developing applications on an unfamiliar environment, cross-platform below me to do a record with a summary of the school room win7 32-bit systems development cocos2d game compilation pit Andrews encountered.

First, we are more familiar to quote the words, "We must first of its profits", the first step in the development process, of course, is to build environmental matter, and indeed this chapter is about the encounter in the process of building environment Some solutions to the problem.

To compile the application Android platform, you need to download the JDK, NDK and SDK, in addition to the SDK directly Baidu should be able to download. Download the SDK needs FQ, but these days (June 3) for unknown reasons "ladder" can not make, but unfortunately it just means Friends of Almighty downloaded a version number of the SDK r24.1.1, about the size of 200MB, unzip directory As shown below:

After reading "SDK Readme" Knowing the need to run the SDK Manager to download the software resources, it should be noted that first configured java environment before you run, otherwise the program will flash, nothing will happen. I choose here to install JDK1.8, so it is necessary to add a run path (C: \ Program Files \ Java \ jdk1.8.0_211 \ bin) to environment variables, and then run the SDK Manager:

 

All the default installation. To facilitate the management, I would sdk and ndk are extracted to the d: / directory under the android to begin the installation cocos2d-x, incidentally, cocos version 3.17.2 is used here, and then enter cocos extract directory, run python setup.py , followed by input and extraction path ndk sdk to complete the installation, I have been set up here, so run shot as follows:

Then establish a cocos2d-x project, because I used to use js language, so the establishment of a cocos2d-js project named game in the web directory, directory, or other types of projects can also be.

Into the project directory, run cocos compile -p android:

Need to download gradle, later there are still a bunch of packages need to download, keep network connections installed by default. Then given the configuration process, the information can be seen from the console are missing licences:

解决方案是进入sdk/tools/bin目录可以看到有一个sdkmanager批处理文件,在这个位置运行命令sdkmanager "build-tools;27.0.3",然后输入“y”同意授权:

然后重新编译。又出错了,提示缺少cmake工具,可能是因为我这个sdk最初不是从谷歌官网上下载的吧?去cmake官网下载,由于我这里使用的是32位系统,所以下载了cmake-3.14.5-win32-x86软件包,看控制台给出的信息知道要将cmake解压到sdk目录下:

继续编译。还是出错,这次的原因没看明白(还没开始学android开发。。。),控制台给出的信息是:com.android.ide.common.process.ProcessException: Error configuring:

好吧,搜索引擎是最好的老师,百度一下发现说各种原因的都有,于是乎具体问题具体分析,把控制台往上翻翻看第一个错出在哪里?找到第一个问题:

貌似是缺少一个叫android_gradle_build.json的文件,于是系统决定生成一个,然后又遇到下一个问题:缺少ninja文件:

于是去百度一下ninja,原来它是一个编译工具,官网有给出github链接,去下载即可。不过直接下载到的是64位的可执行程序,我这里32位环境下只能先下载它的源码再编译了,下载的版本是ninja-1.9.0,进入解压目录一看貌似是使用python进行编译的:

一个好的习惯是先看一下README.md文件。

在目录下运行命令python configure.py --bootstrap来编译程序,详细信息在HACKING.md文件。先试试直接编译吧:

好吧,直接报错,好像是一个函数msvc_needs_fs的原因,打开源码一看原来是缺少c++编译环境,可以选择微软的编译工具msvc或者GNU编译工具mingw。考虑到学校电脑没有安装visual studio而蓝桥杯竞赛安装了dev-cpp,于是进入dev-cpp安装目录下果然找到了mingw,于是将~\mingw\bin路径添加到环境变量。

通过阅读configure.py源码知道可加入--platform参数来指定编译平台(Platform构造函数):

于是在ninja解压目录下重新打开cmd,运行命令python configure.py --bootstrap --platform mingw编译成功!

要使用生成的ninja.exe,需要添加到环境变量,于是我将它移到了sdk\cmake\bin目录下并将该目录添加到了环境变量(也可以是其他目录)。然后重新编译cocos,发现问题并没哟解决。。。

参考一博客文章将cocos工程下frameworks\runtime-src\proj.android\build.gradle文件的classpath 'com.android.tools.build:gradle:3.1.0'改为classpath 'com.android.tools.build:gradle:3.2.1'成功解决,然而又出现新的问题:

根据提示知道ndk/toolchains/llvm/prebuilt/windows-x86_64目录并不存在,看来ndk编译安卓平台默认是使用64位的啊,要完成编译,找到ndk目录下build\cmake\android.toolchain.cmake文件,查找ANDROID_HOST_TAG,将set(ANDROID_HOST_TAG windows-x86_64)改为set(ANDROID_HOST_TAG windows):

最后编译cocos,共772个目标文件。

Cocos官方建议使用android-studio集成开发环境来编译发布安卓平台,要使用命令行工具也建议选择64位系统,不然就会像我一样遇到各种坑爹的问题。每个人因为开发环境的不同遇到的问题也会不一样,不过解决问题的方法都是相通的,写这篇博客的时候我还是在校本科生,编程能力和经验都不足,这可能并不是一个好的解决问题的方法,但还是希望这篇博客能够帮助到和我遇到同样问题的人。

Guess you like

Origin www.cnblogs.com/viewts/p/10964050.html