Unity2020 packaging Android APK (including apk signature and old version project compilation and packaging problems)

Recently, the teacher threw an old SDK and asked me to compile it into an Android APK. My computer is already a hodgepodge. Unity2017, unity2020, Android Studio 3.4. I used the computer given by the teacher (green and pollution-free), using the Unity2020 version, without the Java environment, and record the compilation process below.

1. Unity Hub

It is necessary to package Android APK, Android SDK and Java Environment. It is recommended to use the environment added and downloaded through Unity Hub (I also follow this process, because it is too time-consuming to add SDK and Java environment by myself). It should be noted here that only the Unity version downloaded through the Unity Hub can automatically add the Android module through the Unity Hub, otherwise it must be downloaded again or manually configured by itself.

insert image description here
Right-click the corresponding Unity in the Unity hub and select Add Module.
insert image description here
Select the Android module to download directly.

2. Unity

1. Check the Android environment

After adding the Android module, open Unity and check whether the Android environment of Edit->Preferences->External Tools is configured normally.
Please add a picture description
According to the normal operation, it should be consistent with the above picture. It is recommended to use the environment installed by Unity, without manual configuration. If you have special needs, you can change the corresponding directory by yourself (bloggers think it is troublesome).

2、Building Setting

Select File->Building Setting->Android->Switch Platform to switch to the Android platform.
Please add a picture description
There is basically no need to select anything on this interface.

3. Player setting – create a signature

Click Player Setting->Player->Publish Settings in the lower left corner. There is a very important thing here, because the project must be signed because it needs to be packaged into an Apk for device installation, as shown in the figure below. Please add a picture description
How to create a signature file. First select Keystore
insert image description here
in the pop-up window, click Create new -> Anywhere.
insert image description here
You will be asked to choose a folder to create a keystore file. Here, create an Android folder in the same level directory as the Unity project Assets and store it here.
insert image description here
Then you can create information for the signature. Here you need to remember the password that will be used later. Alias ​​is the name of the signature file and you should also remember it. Other settings are optional.

Finally, select the password file you just created for your project, and enter the password you just set. Finally, you can directly build and run the Android file created earlier. (Note that if you deploy the device via usb, you need to enable the developer option for the device or enable the usb file transfer function of the device)

3. The problem of compiling the old project using the new version library

Because the SDK version is very old, there are still some problems in consideration of backward compatibility. I will record two possible common problems here.

1、The minSdk version can not be specified in the AndroidManifest.xml file. You have to remove it.(See the Console for details)

insert image description here

Obviously, this error is a reminder that you cannot specify the minimum version of Androidsdk in the AndroidManifest configuration, then find this file directly and delete this configuration (the test can be successfully deployed), and it is best to go to Unity's Player->other setting Set the corresponding version number in .
insert image description here

2. Prompt that an old file cannot be deleted.

I forgot to take a screenshot of this error. If you are prompted that this error has been compiled before, some old compiled programs have been temporarily stored. This part of the file may have error information. The second compilation is in the original temporary compilation file. , and Unity could not delete him, so an error occurred. This part of the compiled file should be in the Temp folder at the same level as assets, just clear the folder, or restart Unity to complete the compilation.

Four. Conclusion

The last "work" of this year has been completed, and you can "rest" for a while.

Guess you like

Origin blog.csdn.net/qq_44706002/article/details/127918833