Ejemplo n.º 1
0
        //[MenuItem ("iDreamsky/ReadMsconfig")]
        public static MSLDPostProcessConfig ReadMsConfig(string unityProjectDir)
        {
            //读取json配置
            //Debug.Log("msPath unityProjectDir: " + unityProjectDir);
            string msPath = Path.Combine(unityProjectDir, "Assets/Plugins/iDreamsky/msld/Android/msConfig.json");
            //Debug.Log("msPath: " + msPath);
            var sourceContent            = File.ReadAllText(msPath);
            MSLDPostProcessConfig config = JsonUtility.FromJson <MSLDPostProcessConfig>(sourceContent);

            return(config);
        }
Ejemplo n.º 2
0
        public static void OnPostProcessBuild(BuildTarget buildTarget, string pathToBuiltProject)
        {
            var dataPath        = Application.dataPath;
            var len             = dataPath.Length - "Assets".Length;
            var unityProjectDir = dataPath.Remove(len);

            MSLDPostProcessConfig config = MSLDPostProcessCommoniOS.ReadMsConfig(unityProjectDir);

            if (config.wx_app_id == null || config.wx_app_id.Length <= 0)
            {
                Debug.LogError("[MSLDPostProcess][iOS][PostProcessControllerIOS]:wechat appkey is not available.");
                return;
            }

            //if (config.wx_app_secret == null || config.wx_app_secret.Length <= 0)
            //{

            //    Debug.LogError("[MSLDPostProcess][iOS][PostProcessControllerIOS]:wechat appSecret is not available.");
            //    return;
            //}

            string[] schemes = new string[]
            {
                "weixin",
                "wechat",
            };

            MSLDPostProcessCommoniOS.ChangeInfoPlist(pathToBuiltProject, (PlistDocument doc) =>
            {
                MSLDPostProcessCommoniOS.AddApplicationQueriesSchemes(doc, schemes);

                string wxURLType = config.wx_app_id.Trim();
                MSLDPostProcessCommoniOS.AddURLTypes(doc, "Editor", "weixin", wxURLType);

                return(true);
            });
        }
