Unity在无网环境下打包APK

2022-07-12  本文已影响0人  虫小白

参考文档:【游戏开发进阶】教你自制离线Maven仓库,实现Unity离线环境使用Gradle打包(Unity | Android | 谷歌 | Gradle)_林新发的博客-CSDN博客

方法:在能上网的电脑上缓存打包需要的文件拷贝到内网机上部署使用。
测试环境:

内网机环境:win7+unity2017.4.11
外网机环境:win10+unity2017.4.11

public class NewBehaviourScript : MonoBehaviour {

    public string dirPath;//文件夹路径 

    [ContextMenu("修改文件夹")]
    void Excute()
    {
        SimplePath(dirPath);
    }

    void SimplePath(string folderPath)
    {
        string[] files = Directory.GetFiles(folderPath);
        string[] dirs = Directory.GetDirectories(folderPath);

        for (int i = files.Length-1; i >=0; i--)
        {
            List<int> pointIndex = GetCharIndex('.', files[i]);
            if (pointIndex.Count > 0)
            {
                pointIndex.RemoveAt(pointIndex.Count - 1);
            }

            List<int> targetPointIndex = new List<int>();
            for (int j = 0; j < pointIndex.Count; j++)
            {
                int tempIndex = pointIndex[j];
                if (tempIndex > 0 && tempIndex < files[i].Length - 1)
                {
                    if (char.IsNumber(files[i][tempIndex - 1]) && char.IsNumber(files[i][tempIndex + 1]))
                    {
                        continue;
                    }
                    else
                    {
                        targetPointIndex.Add(tempIndex);
                    }
                }
            }

            string filePath = files[i];
            for (int j = 0; j < targetPointIndex.Count; j++)
            {
                filePath = new StringBuilder(filePath).Replace('.', '\\', targetPointIndex[j], 1).ToString();
            }

            string[] temp = filePath.Split('\\');
            string newDir = "";
            for (int j = 0; j < temp.Length-2; j++)
            {
                newDir += temp[j] + "\\";
            }
            Directory.CreateDirectory(newDir.TrimEnd('\\'));
            File.Copy(files[i], newDir + temp[temp.Length - 1]);
        }

        for (int i = 0; i < dirs.Length; i++)
        {
            SimplePath(dirs[i]);
        }
    }

    List<int> GetCharIndex(char c,string value)
    {
        List<int> result = new List<int>();
        for (int i = 0; i < value.Length; i++)
        {
            if (value[i].Equals(c))
            {
                result.Add(i);
            }
        }
        return result;
    }
}

org.jacoco文件夹及其内部文件需要手动处理,处理前,文件结构如下图

007.png
处理后,文件结构如下图
008.png
4,在Unity playerSetting中,勾选Custom Gradle Template
build.png
5,找到mainTemplate打开进行编辑
001.JPG
002.png
6,打包apk报错如下,记住需要的路径
005.png
7,将第3步中处理后的文件夹名称改为repository,复制到.m2文件夹下(没有手动按照第6步的路径创建即可)。
8,打包。
上一篇 下一篇

猜你喜欢

热点阅读