Cocos Creator Android apk package

This is an article about some of the problems encountered with packed Android APP Cocos Creator compiler time, although the packaging says the process is not very complicated, but which will still encounter a variety of pit.

We will project with CCC (Cocos Creator) compiler package when it must be configured first native development environment, I am here mainly packaged into Android APP when the need to rely on the development environment.

Download the Java SDK (JDK)

Need to have a complete Java SDK tools on the local computer engineering at compile time Android, without this tool can be downloaded to the following address:

Java SE Development Kit 8 Downloads

Download time and choose what to pay attention to match the native operating system and architecture, the download is complete run the installation on it.

Check the Java environment after installation is to enter the following code in the command-line tool to view:

  java -version

FIG displayed on the output result, there is no problem, if the system is used to install the JRE  JAVA SE Runtime Environment

After inspection, we also need to make sure the environment variable under this machine contains JAVA_HOME. No environment can be configured by right-clicking My Computer, select Properties to open the Advanced tab to view and modify environment variables.

Variable value is the path where Java is installed, you need to restart the computer to take effect after the changes are complete.

In accordance with the official documents , download JDK download the SDK and NDK is required by Android Studio. Of course, you can go alone to download these two tools: SDK , NDK   . After downloading the installation is to run on it.

We will first talk about here to download from Android Studio, the first is to install Android Studio   . During the installation directly point the next step, the next step on it.

安装完成之后,运行打开一个新的文件就可以了,进入主界面之后。点击主界面右上角的一个是下载的图标去下载安装我们所需的工具。

 

点开之后进入分页栏,根据自己想支持的手机版本去下载

 

在 SDK Tools 分页栏,首先勾选右下角的 Show Package Details,显示分版本的工具选择。

在 Android SDK Build-Tools 里,选择最新的 build tools 版本。

勾选 Android SDK Platform-Tools, Android SDK Tools 和 Android Support Library

勾选 NDK,确保版本在 14 以上(推荐使用 r16)。NDK-r18 已经移除了 GNU 编译器,请 Creator v2.0.9 以下的版本 不要 将 NDK 更新到 r18,否则会导致编译报错。

记住窗口上方所示的 Android SDK Location 指示的目录,稍后我们需要在 Cocos Creator 里填写这个 SDK 所在位置。

点击 OK,根据提示完成安装。

 

 

配置原生发布环境路径

下载安装好开发环境依赖后,让我们回到 Cocos Creator 中配置构建发布原生平台的环境路径。在主菜单中选择 文件 -> 设置,打开设置窗口:

 

在原生开发环境里面要配置两个路径:

  • NDK 路径,选择 Android SDK Location 路径下的 ndk-bundle 文件夹(NDK 是其根目录),不需要编译 Android 平台的话这里可以跳过。
  • Android SDK 路径,选择刚才在 SDK Manager 中记下的 Android SDK Location 路径(Android SDK 的目录下应该包含 build-tools、platforms 等文件夹),不需要编译 Android 平台的话这里可以跳过。

配置完成后点击 保存 按钮,保存并关闭窗口。

配置好开发环境后就是打包发布了。

打包发布原生平台

点击菜单栏的 项目 -> 构建发布,打开构建发布面板。或者快捷键 Ctrl + Shift + B 也可以打开构建发布面板。

 

这里的这些构建选项都可以参考 Cocos Creator 的官方文档 去查看各个选项的作用,这里就不再一一列出了。

构建原生工程

选择发布平台,设置了初始场景后,就可以开始构建了,点击右下角的 构建 按钮,开始构建流程。

 

构建成功后,在CCC编译器面板的控制台,看到输出了

Built to "C:\Users\Administrator\Desktop\Animation\build\jsb-link" successfully

就表示已经构建成功。构建结束后,我们得到的是一个标准的 cocos2d-x 工程,和使用 Cocos Console 新建的工程有同样的结构。接下来我们可以选择通过 Cocos Creator 编辑器的进程进行编译,以及运行桌面预览,或手动在相应平台的 IDE 中打开构建好的原生工程,进行进一步的预览、调试和发布。

通过编译器去编译和运行

点击下方的 编译 按钮,进入编译流程,如果模板选择了 link 的源码版引擎,这个编译的过程将会花费比较久的时间。编译成功后会提示

Compile native project successfully.

如果在控制台中显示出现错误的,建议删除掉 SDK 中的 ndk-bundle 文件,然后重新 下载 DNK 文件,建议下载旧版本 r16 或者 r17,下载最新版本可能会报错。

下载完成后将下载的文件替换掉我们删除的 ndk-bundle 文件,并将文件名更改成 ndk-bundle 。然后再次进行编译。

接下来就可以点击右下角的 运行 按钮,通过默认方式预览原生平台的游戏。

preview

点击运行后,视平台不同可能还会继续进行一部分编译工作,请耐心等待或通过日志文件查看进展。

如果我们没有更改路径,打包后的 apk 会在 build\jsb-link\publish\android 里面。

这就完成了打包,虽然不是很难,但是我们总是会因为配置环境变量的问题,而报出各种错误,在下载工具的时候也会因为工具的残缺,报出各式各样的错误,总之会出现各种各样的坑。

Guess you like

Origin www.cnblogs.com/zhen-prz/p/10967886.html