Ejemplo n.º 3
0
        public static void OnPostProcessBuild(BuildTarget buildTarget, string pathToBuiltProject)
        {
            Debug.Log("MSLD Post ProcessBuild <LeBianPostProcessAndroid>");
            var    dataPath        = Application.dataPath;
            var    len             = dataPath.Length - "Assets".Length;
            var    unityProjectDir = dataPath.Remove(len);
            string androidProjPath = MSLDPostProcessCommonAndroid.GetProjectPathFromBuild(pathToBuiltProject);

            bool success = MSLDPostProcessCommonAndroid.ChangeAndroidManifestAndroid(androidProjPath, (document, appElement, activityElement) => {
                // 读取配置
                MSLDPostProcessConfig config = MSLDPostProcessCommonAndroid.ReadMsConfig(unityProjectDir);

                string MainChId     = config.lb_MainChId;
                string LEBIAN_SECID = config.lb_LEBIAN_SECID;
                string lebianChanle = config.ms_channel_id;
                if (MainChId == null || MainChId.Length == 0)
                {
                    Debug.LogError("MSLD LB MainChId 未配置");
                    return(false);
                }
                if (LEBIAN_SECID == null || LEBIAN_SECID.Length == 0)
                {
                    Debug.LogError("MSLD LB LEBIAN_SECID 未配置");
                    return(false);
                }
                if (lebianChanle == null || lebianChanle.Length == 0)
                {
                    Debug.LogError("MSLD LB channnel Id 未配置");
                    return(false);
                }
                Debug.Log("MSLD LB MainChId:" + MainChId);
                Debug.Log("MSLD LB LEBIAN_SECID:" + LEBIAN_SECID);
                Debug.Log("MSLD LB lebianChanle:" + lebianChanle);

                //读取lb的xml配置
                string lbXmlPath = Path.Combine(unityProjectDir, "Assets/Plugins/iDreamsky/msld/Android/lebian/lb-AndroidManifest.xml");
                Debug.Log("MSLD LB lbXmlPath:" + lbXmlPath);

                var lbXmlDocument = new XmlDocument();
                lbXmlDocument.Load(lbXmlPath);

                string packageName = PlayerSettings.applicationIdentifier;
                Debug.Log("MSLD LB packageName:" + packageName);

                var mfest = lbXmlDocument.SelectSingleNode("manifest");

                // lb_target_pkgname 替换包名
                var providers = mfest.SelectNodes("provider");
                foreach (XmlNode item in providers)
                {
                    foreach (XmlAttribute att in item.Attributes)
                    {
                        if (att.Value.Contains("lb_target_pkgname"))
                        {
                            string newValue = att.Value.Replace("lb_target_pkgname", packageName);
                            ((XmlElement)item).SetAttribute(att.LocalName, att.NamespaceURI, newValue);
                        }
                    }
                }

                //设置横竖屏
                string allowValue = "";
                if (PlayerSettings.allowedAutorotateToLandscapeLeft || PlayerSettings.allowedAutorotateToLandscapeRight)
                {
                    allowValue = "landscape";
                }
                //if (PlayerSettings.allowedAutorotateToPortrait || PlayerSettings.allowedAutorotateToPortraitUpsideDown)
                //{
                //    if (!string.IsNullOrEmpty(allowValue))
                //    {
                //        allowValue += "|";
                //    }
                //    allowValue += "portrait";
                //}

                Debug.Log("MSLD LB allowValue:" + allowValue);

                var activitys = mfest.SelectNodes("activity");
                foreach (XmlNode item in activitys)
                {
                    if (item.Attributes["android:name"].Value == "com.excelliance.open.NextChapter")
                    {
                        //var cc = item.Attributes["android:configChanges"];
                        var cc = item.Attributes["android:screenOrientation"];
                        ((XmlElement)item).SetAttribute(cc.LocalName, cc.NamespaceURI, allowValue);
                    }
                }

                // 设置 ClientChId
                // 设置  MainChId LEBIAN_SECID
                var metas = mfest.SelectNodes("meta-data");
                foreach (XmlNode item in metas)
                {
                    if (item.Attributes["android:name"].Value == "ClientChId")
                    {
                        var cc = item.Attributes["android:value"];
                        ((XmlElement)item).SetAttribute(cc.LocalName, cc.NamespaceURI, lebianChanle);
                    }
                    else if (item.Attributes["android:name"].Value == "MainChId")
                    {
                        var cc = item.Attributes["android:value"];
                        ((XmlElement)item).SetAttribute(cc.LocalName, cc.NamespaceURI, MainChId);
                    }
                    else if (item.Attributes["android:name"].Value == "LEBIAN_SECID")
                    {
                        var cc = item.Attributes["android:value"];
                        ((XmlElement)item).SetAttribute(cc.LocalName, cc.NamespaceURI, LEBIAN_SECID);
                    }
                }

                //lbXmlDocument.Save(lbXmlPath.Replace(".", "_d."));
                // 内容设置到主activity
                foreach (XmlNode item in mfest.ChildNodes)
                {
                    //Debug.Log("MSLD LB item:" + item.Value);
                    appElement.AppendChild(document.ImportNode(item, true));
                }
                //document.Save(lbXmlPath.Replace(".", "_d2."));

                // 设置 application:name com.excelliance.open.LBApplication
                Debug.Log("MSLD LB set com.excelliance.open.LBApplication");
                appElement.SetAttribute("name", appElement.Attributes["android:icon"].NamespaceURI, "com.excelliance.open.LBApplication");

                // 设置权限
                XmlElement manifest = (XmlElement)document.SelectSingleNode("manifest");
                if (manifest == null)
                {
                    Debug.LogError("[MSLDPostProcess][Android][ChangeAndroidManifest]: manifest Not exists");
                    return(false);
                }
                MSLDPostProcessCommonAndroid.AddAndroidPermission(document, manifest, "android.permission.GET_DETAILED_TASKS");
                MSLDPostProcessCommonAndroid.AddAndroidPermission(document, manifest, "android.permission.REORDER_TASKS");
                MSLDPostProcessCommonAndroid.AddAndroidPermission(document, manifest, "android.permission.INTERNET");
                MSLDPostProcessCommonAndroid.AddAndroidPermission(document, manifest, "android.permission.WAKE_LOCK");
                MSLDPostProcessCommonAndroid.AddAndroidPermission(document, manifest, "android.permission.ACCESS_NETWORK_STATE");
                MSLDPostProcessCommonAndroid.AddAndroidPermission(document, manifest, "android.permission.ACCESS_WIFI_STATE");
                MSLDPostProcessCommonAndroid.AddAndroidPermission(document, manifest, "android.permission.READ_EXTERNAL_STORAGE");
                MSLDPostProcessCommonAndroid.AddAndroidPermission(document, manifest, "android.permission.WRITE_EXTERNAL_STORAGE");
                MSLDPostProcessCommonAndroid.AddAndroidPermission(document, manifest, "android.permission.GET_TASKS");
                MSLDPostProcessCommonAndroid.AddAndroidPermission(document, manifest, "android.permission.READ_PHONE_STATE");
                MSLDPostProcessCommonAndroid.AddAndroidPermission(document, manifest, "android.permission.REQUEST_INSTALL_PACKAGES");
                MSLDPostProcessCommonAndroid.AddAndroidPermission(document, manifest, "android.permission.FOREGROUND_SERVICE");
                return(true);
            });

            if (!success)
            {
                Debug.LogError("MSLD LB ChangeAndroidManifestAndroid error ");
            }

            //  Debug.Log("MSLD LB androidProjPath:" + androidProjPath);
            //// 复制application com.excelliance.open;
            //if (!MSLDPostProcessCommonAndroid.copyFile(
            //Path.Combine(unityProjectDir, "/Assets/Plugins/iDreamsky/msld/Android/lebian/LBApplication.java"),
            //Path.Combine(androidProjPath, "/src/main/java/com/excelliance/open/LBApplication.java")))
            //{
            //    Debug.LogError("MSLD LB copy file error ");
            //}
        }
