//[PostProcessBuild(1900)] 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); // 拷贝文件 string idsJavalPath = Path.Combine(unityProjectDir, "AndroidSdk/JavaFiles/com/idreamsky/sdkproxy/SdkProxyActivity.java"); string idsJAVAToPath = Path.Combine(androidProjPath, "src/main/java/com/idreamsky/sdkproxy/SdkProxyActivity.java"); MSLDPostProcessCommonAndroid.copyFile(idsJavalPath, idsJAVAToPath); // 拷贝文件 string idsJavaNativePath = Path.Combine(unityProjectDir, "AndroidSdk/JavaFiles/com/idreamsky/sdkproxy/NativeProxy.java"); string idsJAVANativeToPath = Path.Combine(androidProjPath, "src/main/java/com/idreamsky/sdkproxy/NativeProxy.java"); MSLDPostProcessCommonAndroid.copyFile(idsJavaNativePath, idsJAVANativeToPath); // 配置proxy的activity。与其他Activity同步 MSLDPostProcessCommonAndroid.ChangeAndroidManifestAndroid(androidProjPath, (XmlDocument xmlDocument, XmlElement appElement, XmlElement activityElement) => { activityElement.SetAttribute("android:name", "com.idreamsky.sdkproxy.SdkProxyActivity"); return(true); }); //配置头条 MSLDPostProcessCommonAndroid.ChangeAndroidManifestAndroid(androidProjPath, (XmlDocument xmlDocument, XmlElement appElement, XmlElement activityElement) => { string namespaceUrl = ""; if (activityElement.GetAttributeNode("android:name") != null) { namespaceUrl = activityElement.GetAttributeNode("android:name").NamespaceURI; } var meta_data = xmlDocument.CreateElement("meta-data"); meta_data.SetAttribute("name", namespaceUrl, "toutiao.appId"); meta_data.SetAttribute("value", namespaceUrl, "166509"); activityElement.AppendChild(meta_data); meta_data = xmlDocument.CreateElement("meta-data"); meta_data.SetAttribute("name", namespaceUrl, "toutiao.appName"); meta_data.SetAttribute("value", namespaceUrl, "梦工厂大冒险"); activityElement.AppendChild(meta_data); meta_data = xmlDocument.CreateElement("meta-data"); meta_data.SetAttribute("name", namespaceUrl, "toutiao.channelId"); meta_data.SetAttribute("value", namespaceUrl, "MBGDWJR001"); activityElement.AppendChild(meta_data); return(true); }); }
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); }); }
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 "); //} }
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); }); }