string CheckUrlType(XmlNode parent, string identifier, string schemeValue) { if (parent == null) { return(" <Url Types> is not configured.\n\n"); } XmlNode urlType = parent.SelectSingleNode("./dict[string = '" + identifier + "']"); if (urlType == null) { return(" Url Type of <weixin> is not configured.\n\n"); } if (!MsdkUtil.XmlMath(urlType, "key", "CFBundleTypeRole", "string", "Editor")) { return(" Url Type of <" + identifier + "> config error.<Role> should be <Editor>.\n\n"); } XmlNode schemeNode = urlType.SelectSingleNode("array/string"); if (schemeNode == null || !schemeNode.InnerText.Equals(schemeValue)) { return(" Url Type of <" + identifier + "> config error. It's <URL Schemes> should be <" + schemeValue + ">.\n\n"); } else { return(""); } }
void CheckProjectProperties() { bool Succeed = false; string filePath = env.PATH_PUGLIN_ANDROID + "/project.properties"; if (!File.Exists(filePath)) { errorMsg.Append(filePath + " isn't exits.\n\n"); return; } Dictionary <string, string> configs = MsdkUtil.ReadConfigs(filePath); foreach (var config in configs) { if (config.Key.IndexOf("android.library.reference") != -1) { if (config.Value.Equals("./MSDKLibrary")) { // 检查成功 Succeed = true; } } } if (!Succeed) { errorMsg.Append("project.properties configuration error. " + "It should have an item like <android.library.reference1=./MSDKLibrary>.\n\n"); } }
static void ShowResult() { CheckConfig window = (CheckConfig)EditorWindow.GetWindow(typeof(CheckConfig)); window.position = new Rect((Screen.currentResolution.width - windowWidth) / 2, (Screen.currentResolution.height - windowHeight) / 2, windowWidth, windowHeight); string title = check.result.platform + "配置检查"; try { if (MsdkUtil.isUnityEarlierThan("5.1")) { PropertyInfo info = window.GetType().GetProperty("title"); info.SetValue(window, title, null); } else { PropertyInfo info = window.GetType().GetProperty("titleContent"); info.SetValue(window, new GUIContent(title), null); } } catch (Exception e) { Debug.LogException(e); } window.Show(); }
private static void EditorCode(string projectPath) { string ocFile = projectPath + "/Classes/UnityAppController.mm"; StreamReader streamReader = new StreamReader(ocFile); string text_all = streamReader.ReadToEnd(); streamReader.Close(); if (string.IsNullOrEmpty(text_all)) { return; } if (text_all.Contains(MsdkNativeCode.IOS_HEADER)) { Debug.LogWarning("You are appending to XCode project, would not modified <Classes/UnityAppController.mm>"); return; } MsdkUtil.WriteBelow(ocFile, MsdkNativeCode.IOS_SRC_HEADER, MsdkNativeCode.IOS_HEADER); MsdkUtil.WriteBelow(ocFile, MsdkNativeCode.IOS_SRC_FINISH, MsdkNativeCode.IOS_XG_REGISTER); MsdkUtil.ReplaceLineBelow(ocFile, MsdkNativeCode.IOS_SRC_OPENURL, "return ", MsdkNativeCode.IOS_HANDLE_URL); MsdkUtil.WriteBelow(ocFile, MsdkNativeCode.IOS_SRC_REGISTER, MsdkNativeCode.IOS_XG_SUCC); MsdkUtil.WriteBelow(ocFile, MsdkNativeCode.IOS_SRC_REGISTER_FAIL, MsdkNativeCode.IOS_XG_FAIL); MsdkUtil.WriteBelow(ocFile, MsdkNativeCode.IOS_SRC_RECEIVE, MsdkNativeCode.IOS_XG_RECEIVE); MsdkUtil.WriteBelow(ocFile, MsdkNativeCode.IOS_SRC_ACTIVE, MsdkNativeCode.IOS_XG_CLEAR + MsdkNativeCode.IOS_BECAME_ACTIVE); }
string getSwitch(XmlNode parent, string key, ref bool moduleSwitch) { try { moduleSwitch = Convert.ToBoolean(MsdkUtil.XmlNextName(parent, "key", key)); return(""); } catch { return(" Get switch of <" + key + "> error. Please check your <info.plist> file.\n\n"); } }
public void Replace(string regex, string newString) { if (!File.Exists(androidConfigPath)) { Debug.LogError("Assets/Plugin/Android/assets/msdkconfig.ini is not exist! Please deploy MSDK first."); } else { MsdkUtil.ReplaceTextWithRegex(androidConfigPath, regex, newString); } }
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); } }
public void ReplaceBelow(string below, string addString) { if (!File.Exists(iosConfigPath)) { Debug.LogError(iosConfigPath + " is not exist!"); } else { MsdkUtil.ReplaceBelow(iosConfigPath, below, addString); } }
private static void EditorMod(string pathToBuiltProject) { Dictionary <string, string> modFileRules = new Dictionary <string, string>() { { ".*/MSDK/MSDK.framework", " \"" + pathToBuiltProject + "/MSDK/MSDK.framework\"," }, { ".*/MSDK/WGPlatformResources.bundle", " \"" + pathToBuiltProject + "/MSDK/WGPlatformResources.bundle\"," }, { ".*/MSDK/MSDKResources.bundle", " \"" + pathToBuiltProject + "/MSDK/MSDKResources.bundle\"," }, { ".*/MSDK/MSDKAdapter.framework", " \"" + pathToBuiltProject + "/MSDK/MSDKAdapter.framework\"," }, { ".*/MSDK/bugly/BuglyBridge.h", " \"" + pathToBuiltProject + "/MSDK/bugly/BuglyBridge.h\"," }, { ".*/MSDK/bugly/libBuglyBridge.a", " \"" + pathToBuiltProject + "/MSDK/bugly/libBuglyBridge.a\"," } }; MsdkUtil.ReplaceTextWithRegex(env.PATH_EDITOR + "/Resources/MSDKXcodeConfig.projmods", modFileRules); }
private static void CopyOtherFiles(string pathToBuiltProject) { if (!MsdkUtil.isUnityEarlierThan("5.0")) { return; } string destDir = pathToBuiltProject + "/MSDK"; if (!Directory.Exists(destDir)) { Directory.CreateDirectory(destDir); } //MsdkUtil.CopyDir(env.PATH_ADAPTER_IOS + "/oc", destDir + "/oc", true); MsdkUtil.CopyDir(env.PATH_BUGLY + "/iOS", destDir + "/bugly", true); }
private void ReplaceManifest(string regex, string newString) { string manifest = env.PATH_PUGLIN_ANDROID + "/AndroidManifest.xml"; string manifestCopy = env.PATH_PUGLIN_ANDROID + "/Copy_AndroidManifest.xml"; if (File.Exists(manifest)) { MsdkUtil.ReplaceTextWithRegex(manifest, regex, newString); } else { Debug.LogError("Assets/Plugin/Android/AndroidManifest.xml is not exits! Please deploy MSDK first."); } if (File.Exists(manifestCopy)) { MsdkUtil.ReplaceTextWithRegex(manifestCopy, regex, newString); } }
string Ck(XmlNode node, string attributes, string value = "", bool recursivity = false) { string result = ""; attributes = "android:" + attributes; string configration = attributes + "=\"" + value + "\""; if (!MsdkUtil.XmlInclue(node, attributes, value, recursivity)) { try { string package = node.Attributes["android:name"].Value; result += package + " lack of configuration \"" + configration + "\".\n\n"; } catch { result += "lack of configuration \"" + configration + "\".\n\n"; } } return(result); }
string CheckXmlMatch(XmlNode parent, string key, string value, string logName = "") { if (MsdkUtil.XmlMath(parent, "key", key, "string", value)) { return(""); } else { if (String.IsNullOrEmpty(logName)) { return(" <" + key + "> should be <" + value + ">.\n\n"); } else { return(" " + logName + " config error. <" + key + "> should be <" + value + ">.\n\n"); } } }
public static void UpdateBaseInfo() { MsdkUtil.ReplaceBelow(iosConfigPath, weixin, " <string>" + DeploySettings.Instance.WxAppId + "</string>"); MsdkUtil.ReplaceBelow(iosConfigPath, tencentopenapi, " <string>tencent" + DeploySettings.Instance.QqAppId + "</string>"); MsdkUtil.ReplaceBelow(iosConfigPath, QQ, " <string>" + DeploySettings.Instance.QqScheme + "</string>"); MsdkUtil.ReplaceBelow(iosConfigPath, QQLaunch, " <string>tencentlaunch" + DeploySettings.Instance.QqAppId + "</string>"); MsdkUtil.ReplaceBelow(iosConfigPath, tencentVideo, " <string>tencentvideo" + DeploySettings.Instance.QqAppId + "</string>"); MsdkUtil.ReplaceBelow(iosConfigPath, offerId, " <string>" + DeploySettings.Instance.IOSOfferId + "</string>"); MsdkUtil.ReplaceBelow(iosConfigPath, qqAppId, " <string>" + DeploySettings.Instance.QqAppId + "</string>"); MsdkUtil.ReplaceBelow(iosConfigPath, wxAppId, " <string>" + DeploySettings.Instance.WxAppId + "</string>"); MsdkUtil.ReplaceBelow(iosConfigPath, msdkKey, " <string>" + DeploySettings.Instance.MsdkKey + "</string>"); }
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", "")); } } }
public static void Deploy() { if (Directory.Exists(env.PATH_TEMP)) { Directory.Delete(env.PATH_TEMP, true); } Directory.CreateDirectory(env.PATH_TEMP); /* 1) MSDKLibrary */ DeployLibrary(); /* 2) assets */ if (!Directory.Exists(env.PATH_PUGLIN_ANDROID + "/assets")) { Directory.CreateDirectory(env.PATH_PUGLIN_ANDROID + "/assets"); } MsdkUtil.CopyDir(DIR_ASSETS, env.PATH_PUGLIN_ANDROID + "/assets", true); /* 3) libs */ MsdkUtil.CopyDir(DIR_LIBS, env.PATH_PUGLIN_ANDROID + "/libs", true); #if UNITY_5 // Editor目录处的jar包不需要到 Android/libs 下 #else MsdkUtil.CopyDir(env.PATH_BUGLY + "/Android/libs", env.PATH_PUGLIN_ANDROID + "/libs", true); #endif /* 4) files */ MsdkUtil.CopyFile(FILE_PROPERTY, env.PATH_PUGLIN_ANDROID + "/project.properties", true); string manifestFile = MsdkUtil.CopyFile(FILE_MANIFEST, env.PATH_PUGLIN_ANDROID + "/AndroidManifest.xml", true); MsdkUtil.ReplaceTextWithRegex(manifestFile, manifestRules); MsdkUtil.ReplaceText(manifestFile, "com.example.wegame", game.BundleId); /* 5) adapter.jar */ GenerateAdapter(); // 更新Config ConfigSettings.Instance.Update(); }
void CheckMsdkConfig() { // 读取配置 string filePath = env.PATH_PUGLIN_ANDROID + "/assets/msdkconfig.ini"; if (!File.Exists(filePath)) { errorMsg.Append(filePath + " isn't exits.\n\n"); return; } Dictionary <string, string> configs = MsdkUtil.ReadConfigs(filePath); // 检查环境及和各模块开开关 GetKey(configs, "MSDK_ENV", ref result.domain); GetKey(configs, "needNotice", ref result.notice); GetKey(configs, "PUSH", ref result.push); GetKey(configs, "SAVE_UPDATE", ref result.update); GetKey(configs, "GRAY_TEST_SWITCH", ref result.grayTest); GetKey(configs, "localLog", ref result.logLevel); GetKey(configs, "STAT_LOG", ref result.statLog); GetKey(configs, "WXTOKEN_REFRESH", ref result.refresh); GetKey(configs, "CLOSE_BUGLY_REPORT", ref result.closeBugly); }
// 1)info.plist void CheckPlist() { // 记录错误信息初始位置 errorBegin = errorMsg.Length; warnningBegin = warnningMsg.Length; string filePath = result.projectPath + "/info.plist"; XmlDocument doc = new XmlDocument(); doc.XmlResolver = null; try { doc.Load(filePath); } catch (Exception e) { Debug.LogException(e); errorMsg.Append(" Load " + filePath + " error!\n"); return; } XmlNode application = doc.SelectSingleNode("/plist/dict"); // 检查环境,开关配置 result.domain = MsdkUtil.XmlNextValue(application, "key", "MSDK_ENV", "string"); if (String.IsNullOrEmpty(result.domain)) { errorMsg.Append(" <MSDK_URL> is null.\n\n"); } errorMsg.Append(getSwitch(application, "MSDK_PUSH_SWITCH", ref result.push) + getSwitch(application, "AutoRefreshToken", ref result.refresh) + getSwitch(application, "NeedNotice", ref result.notice)); // 检查appid等配置 errorMsg.Append(CheckXmlMatch(application, "CHANNEL_DENGTA", "1001") + CheckXmlMatch(application, "MSDK_OfferId", deploySetting.IOSOfferId) + CheckXmlMatch(application, "QQAppID", deploySetting.QqAppId) + CheckXmlMatch(application, "WXAppID", deploySetting.WxAppId) + CheckXmlMatch(application, "MSDKKey", deploySetting.MsdkKey)); string noticeTime = MsdkUtil.XmlNextValue(application, "key", "NoticeTime", "integer"); try { Convert.ToInt32(noticeTime); } catch { errorMsg.Append(" <NoticeTime> configuration error, it must be integer.\n\n"); } // NSAppTransportSecurity XmlNode securityConfig = application.SelectSingleNode("key[. = 'NSAppTransportSecurity']"); if (securityConfig != null && securityConfig.NextSibling != null && "dict".Equals(securityConfig.NextSibling.Name)) { securityConfig = securityConfig.NextSibling; } else { errorMsg.Append(" <NSAppTransportSecurity> must be config.\n\n"); } if (!MsdkUtil.XmlMath(securityConfig, "key", "NSAllowsArbitraryLoads", "true")) { errorMsg.Append(" <NSAllowsArbitraryLoads> must be true.\n\n"); } // LSApplicationQueriesSchemes string[] schemes = { "mqq", "mqqapi", "wtloginmqq2", "mqqopensdkapiV3", "mqqopensdkapiV2", "mqqwpa", "mqqOpensdkSSoLogin", "mqqgamebindinggroup", "mqqopensdkfriend", "mqzone", "weixin", "wechat" }; XmlNode queriesSchemes = application.SelectSingleNode("key[. = 'LSApplicationQueriesSchemes']"); if (queriesSchemes == null || queriesSchemes.NextSibling == null || !"array".Equals(queriesSchemes.NextSibling.Name)) { errorMsg.Append(" <LSApplicationQueriesSchemes> should be config."); } else { queriesSchemes = queriesSchemes.NextSibling; foreach (string scheme in schemes) { XmlNode schemeContent = queriesSchemes.SelectSingleNode("string" + "[. = '" + scheme + "']"); if (schemeContent == null) { errorMsg.Append(" <LSApplicationQueriesSchemes> lack of <" + scheme + ">.\n\n"); } } } // CFBundleURLTypes XmlNode urlTypes = application.SelectSingleNode("key[. = 'CFBundleURLTypes']"); if (urlTypes == null || urlTypes.NextSibling == null || !"array".Equals(urlTypes.NextSibling.Name)) { errorMsg.Append(" <CFBundleURLTypes> must be config.\n\n"); } else { urlTypes = urlTypes.NextSibling; } errorMsg.Append(CheckUrlType(urlTypes, "weixin", deploySetting.WxAppId)); errorMsg.Append(CheckUrlType(urlTypes, "tencentopenapi", "tencent" + deploySetting.QqAppId)); errorMsg.Append(CheckUrlType(urlTypes, "QQ", deploySetting.QqScheme)); errorMsg.Append(CheckUrlType(urlTypes, "QQLaunch", "tencentlaunch" + deploySetting.QqAppId)); errorMsg.Append(CheckUrlType(urlTypes, "tencentvideo", "tencentvideo" + deploySetting.QqAppId)); }
void CheckAndroidManifest() { string filePath = env.PATH_PUGLIN_ANDROID + "/AndroidManifest.xml"; if (!File.Exists(filePath)) { errorMsg.Append(filePath + " isn't exits.\n\n"); return; } CheckPermission(filePath); XmlDocument doc = new XmlDocument(); doc.Load(filePath); XmlNode application = doc.SelectSingleNode("/manifest/application"); XmlNodeList nodes = application.ChildNodes; foreach (XmlNode node in nodes) { if (!node.NodeType.Equals(XmlNodeType.Element)) { continue; } if (MsdkUtil.XmlInclue(node, "android:name", "com.tencent.tauth.AuthActivity")) { errorMsg.Append(Ck(node, "launchMode", "singleTask") + Ck(node, "noHistory", "true") + Ck(node, "name", "android.intent.category.DEFAULT", true) + Ck(node, "name", "android.intent.action.VIEW", true) + Ck(node, "name", "android.intent.category.BROWSABLE", true) + Ck(node, "scheme", "tencent" + deploySetting.QqAppId, true)); } if (MsdkUtil.XmlInclue(node, "android:name", "com.tencent.connect.common.AssistActivity")) { errorMsg.Append(Ck(node, "configChanges", "orientation|screenSize|keyboardHidden") + Ck(node, "screenOrientation", "portrait") + Ck(node, "theme", "@android:style/Theme.Translucent.NoTitleBar")); } if (MsdkUtil.XmlInclue(node, "android:name", deploySetting.BundleId + ".wxapi.WXEntryActivity")) { errorMsg.Append(Ck(node, "excludeFromRecents", "true") + Ck(node, "exported", "true") + Ck(node, "launchMode", "singleTop") + Ck(node, "taskAffinity") + Ck(node, "name", "android.intent.action.VIEW", true) + Ck(node, "name", "android.intent.category.DEFAULT", true) + Ck(node, "scheme", deploySetting.WxAppId, true)); } if (MsdkUtil.XmlInclue(node, "android:name", "com.tencent.msdk.weixin.qrcode.WXQrCodeActivity")) { errorMsg.Append(Ck(node, "excludeFromRecents", "true") + Ck(node, "exported", "true") + Ck(node, "launchMode", "singleTask") + Ck(node, "taskAffinity") + Ck(node, "configChanges", "orientation|screenSize|keyboardHidden") + Ck(node, "theme", "@android:style/Theme.Light.NoTitleBar") + Ck(node, "screenOrientation", "portrait")); } if (MsdkUtil.XmlInclue(node, "android:name", "com.tencent.msdk.webview.WebViewActivity")) { warnningMsg.Append(Ck(node, "process", ":msdk_inner_webview") + Ck(node, "hardwareAccelerated", "true") + Ck(node, "configChanges", "orientation|screenSize|keyboardHidden|navigation|fontScale|locale") + Ck(node, "screenOrientation", "unspecified") + Ck(node, "theme", "@android:style/Theme.NoTitleBar") + Ck(node, "windowSoftInputMode", "stateHidden|adjustResize")); } if (MsdkUtil.XmlInclue(node, "android:name", "com.tencent.msdk.webview.JumpShareActivity")) { warnningMsg.Append(Ck(node, "theme", "@android:style/Theme.Translucent.NoTitleBar")); } if (result.update && MsdkUtil.XmlInclue(node, "android:name", "com.tencent.tmdownloader.TMAssistantDownloadService")) { errorMsg.Append(Ck(node, "exported", "false") + Ck(node, "process", ":TMAssistantDownloadSDKService")); } if (result.push && MsdkUtil.XmlInclue(node, "android:name", "com.tencent.android.tpush.XGPushActivity")) { errorMsg.Append(Ck(node, "exported", "false") + Ck(node, "theme", "@android:style/Theme.Translucent")); } if (MsdkUtil.XmlInclue(node, "android:name", "com.tencent.msdk.SchemeActivity")) { errorMsg.Append(Ck(node, "launchMode", "singleTask") + Ck(node, "name", "android.intent.category.DEFAULT", true) + Ck(node, "name", "android.intent.action.VIEW", true) + Ck(node, "name", "android.intent.category.BROWSABLE", true) + Ck(node, "scheme", "tencentvideo" + deploySetting.QqAppId, true)); } if (result.push && MsdkUtil.XmlInclue(node, "android:name", "com.tencent.android.tpush.XGPushReceiver")) { errorMsg.Append(Ck(node, "process", ":xg_service_v3") + Ck(node, "priority", "0x7fffffff", true) + Ck(node, "name", "com.tencent.android.tpush.action.SDK", true) + Ck(node, "name", "com.tencent.android.tpush.action.INTERNAL_PUSH_MESSAGE", true) + Ck(node, "name", "android.net.conn.CONNECTIVITY_CHANGE", true) + Ck(node, "name", "android.intent.action.USER_PRESENT", true) + Ck(node, "name", "android.bluetooth.adapter.action.STATE_CHANGED", true) + Ck(node, "name", "android.intent.action.ACTION_POWER_CONNECTED", true) + Ck(node, "name", "android.intent.action.ACTION_POWER_DISCONNECTED", true) + Ck(node, "name", "android.intent.action.MEDIA_UNMOUNTED", true) + Ck(node, "name", "android.intent.action.MEDIA_REMOVED", true) + Ck(node, "name", "android.intent.action.MEDIA_CHECKING", true) + Ck(node, "name", "android.intent.action.MEDIA_EJECT", true) + Ck(node, "scheme", "file", true) ); } if (result.push && MsdkUtil.XmlInclue(node, "android:name", "com.tencent.android.tpush.service.XGPushService")) { errorMsg.Append(Ck(node, "exported", "true") + Ck(node, "persistent", "true") + Ck(node, "process", ":xg_service_v3")); } if (result.push && MsdkUtil.XmlInclue(node, "android:name", "com.tencent.android.tpush.rpc.XGRemoteService")) { errorMsg.Append(Ck(node, "name", deploySetting.BundleId + ".PUSH_ACTION", true)); } if (result.push && MsdkUtil.XmlInclue(node, "android:name", "com.tencent.android.tpush.XGPushProvider")) { errorMsg.Append(Ck(node, "authorities", deploySetting.BundleId + ".AUTH_XGPUSH") + Ck(node, "exported", "true", true)); } if (result.push && MsdkUtil.XmlInclue(node, "android:name", "com.tencent.android.tpush.SettingsContentProvider")) { errorMsg.Append(Ck(node, "authorities", deploySetting.BundleId + ".TPUSH_PROVIDER", true) + Ck(node, "exported", "false", true)); } if (result.push && MsdkUtil.XmlInclue(node, "android:name", "com.tencent.mid.api.MidProvider")) { errorMsg.Append(Ck(node, "authorities", deploySetting.BundleId + ".TENCENT.MID.V3", true) + Ck(node, "exported", "true", true)); } if (MsdkUtil.XmlInclue(node, "android:name", "com.tencent.special.httpdns.Cache$ConnectReceiver")) { errorMsg.Append(Ck(node, "label", "NetworkConnection", true) + Ck(node, "name", "android.net.conn.CONNECTIVITY_CHANGE", true) ); } } }
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); } }