Ejemplo n.º 4
0
        public static void OnPostProcessBuild(BuildTarget buildTarget, string pathToBuiltProject)
        {
            var dataPath        = Application.dataPath;
            var len             = dataPath.Length - "Assets".Length;
            var unityProjectDir = dataPath.Remove(len);

            MSLDPostProcessConfig config = MSLDPostProcessCommoniOS.ReadMsConfig(unityProjectDir);

            if (config.qq_app_id == null || config.qq_app_id.Length <= 0)
            {
                Debug.LogError("[MSLDPostProcess][iOS][PostProcessControllerIOS]:change controller success.");
                return;
            }

            string[] schemes = new string[]
            {
                "mqqapi",
                "mqq",
                "mqqOpensdkSSoLogin",
                "mqqconnect",
                "mqqopensdkdataline",
                "mqqopensdkgrouptribeshare",
                "mqqopensdkfriend",
                "mqqopensdkapi",
                "mqqopensdkapiV2",
                "mqqopensdkapiV3",
                "mqqopensdkapiV4",
                "mqzoneopensdk",
                "wtloginmqq",
                "wtloginmqq2",
                "mqqwpa",
                "mqzone",
                "mqzonev2",
                "mqzoneshare",
                "wtloginqzone",
                "mqzonewx",
                "mqzoneopensdkapiV2",
                "mqzoneopensdkapi19",
                "mqzoneopensdkapi",
                "mqqbrowser",
                "mttbrowser",
                "tim",
                "timapi",
                "timopensdkfriend",
                "timwpa",
                "timgamebindinggroup",
                "timapiwallet",
                "timOpensdkSSoLogin",
                "wtlogintim",
                "timopensdkgrouptribeshare",
                "timopensdkapiV4",
                "timgamebindinggroup",
                "timopensdkdataline",
                "wtlogintimV1",
                "timapiV1",
            };

            MSLDPostProcessCommoniOS.ChangeInfoPlist(pathToBuiltProject, (PlistDocument doc) => {
                MSLDPostProcessCommoniOS.AddApplicationQueriesSchemes(doc, schemes);

                string qqURLType = "tencent" + config.qq_app_id.Trim();
                MSLDPostProcessCommoniOS.AddURLTypes(doc, "Editor", "tencent", qqURLType);

                return(true);
            });
        }
