コード例 #1
0
ファイル: DeployAndroid.cs プロジェクト: P79N6A/BuildProject
    static void DeployLibrary()
    {
        bool needReplace = true;

        Debug.Log("DIR_MSDKLIBRARY:" + DIR_MSDKLIBRARY);
        string[] msdkJarFile = Directory.GetFiles(DIR_MSDKLIBRARY + "/libs", "MSDK_Android_*.jar");
        /* 此目录中应只有一个 MSDK jar 包 */
        if (msdkJarFile.Length != 1)
        {
            env.Error("Get MSDK jar file error! Check jar file in " + DIR_MSDKLIBRARY + "/libs");
            return;
        }
        string srcJar = msdkJarFile [0];

        string destJar = env.PATH_PUGLIN_ANDROID + "/MSDKLibrary/libs/" + Path.GetFileName(srcJar);

        if (destJar != null && destJar.Length != 0 && File.Exists(destJar))
        {
            string srcMd5  = MsdkUtil.GetFileMd5(srcJar);
            string destMd5 = MsdkUtil.GetFileMd5(destJar);
            if (srcMd5 == destMd5)
            {
                needReplace = false;
            }
        }

        if (needReplace)
        {
            Debug.Log("Would replace MSDKLibrary.\n" + srcJar + " is not equale to " + destJar);
            MsdkUtil.ReplaceDir(DIR_MSDKLIBRARY, env.PATH_PUGLIN_ANDROID + "/MSDKLibrary");
            // Unity只会打 armeabi-v7a x86 的so,删除多余指令集的so解决机型兼容问题
            string[] abis = Directory.GetDirectories(env.PATH_PUGLIN_ANDROID + "/MSDKLibrary/libs");
            foreach (string abi in abis)
            {
                string abiName = Path.GetFileName(abi);
                if (abiName.Equals("armeabi-v7a") || abiName.Equals("x86"))
                {
                    continue;
                }
                if (Directory.Exists(abi))
                {
                    try {
                        Directory.Delete(abi, true);
                    } catch (IOException e) {
                        Debug.LogException(e);
                    }
                }
            }
        }
        else
        {
            Debug.Log("Would not replace MSDKLibrary.\n" + srcJar + " is equale to " + destJar);
        }
    }
コード例 #2
0
    private static void CopyFrameworks(string pathToBuiltProject, bool isC11)
    {
        string destDir = pathToBuiltProject + "/MSDK";

        if (!Directory.Exists(destDir))
        {
            Directory.CreateDirectory(destDir);
        }
        Debug.Log("isC11:" + isC11);
        string tail = "";

        if (isC11)
        {
            tail = "_C11";
        }
        MsdkUtil.ReplaceDir(env.PATH_LIBRARYS_IOS + "/Library/MSDK" + tail + "/MSDK.framework",
                            destDir + "/MSDK.framework");
        MsdkUtil.ReplaceDir(env.PATH_LIBRARYS_IOS + "/Library/MSDK" + tail + "/MSDKResources" + tail + ".bundle",
                            destDir + "/MSDKResources.bundle");
        MsdkUtil.ReplaceDir(env.PATH_LIBRARYS_IOS + "/Library/MSDK" + tail + "/WGPlatformResources" + tail + ".bundle",
                            destDir + "/WGPlatformResources.bundle");

        MsdkUtil.ReplaceDir(env.PATH_LIBRARYS_IOS + "/MSDKAdapter" + tail + "/MSDKAdapter" + tail + ".framework",
                            destDir + "/MSDKAdapter.framework");
        if (!isC11)
        {
            return;
        }
        DirectoryInfo xcodeMsdk = new DirectoryInfo(destDir);

        DirectoryInfo[] frameworks = xcodeMsdk.GetDirectories("*.framework");
        foreach (DirectoryInfo framework in frameworks)
        {
            FileInfo[] files = framework.GetFiles("*_C11");
            foreach (FileInfo file in files)
            {
                file.MoveTo(file.DirectoryName + "/" + file.Name.Replace("_C11", ""));
            }
        }
    }
