Git command line scam notes
Recently, when writing the packaging pipeline, I encountered several pits, so I will summarize it a little.
Pull the remote branch if it exists, checkout if it does not exist
Full pull
1 | git clone -b master "${git_url}" "${products_dir}" |
There is a pit to pay attention to here, that is, you can’t use ‘–depth = 1’ when ** cloning, which will cause you to only pull the information of the branch in the future, and the other branches do not exist no matter how you check **
But sometimes our repository is too big, we just want to pull the latest version of the branch how to do, can pull success pull success, pull success to create a branch.
Sounds fine, but if you write directly, you will encounter problems, that is, the entire shell will exit if you fail to pull it, so is there a way to solve it?
There are two ways, the first is to use subprocess.
Subprocess tries to pull the latest version
1 | git_clone=$(git clone--depth=1 -b "${branch}" "${git_url}" "${products_dir}") |
The internal part of '$ () ’ is subprocess, its failure will not cause the shell to exit directly
set
** Set set + e in the head of the shell to ensure that the failure does not exit, and then check whether the command is executed successfully **
1 | !/bin/bash |
‘$?’ means to get the execution result of the previous instruction. If the result is 0, it means success.
If the repository uses lfs, it is best to use git
That is to say, if your repository uses lfs, then try to use’git lfs clone ‘instead of’git clone’, the same is true for other commands
android:requestLegacyExternalStorage
If you encounter such an error during the packaging of the APK: ‘AAPT: error: attribute android: requestLegacyExternalStorage not found.’
This problem occurs when the project build.gradle - compileSdkVersion is configured with a version less than 29 and also configures the android: requestLegacyExternalStorage property in AndroidManifest.xml - application (whether it is configured by your own project or the third-party library).
This property is mainly used because of the storage permission adjustment of Android 10.0, a temporary solution launched by Google.
This blog describes two solutions: https://juejin.cn/post/6850418117093523464
However, these two methods do not apply to our situation, because we are directly generated APK, there is no way to pause the operation of the middle of the Gradle product, of course, we can say that the first package Gradle project out, and then build APK
However, Unity officially provides a method. We can define the’AndroidManifest.xml 'of the intermediate Gradle product. There are two types here. One is to define the unityLibrary, the other is to define the launcher, and we take the second
Then change the generated’Assets/Plugins/Android/LauncherManifest.xml 'to this:
1 |
|
Mainly add’tools: remove = “android: requestLegacyExternalStorage” 'in the application tag