Ejemplo n.º 5
0
        public static void OnPostProcessBuild(BuildTarget buildTarget, string pathToBuiltProject)
        {
            var    dataPath        = Application.dataPath;
            var    len             = dataPath.Length - "Assets".Length;
            var    unityProjectDir = dataPath.Remove(len);
            string androidProjPath = MSLDPostProcessCommonAndroid.GetProjectPathFromBuild(pathToBuiltProject);

            MSLDPostProcessConfig cfg = MSLDPostProcessCommonAndroid.ReadMsConfig(unityProjectDir);

            if (cfg == null || cfg.qq_app_id == null || cfg.qq_app_id.Length == 0)
            {
                Debug.LogError("[MSLDPostProcessQQAndroid][Android][OnPostProcessBuild]: qq_app_id is not set in msConfig.json");
                return;
            }

            MSLDPostProcessCommonAndroid.ChangeAndroidManifestAndroid(androidProjPath, (XmlDocument xmlDocument, XmlElement appElement, XmlElement activityElement) => {
                XmlElement manifest = (XmlElement)xmlDocument.SelectSingleNode("manifest");
                var android         = manifest.GetAttribute("xmlns:android");

                //添加权限
                MSLDPostProcessCommonAndroid.AddAndroidPermission(xmlDocument, manifest, "android.permission.INTERNET");
                MSLDPostProcessCommonAndroid.AddAndroidPermission(xmlDocument, manifest, "android.permission.ACCESS_NETWORK_STATE");

                //添加 AuthActivity
                var qqAuthActivity = xmlDocument.CreateElement("activity");
                qqAuthActivity.SetAttribute("name", android, "com.tencent.tauth.AuthActivity");
                qqAuthActivity.SetAttribute("launchMode", android, "singleTask");
                qqAuthActivity.SetAttribute("noHistory", android, "true");

                var intent_filte = xmlDocument.CreateElement("intent-filter");
                var action       = xmlDocument.CreateElement("action");
                action.SetAttribute("name", android, "android.intent.action.VIEW");
                intent_filte.AppendChild(action);

                var category = xmlDocument.CreateElement("category");
                category.SetAttribute("name", android, "android.intent.category.DEFAULT");
                intent_filte.AppendChild(category);

                category = xmlDocument.CreateElement("category");
                category.SetAttribute("name", android, "android.intent.category.BROWSABLE");
                intent_filte.AppendChild(category);

                var scheme = xmlDocument.CreateElement("data");
                Debug.Log("Get qq_app_id::" + cfg.qq_app_id);
                scheme.SetAttribute("scheme", android, "tencent" + cfg.qq_app_id);
                intent_filte.AppendChild(scheme);

                qqAuthActivity.AppendChild(intent_filte);
                appElement.AppendChild(qqAuthActivity);

                //添加 AssistActivity
                var qqAssistActivity = xmlDocument.CreateElement("activity");
                qqAssistActivity.SetAttribute("name", android, "com.tencent.connect.common.AssistActivity");
                qqAssistActivity.SetAttribute("configChanges", android, "orientation|keyboardHidden");
                qqAssistActivity.SetAttribute("screenOrientation", android, "behind");
                qqAssistActivity.SetAttribute("theme", android, "@android:style/Theme.Translucent.NoTitleBar");
                appElement.AppendChild(qqAssistActivity);

                return(true);
            });
        }
Ejemplo n.º 6
0
    public static bool PostProcessAndroid(string unityProjectDir, string androidProjectDir)
    {
        // 拷贝配置文件
        string confiFilePath = Path.Combine(unityProjectDir, "Assets/Plugins/iDreamsky/msld/Android/msConfig.json");
        string toPath        = Path.Combine(androidProjectDir, "src/main/assets/msld/config/msConfig.json");

        MSLDPostProcessCommonAndroid.copyFile(confiFilePath, toPath);

        // 修改Manifest
        if (!MSLDPostProcessCommonAndroid.ChangeAndroidManifestAndroid(androidProjectDir, (xmlDocument, appElement, activityElement) => {
            activityElement.SetAttribute("android:name", "com.ms.sdk.plugin.unity.MSLDUnityActivity");

            string namespaceUrl = "";
            if (activityElement.GetAttributeNode("android:name") != null)
            {
                namespaceUrl = activityElement.GetAttributeNode("android:name").NamespaceURI;
            }

            Debug.Log("MSLD post set com.ms.sdk.plugin.unity.MSUnityApplication");
            appElement.SetAttribute("name", namespaceUrl, "com.ms.sdk.plugin.unity.MSUnityApplication");
            appElement.SetAttribute("usesCleartextTraffic", namespaceUrl, "true");


            // 极光一键登录配置
            MSLDPostProcessConfig cfg = MSLDPostProcessCommonAndroid.ReadMsConfig(unityProjectDir);
            Debug.Log("MSLD post jg_app_key:" + cfg.jg_app_key);
            if (cfg.jg_app_key != null && cfg.jg_app_key.Length > 0)
            {
                XmlElement manifest = (XmlElement)xmlDocument.SelectSingleNode("manifest");
                var android = manifest.GetAttribute("xmlns:android");
                XmlElement node = xmlDocument.CreateElement("meta-data");
                node.SetAttribute("name", android, "JPUSH_APPKEY");
                node.SetAttribute("value", android, cfg.jg_app_key);
                appElement.AppendChild(node);

                AddJiGuangActivity(xmlDocument, appElement);
            }

            return(true);
        }))
        {
            return(false);
        }


        // 修改gradle
        if (!ChangeGradleFileAndroid(androidProjectDir))
        {
            return(false);
        }

        // 删除可能重复的资源
        var fileAndroid = Path.Combine(androidProjectDir, "libs/android-support-v4.jar");

        if (File.Exists(fileAndroid))
        {
            Debug.Log("[MSLDPostProcess][Android][ChangeGradleFile]: remove fileAndroid");
            File.Delete(fileAndroid);
        }

        //// 拷贝java文件
        //string javaFilePath = Path.Combine(unityProjectDir, "Assets/Plugins/iDreamsky/msld/Android/java/com/ms");
        //string javaToPath = Path.Combine(androidProjectDir, "src/main/java/com/ms");
        //MSLDPostProcessCommonAndroid.copyDir(javaFilePath, javaToPath);

        return(true);
    }
