cocos creator build release android experience

macos development environment cocos creator build release android experience

I have been busy for almost 2-3 days, with only one goal, build and release the android project based on cocos creator 3.7, and run it successfully. This task felt simple at the beginning, and I thought it would be enough to do it with a little bit. As a result, various errors were reported, and the reason was incomprehensible, so it was difficult to solve. Finally, after a few days of tossing, it was basically passed, and the first apk file was completed, 14.7M, which can run normally on the emulator. in conclusion:

1. Character set problem

This problem is the biggest problem. The compilation fails at the beginning. Check the file and find:

1、buidler.gradle

The last line of the file uses the NATIVE_DIR variable, NATIVE_DIR

The variable is defined in the gradle.properties file. The character set of this file is set to iso, so the reading is garbled. The modification method is: directly replace with a string variable.

如:apply from: "/Users/xxx/xxx/xxgame/native/engine/android/build.gradle"

2、gradle.properties

The file is garbled, you need to modify settings->Editor->File Encodings, and set global Encoding, Project Encoding and Default encoding for properties files to utf-8.

Modify (emphasis is utf-8)

org.gradle.jvmargs=-Xmx4608m -Dfile.encoding=UTF-8

3、 settings.gradle

This file involves the NATIVE_DIR variable, which is replaced by a string variable. Note that there are two places, the method is the same as 1.

Second, the compilation path problem

During the compilation process, various errors will be reported, and the design sdk and ndk version problems, the solution is to set the parameters correctly.

1. cocos creator preferences - external program

Need to be set correctly, android ndk, android sdk and cmake path

For example (this must be determined according to the respective installation environment):

Android ndk: /Applications/adt-bundle-mac-x86_64-20140702/sdk/ndk/25.1.8937393

Android SDK: /Applications/adt-bundle-mac-x86_64-20140702/sdk

cmake:/Applications/adt-bundle-mac-x86_64-20140702/sdk/cmake

2. Correctly install android studio

3. Correctly configure android studio-> sdk manager

The use of this tool is the key. All different versions must be configured correctly here to compile successfully. In tools->sdk manager, sdk platforms are mainly different versions of android;

SDK tools include android sdk build-tools, ndk version selection, cmake version selection, and many other tools to download and update.

4. Select android studio -> build -> select build vairant for compilation parameters

You can choose release and debug in it, I chose release, and finally compiled successfully.

5. fs-extra reports an error

Enter the project template directory and run npm installation, such as:

cd /Users/xxx/xxxgame/extensions/cocos-build-template
npm install fs-extra

Then report the error and solve it.

3. Other errors

Because there are too many situations, we can only solve them one by one according to the error prompt. The general idea is: use cocos creator to build an android project, then use android studio to open the project, and finally use build to compile, find errors, and solve them according to the prompts.

Guess you like

Origin blog.csdn.net/a17432025/article/details/128827121