コード例 #3
0
ファイル: DeployAndroid.cs プロジェクト: P79N6A/BuildProject
    static void GenerateAdapter()
    {
        MsdkUtil.ReplaceDir(env.PATH_ADAPTER_ANDROID + "/java", env.PATH_TEMP + "/java");
        MsdkUtil.ReplaceTextWithRegex(env.PATH_TEMP + "/java/src/com/tencent/msdk/adapter/MsdkActivity.java", srcFileRules);
        MsdkUtil.ReplaceText(env.PATH_TEMP + "/java/src/com/example/wegame/MGameActivity.java", "com.example.wegame", game.BundleId);
        MsdkUtil.ReplaceText(env.PATH_TEMP + "/java/src/com/example/wegame/wxapi/WXEntryActivity.java", "com.example.wegame", game.BundleId);

        File.Move(env.PATH_TEMP + "/java/src/com/example/wegame/MGameActivity.java", env.PATH_TEMP + "/java/src/MGameActivity.java");
        File.Move(env.PATH_TEMP + "/java/src/com/example/wegame/wxapi/WXEntryActivity.java",
                  env.PATH_TEMP + "/java/src/WXEntryActivity.java");
        Directory.Delete(env.PATH_TEMP + "/java/src/com/example", true);
        string packagePath = game.BundleId.Replace(".", "/");

        packagePath = packagePath.Trim();
        Directory.CreateDirectory(env.PATH_TEMP + "/java/src/" + packagePath);
        File.Move(env.PATH_TEMP + "/java/src/MGameActivity.java", env.PATH_TEMP + "/java/src/" + packagePath + "/MGameActivity.java");
        Directory.CreateDirectory(env.PATH_TEMP + "/java/src/" + packagePath + "/wxapi");
        File.Move(env.PATH_TEMP + "/java/src/WXEntryActivity.java",
                  env.PATH_TEMP + "/java/src/" + packagePath + "/wxapi/WXEntryActivity.java");

        string msdkUnityJar = ADAPTER_JARFILE_PREFIX + WGPlatform.Version + ".jar";

        string androidSdkJar  = "";
        string androidSdkRoot = EditorPrefs.GetString("AndroidSdkRoot");

        if (!Directory.Exists(androidSdkRoot))
        {
            env.Error("Android Sdk Location Error! Check on \"Preferences->External Tools \"");
            return;
        }

        string[] platforms     = Directory.GetDirectories(androidSdkRoot + "/platforms");
        string[] platformsTemp = platforms.Where(str => Regex.IsMatch(str, @"android-\d\d$")).ToArray();
        if (platformsTemp.Length != 0)
        {
            platforms = platformsTemp;
        }
        else
        {
            platforms = platforms.Where(str => Regex.IsMatch(str, @"android-\d$")).ToArray();
        }
        System.Array.Sort(platforms, System.StringComparer.Ordinal);
        for (int i = 1; i <= platforms.Length; i++)
        {
            androidSdkJar = platforms[platforms.Length - i] + "/android.jar";
            if (File.Exists(androidSdkJar))
            {
                break;
            }
        }
        if (!File.Exists(androidSdkJar))
        {
            env.Error("Find android.jar error in " + androidSdkRoot + "/platforms");
        }

        string[] msdkJarFile = Directory.GetFiles(DIR_MSDKLIBRARY + "/libs", "MSDK_Android_*.jar");
        /* 此目录中应只有一个 MSDK jar 包 */
        if (msdkJarFile.Length != 1)
        {
            env.Error("Get MSDK jar file error! Check jar file in " + DIR_MSDKLIBRARY + "/libs");
            return;
        }
        string msdkLibraryJar = msdkJarFile [0];

#if UNITY_EDITOR_WIN
        string shellFile = env.PATH_TEMP + "/java/MsdkAdapter.bat";
        string dirRoot   = Path.GetPathRoot(env.PATH_TEMP);
        dirRoot = dirRoot.Replace("\\", "");
        MsdkUtil.ReplaceText(shellFile, "DirRoot", dirRoot);
#elif UNITY_EDITOR_OSX
        string shellFile = env.PATH_TEMP + "/java/MsdkAdapter.sh";
#else
        string shellFile = "";
#endif
        MsdkUtil.ReplaceText(shellFile, "MSDKUnityLibrary", env.PATH_TEMP + "/java");
        MsdkUtil.ReplaceText(shellFile, "MSDKUnityJar", msdkUnityJar);
        MsdkUtil.ReplaceText(shellFile, "MSDKLibraryJar", msdkLibraryJar);
        MsdkUtil.ReplaceText(shellFile, "AndroidSdkJar", androidSdkJar);
        MsdkUtil.ReplaceText(shellFile, "UnityJar", env.PATH_LIBRARYS_ANDROID + "/UnityClasses.jar");
        MsdkUtil.ReplaceText(shellFile, "GamePackage", packagePath);
        Debug.Log(File.ReadAllText(shellFile));
        shellFile = "\"" + shellFile + "\"";

        Encoding utf8WithoutBom          = new UTF8Encoding(false);
        System.Diagnostics.Process shell = new System.Diagnostics.Process();
                #if UNITY_EDITOR_WIN
        shell.StartInfo.FileName = "cmd.exe";
                #elif UNITY_EDITOR_OSX
        shell.StartInfo.FileName = "sh";
                #endif
        shell.StartInfo.UseShellExecute        = false;
        shell.StartInfo.RedirectStandardInput  = true;
        shell.StartInfo.RedirectStandardOutput = true;
        shell.StartInfo.RedirectStandardError  = true;
                #if UNITY_EDITOR_WIN
        Encoding gb = Encoding.GetEncoding("gb2312");
        shell.StartInfo.StandardOutputEncoding = gb;
        shell.StartInfo.StandardErrorEncoding  = gb;
                #endif
        shell.StartInfo.CreateNoWindow = true;
        shell.Start();

        Stream       input = shell.StandardInput.BaseStream;
        StreamWriter myIn  = new StreamWriter(input, utf8WithoutBom);

                #if UNITY_EDITOR_OSX
        myIn.WriteLine("chmod a+x " + shellFile);
                #endif
        myIn.WriteLine(shellFile);
        myIn.WriteLine("exit");
        myIn.AutoFlush = true;
        myIn.Close();

        if (!shell.WaitForExit(5000))
        {
            env.Error("Execute shell command out time! Check Console for Detail");
        }
        if (shell.StandardError.Peek() != -1)
        {
            env.Error("Execute shell command return error! Check Console for Detail");
            env.Error(shell.StandardError.ReadToEnd());
        }
        shell.Close();

        string outputJar = env.PATH_TEMP + "/java/classes/" + msdkUnityJar;
        if (!File.Exists(outputJar))
        {
            env.Error("Generate " + msdkUnityJar + " error! Check Console for Detail");
        }
        else
        {
            string[] adapterJars = Directory.GetFiles(env.PATH_PUGLIN_ANDROID + "/libs/");
            foreach (string file in adapterJars)
            {
                if (file.IndexOf(ADAPTER_JARFILE_PREFIX) >= 0)
                {
                    File.Delete(file);
                }
            }
            string targetJar = env.PATH_PUGLIN_ANDROID + "/libs/" + msdkUnityJar;
            File.Move(outputJar, targetJar);
        }
    }