Ejemplo n.º 7
0
        public static void OnPostProcessBuild(BuildTarget buildTarget, string pathToBuiltProject)
        {
            var    dataPath        = Application.dataPath;
            var    len             = dataPath.Length - "Assets".Length;
            var    unityProjectDir = dataPath.Remove(len);
            string androidProjPath = MSLDPostProcessCommonAndroid.GetProjectPathFromBuild(pathToBuiltProject);

            Debug.Log("MSLDPostProcessWechatAndroid pathToBuiltProject " + androidProjPath);

            MSLDPostProcessConfig cfg = MSLDPostProcessCommonAndroid.ReadMsConfig(unityProjectDir);

            if (cfg == null || cfg.wx_app_id == null || cfg.wx_app_id.Length == 0)
            {
                Debug.LogError("[MSLDPostProcessWechatAndroid][Android][OnPostProcessBuild]: wx_app_id is not set in msConfig.json");
                return;
            }

            //创建WXEntryActivity.java文件
            if (false == CreateWXEntryActivity(androidProjPath))
            {
                Debug.LogError("[MSLDPostProcessWechatAndroid][Android][OnPostProcessBuild]: create wxEntryActivity failure");
                return;
            }

            MSLDPostProcessCommonAndroid.ChangeAndroidManifestAndroid(androidProjPath, (XmlDocument xmlDocument, XmlElement appElement, XmlElement activityElement) => {
                XmlElement manifest = (XmlElement)xmlDocument.SelectSingleNode("manifest");
                var android         = manifest.GetAttribute("xmlns:android");

                //添加权限
                MSLDPostProcessCommonAndroid.AddAndroidPermission(xmlDocument, manifest, "android.permission.INTERNET");
                MSLDPostProcessCommonAndroid.AddAndroidPermission(xmlDocument, manifest, "android.permission.MODIFY_AUDIO_SETTINGS");
                MSLDPostProcessCommonAndroid.AddAndroidPermission(xmlDocument, manifest, "android.permission.WRITE_EXTERNAL_STORAGE");
                MSLDPostProcessCommonAndroid.AddAndroidPermission(xmlDocument, manifest, "android.permission.WRITE_EXTERNAL_STORAGE");
                MSLDPostProcessCommonAndroid.AddAndroidPermission(xmlDocument, manifest, "android.permission.ACCESS_WIFI_STATE");
                MSLDPostProcessCommonAndroid.AddAndroidPermission(xmlDocument, manifest, "android.permission.READ_PHONE_STATE");
                MSLDPostProcessCommonAndroid.AddAndroidPermission(xmlDocument, manifest, "android.permission.ACCESS_NETWORK_STATE");

                // 配置 WXEntryActivity,如果已有,则忽略,未找到,则添加
                string packageName    = PlayerSettings.applicationIdentifier;
                string wxActivityName = packageName + ".wxapi.WXEntryActivity";
                bool foundedActivity  = false;
                var alist             = appElement.SelectNodes("activity");
                foreach (XmlNode tnode in alist)
                {
                    var value = tnode.Attributes.GetNamedItem("name", android).Value;
                    if (value == wxActivityName)
                    {
                        foundedActivity = true;
                    }
                }
                if (foundedActivity == false)
                {
                    var WXEntryActivity = xmlDocument.CreateElement("activity");
                    WXEntryActivity.SetAttribute("name", android, wxActivityName);
                    WXEntryActivity.SetAttribute("label", android, "@string/app_name");
                    WXEntryActivity.SetAttribute("exported", android, "true");
                    WXEntryActivity.SetAttribute("theme", android, "@android:style/Theme.Translucent.NoTitleBar");
                    WXEntryActivity.SetAttribute("launchMode", android, "singleTask");
                    WXEntryActivity.SetAttribute("taskAffinity", android, packageName);
                    appElement.AppendChild(WXEntryActivity);
                }

                return(true);
            });
        }