Packaging of Unity's Android project

Configuring the Android operating environment in Unity

1.1 First, unity needs to integrate the android compilation environment, click FIle->Build Settings

3fb1275833b64dcab002a8f60ca600ef.png

1.2 If there is no Android module, if not, download the Android module first.

a6b55154d35c4ac38d1fc6c89ecbc30c.png

1.3 Follow the steps below to download Android support, SDK, NDK, and JDK

b204154f4e274364aee5578458766d9d.png

1.4 If AndroidStudio has been configured with these before, you don’t need to download it, just configure it, Edit->Preferences

a819c9120d5549ed8467cbe8ea25b3a1.png

1.5 Select the External Toos option, pull down and the SDK related configuration will appear. We can just select the local path.

3a0982fce8ff4ab889f5f65106a26c15.png

It is possible to manage the SDK version in Android Studio

2044234a260b467a94fa18f75305fd2b.png

2. Compile and run Android

2.1 Click File -> Build Setting -> Player Settings to enter the project configuration page

c4a7616966774db494abfcf9dd522248.png

2.2 Find Player -> Android module, configure icon, direction, release package name and other information

edffe74fe59c48f58cc4f28d3a601d3d.png

96034c7161a843fd94edcdf8871f035f.png

screen orientation

6cbd1cc8332942f1b39c66ac523e7cd1.png

2.3 Exit to Build Settings and click Build or Build Run

7104a882b5194c3ea8bac7926a12ab78.png

You can generate an unsigned apk in the directory file

6374843673ab4ebdb5ccd04070a08be8.png

Three unity signatures for android projects

3.1 The above only compiles the unsigned package. This is an unsafe package and cannot be put on the application market, so the apk needs to be signed and released. Select the publish of the Project Setting option for key management. You can create a new key or select a local key.

6c6e8410d4fd4efabc0b7267b7e0313f.png

3.2 Then create a new one and fill in the key information

acf7a22f5ed84ebeb989de44551bef57.png

8c2e1a829d7d46a3a783ef282829c358.png

 3.3 Click add Key to configure the key key, and select the Release official package.

3d4d481a17b8404ea5350b56a8ece4c8.png

3.4 You also need to configure the package name information. The package name is the unique identifier of the project and is very important. Find the location of Identification in Other Setting, fill in the package name and version.

fe4bf6202f2b4582a633b2ca9757f07f.png

3.5 Note that it only supports the ARMV7 architecture by default and may not run on some mobile phones, so a prompt is given: You are making a release version and using a custom signing key, but it does not support native 64-bit. If you plan to release this version, please note that most stores will require native 64bit-capable binaries. Add native 64-bit support by updating player settings: set ScriptingBackend to lL2CPP and make sure the target architecture includes ARM64

d4d2a4463bef4e5a8e0238ca9c94db17.png

According to the prompts, we set ScriptingBackend to lL2CPP

392466dc597b4346bff5e41cb92c9736.png

3.6 then changed the tip: Add native 64-bit support by updating player settings: Make sure TargetArchitectures includes ARM64.

d55998bc27364600a1e109603c10bfcf.png

This is because ARM64 is not checked, we can just check it

38dcc3b24cb646e780c48210ac67468f.png

Necessary configuration instructions for 64-bit architecture:

  • Minimum API Level: 26 is enough to meet all platform requirements
  • ScriptingBackend: IL2CPP, transpiled to C++, with better performance and better code encryption effect
  • Target Architectures: ARM64 It’s 2023. At present, all all-in-one device architectures basically support ARM64.

 3.7 Then we recompile and generate an apk file in the project directory

5ea13646344d4043899213341dc6b4a3.png

af147c5e0a074abe881d80710544c17d.png

3.8 Check whether the apk is a signed release package

First, you need to connect the developer mode of the mobile phone via USB, that is, Unity has the connection information of the mobile phone.

51b639ea138f453182be4769981bbc8e.png

Go to the jdk installation directory and right-click to enter the terminal window

8afbf8d96bc644d4812cfb34bea7aa4f.png

adb shell command to check whether apk is a debug package

$ adb shell dumpsys package xx.xx.xx | findstr flags
查看apk是否release版本xx.xx.xx为包名

命令执行成功时,返回flags:
flags=[ DEBUGGABLE HAS_CODE ALLOW_CLEAR_USER_DATA ALLOW_BACKUP LARGE_HEAP ]

代表该APK为debug版本
flags=[ HAS_CODE ALLOW_CLEAR_USER_DATA ALLOW_BACKUP LARGE_HEAP ]
代表该APK为release版本

You can see that the terminal output is the release package

a06021707b2d4f608cab6798ec17a619.png

Interaction between four Unity games and Android native projects

4.1 Sometimes we need to start a unity game module in another app. At this time, we need to export the unity project to a third-party library of android. Android can jump to the game by integrating this unity library.

4.2 Check Export Project in Build Setting. You can see that the Build option at the bottom has changed to Export. Let’s export it.

ea4e8b3531d04f29aa6a083f82553f78.png

4.3 When we export, an android module built by Gradle will be generated. Those who are familiar with this android project can import it into AndroidStudio and run it.

a8fe0baf177a411f8fa1bd013f2249b1.png

4.4 Open AndroidStudio and choose to open the Unity project

c275358f45df4db9a7a903b29f3d8105.png

4.5 You can see that UnityPlayerActivity is the entrance to the game. Let’s click to run it.

6d39a7520ad046f89b67c7f61a457c64.png

4.6 can be seen that it can run. The structure also supports 32 and 64. At this time, you can jump to our game page from any other page.

29d13798f82146c29c1dac2c36df41d2.png

edfeaecfef664e1f953e1277a049162a.jpeg

Guess you like

Origin blog.csdn.net/qq_29848853/article/details/132788896