Use the hot update feature of InjectFix to repair the c# code. The git address corresponding to InjectFix is https://github.com/Tencent/InjectFix
InjectFix does not need to modify the original logic of the C# project, and can use C# to generate patches, but cannot add new classes and functions, so the update method is more in line with Apple's audit specifications. Suitable for repairing online problems on the IOS side
development preparation
Copy the InjectFix library file
IFixToolKit is copied to the Assets sibling directory of the Unity project
Assets/IFix, Assets/Plugins are copied to the Assets of the Unity project
Identifies the type to hot update
Create an InterpertConfig file in the Editor directory to configure classes that can be hot-updated. The method of identifying the Namespace is adopted, so that the classes under the Namespace can be hot updated
using System.Collections.Generic;
using IFix;
using System;
using System.Reflection;
using System.Linq;
//1、配置类必须打[Configure]标签
//2、必须放Editor目录
[Configure]
public class InterpertConfig
{
[IFix]
static IEnumerable<Type> ToProcess
{
get
{
return (from type in Assembly.Load("Assembly-CSharp").GetTypes()
where type.Namespace == "YourNamespace" && !type.Name.Contains("<")
select type);
}
}
}
Repair process
Generate hot update resources
Assuming that the online version is 1.0.0, a corresponding repair version 1.0.0.001 needs to be released at this time
1. Add the library's namespace using IFix to the file that needs to be modified; add the [Patch] tag to the modified function. After repairing, click InjectFix->Fix in the menu bar (the new version will have Fix, Fix (IOS) and Fix (Android) options, directly select the Fix option) to generate Assembly-CSharp.patch.bytes
2. Upload Assembly-CSharp.patch.bytes to the CDN server, and fill in the corresponding information and address in the hot update configuration table below
3. The server sends the corresponding hot update information according to the configuration table
Hot update configuration table
version |
channel |
fixVersion |
abUrl |
1.0.0 |
all |
1.0.0.001 |
https://xxx.oss/app/hotfix/all/1.0.0.001 |
1.0.0 |
huawei |
1.0.0.001 |
https://xxx.oss/app/hotfix/huawei/1.0.0.001 |
1.0.0 |
appstore |
1.0.0.001 |
https://xxx.oss/app/hotfix/appstore/1.0.0.001 |
version: The version number that needs to be fixed
channel: The channel number that needs to be repaired. If it is all, it is the repair package for all platforms. If it is other, it is the repair package for the specific channel. Priority is given to judging the channel package of the specific channel number, if not, select the full-platform repair package.
fixVersion: The version number of the fix version
abUrl: The address of the repair package
Client update flow chart
Precautions
Before releasing the version, you need to execute the menu bar InjectFix->Inject to ensure that the code has been injected. Otherwise, the heat will not work
common problem
Exception: can not load type[System.Int32,netstandard, Version=2.0.0.0, Culture = neutral. PublicKeyToken=cc7b13ffcd2ddd51]
This is because the backend set by the patch is different from the actual packaging setting. The patch is set to netstandard 2.0. So change the API Level to .net 4.x and regenerate the patch package