Configuring the Android operating environment in Unity
1.1 First, unity needs to integrate the android compilation environment, click FIle->Build Settings
1.2 If there is no Android module, if not, download the Android module first.
1.3 Follow the steps below to download Android support, SDK, NDK, and JDK
1.4 If AndroidStudio has been configured with these before, you don’t need to download it, just configure it, Edit->Preferences
1.5 Select the External Toos option, pull down and the SDK related configuration will appear. We can just select the local path.
It is possible to manage the SDK version in Android Studio
2. Compile and run Android
2.1 Click File -> Build Setting -> Player Settings to enter the project configuration page
2.2 Find Player -> Android module, configure icon, direction, release package name and other information
screen orientation
2.3 Exit to Build Settings and click Build or Build Run
You can generate an unsigned apk in the directory file
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.
3.2 Then create a new one and fill in the key information
3.3 Click add Key to configure the key key, and select the Release official package.
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.
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
According to the prompts, we set ScriptingBackend to lL2CPP
3.6 then changed the tip: Add native 64-bit support by updating player settings: Make sure TargetArchitectures includes ARM64.
This is because ARM64 is not checked, we can just check it
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
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.
Go to the jdk installation directory and right-click to enter the terminal window
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
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.
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.
4.4 Open AndroidStudio and choose to open the Unity project
4.5 You can see that UnityPlayerActivity is the entrance to the game. Let’s click to run it.
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.