iOS 如何修复 Ironsource Unity SDK 中的错误
How to fix bug in Ironsource Unity SDK on iOS
我正在使用 Unity 制作移动游戏。
我使用 Ironsource 作为广告中介。我将 SDK 添加到我的项目中并在 Android.
上工作
如果我将构建目标切换到 iOS,我会收到编译器错误..
Assets\IronSource\Editor\IronSourceBuildPostprocessor.cs(53,48): error
CS0619: 'PBXProject.GetUnityTargetName()' is obsolete: 'This function
is deprecated. There are two targets now, call
GetUnityMainTargetGuid() - for app or GetUnityFrameworkTargetGuid() -
for source/plugins to get Guid instead of calling to
TargetGuidByName(GetUnityTargetName()).'
我使用的是 Unity 2019.3.2f1
在 2019.3 之后的任何版本中,该功能已被弃用。
因此,与其等待 ironsource 的修复或答复,我可以通过将已弃用的函数替换为错误中建议的任一函数来自己修复此问题...
但是哪一个?我不知道那个功能是做什么的..
这是来自 ironsource sdk 的整个 class,其中有问题的行是..
该文件名为 IronSourceBuildPostprocessor.cs
我标记了错误的行。
#if UNITY_IOS
using UnityEngine;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEditor.iOS.Xcode;
using System;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Reflection;
namespace IronSource.Editor
{
public class IronSourceBuildPostprocessor
{
[PostProcessBuild]
public static void OnPostprocessBuild (BuildTarget buildTarget, string buildPath)
{
if (buildTarget == BuildTarget.iOS) {
string projectPath = buildPath + "/Unity-iPhone.xcodeproj/project.pbxproj";
string dirpath = Application.dataPath + "/IronSource/Editor/";
string currentNamespace = MethodBase.GetCurrentMethod().DeclaringType.Namespace;
updateProject (buildTarget, projectPath);
if (Directory.Exists (dirpath)) {
//Match the classes that has "Settings" in their name, and don't start with "I"
var files = Directory.GetFiles (dirpath, "*.cs", SearchOption.TopDirectoryOnly).Where (file => Regex.IsMatch (Path.GetFileName (file), "^(?!IAdapter).+Settings.*$"));
//Go over all the adapter settings classes, and call their updateProject method
foreach (string file in files) {
string classname = Path.GetFileNameWithoutExtension (file);
if (!String.IsNullOrEmpty (classname)) {
IAdapterSettings adapter = (IAdapterSettings)Activator.CreateInstance (Type.GetType (currentNamespace + "." + classname));
adapter.updateProject (buildTarget, projectPath);
}
}
}
}
Debug.Log ("IronSource build postprocessor finished");
}
private static void updateProject (BuildTarget buildTarget, string projectPath)
{
Debug.Log ("IronSource - Update project for IronSource");
PBXProject project = new PBXProject ();
project.ReadFromString (File.ReadAllText (projectPath));
string targetId = project.TargetGuidByName (PBXProject.GetUnityTargetName ()); // THIS IS BAD LINE!!!
// Required System Frameworks
project.AddFrameworkToProject (targetId, "AdSupport.framework", false);
project.AddFrameworkToProject (targetId, "AudioToolbox.framework", false);
project.AddFrameworkToProject (targetId, "AVFoundation.framework", false);
project.AddFrameworkToProject (targetId, "CoreGraphics.framework", false);
project.AddFrameworkToProject (targetId, "CoreMedia.framework", false);
project.AddFrameworkToProject (targetId, "CoreTelephony.framework", false);
project.AddFrameworkToProject (targetId, "CoreVideo.framework", false);
project.AddFrameworkToProject (targetId, "CFNetwork.framework", false);
project.AddFrameworkToProject (targetId, "Foundation.framework", false);
project.AddFrameworkToProject (targetId, "MobileCoreServices.framework", false);
project.AddFrameworkToProject (targetId, "QuartzCore.framework", false);
project.AddFrameworkToProject (targetId, "Security.framework", false);
project.AddFrameworkToProject (targetId, "StoreKit.framework", false);
project.AddFrameworkToProject (targetId, "SystemConfiguration.framework", false);
project.AddFrameworkToProject (targetId, "WebKit.framework", false);
project.AddFileToBuild (targetId, project.AddFile ("usr/lib/libz.tbd", "Frameworks/libz.tbd", PBXSourceTree.Sdk));
// Custom Link Flag
project.AddBuildProperty (targetId, "OTHER_LDFLAGS", "-ObjC");
File.WriteAllText (projectPath, project.WriteToString ());
}
}
}
#endif
我在其他插件中遇到了同样的问题,长话短说我已经将其更改为:
PBXProject proj = new PBXProject();
proj.ReadFromFile(projPath);
string target = proj.TargetGuidByName("Unity-iPhone");
所以 ironsource 说要这样做..
#if UNITY_2019_3_OR_NEWER
string targetId = project.GetUnityFrameworkTargetGuid();
#else
string targetId = project.TargetGuidByName(PBXProject.GetUnityTargetName());
#endif
他们还说 "This is Unity's and Apple's bug but you can try this" 这显然完全是胡扯。他们为什么不通过添加这些行来修复他们的 SDK?
我正在使用 Unity 制作移动游戏。 我使用 Ironsource 作为广告中介。我将 SDK 添加到我的项目中并在 Android.
上工作如果我将构建目标切换到 iOS,我会收到编译器错误..
Assets\IronSource\Editor\IronSourceBuildPostprocessor.cs(53,48): error CS0619: 'PBXProject.GetUnityTargetName()' is obsolete: 'This function is deprecated. There are two targets now, call GetUnityMainTargetGuid() - for app or GetUnityFrameworkTargetGuid() - for source/plugins to get Guid instead of calling to TargetGuidByName(GetUnityTargetName()).'
我使用的是 Unity 2019.3.2f1 在 2019.3 之后的任何版本中,该功能已被弃用。
因此,与其等待 ironsource 的修复或答复,我可以通过将已弃用的函数替换为错误中建议的任一函数来自己修复此问题...
但是哪一个?我不知道那个功能是做什么的.. 这是来自 ironsource sdk 的整个 class,其中有问题的行是.. 该文件名为 IronSourceBuildPostprocessor.cs 我标记了错误的行。
#if UNITY_IOS
using UnityEngine;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEditor.iOS.Xcode;
using System;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Reflection;
namespace IronSource.Editor
{
public class IronSourceBuildPostprocessor
{
[PostProcessBuild]
public static void OnPostprocessBuild (BuildTarget buildTarget, string buildPath)
{
if (buildTarget == BuildTarget.iOS) {
string projectPath = buildPath + "/Unity-iPhone.xcodeproj/project.pbxproj";
string dirpath = Application.dataPath + "/IronSource/Editor/";
string currentNamespace = MethodBase.GetCurrentMethod().DeclaringType.Namespace;
updateProject (buildTarget, projectPath);
if (Directory.Exists (dirpath)) {
//Match the classes that has "Settings" in their name, and don't start with "I"
var files = Directory.GetFiles (dirpath, "*.cs", SearchOption.TopDirectoryOnly).Where (file => Regex.IsMatch (Path.GetFileName (file), "^(?!IAdapter).+Settings.*$"));
//Go over all the adapter settings classes, and call their updateProject method
foreach (string file in files) {
string classname = Path.GetFileNameWithoutExtension (file);
if (!String.IsNullOrEmpty (classname)) {
IAdapterSettings adapter = (IAdapterSettings)Activator.CreateInstance (Type.GetType (currentNamespace + "." + classname));
adapter.updateProject (buildTarget, projectPath);
}
}
}
}
Debug.Log ("IronSource build postprocessor finished");
}
private static void updateProject (BuildTarget buildTarget, string projectPath)
{
Debug.Log ("IronSource - Update project for IronSource");
PBXProject project = new PBXProject ();
project.ReadFromString (File.ReadAllText (projectPath));
string targetId = project.TargetGuidByName (PBXProject.GetUnityTargetName ()); // THIS IS BAD LINE!!!
// Required System Frameworks
project.AddFrameworkToProject (targetId, "AdSupport.framework", false);
project.AddFrameworkToProject (targetId, "AudioToolbox.framework", false);
project.AddFrameworkToProject (targetId, "AVFoundation.framework", false);
project.AddFrameworkToProject (targetId, "CoreGraphics.framework", false);
project.AddFrameworkToProject (targetId, "CoreMedia.framework", false);
project.AddFrameworkToProject (targetId, "CoreTelephony.framework", false);
project.AddFrameworkToProject (targetId, "CoreVideo.framework", false);
project.AddFrameworkToProject (targetId, "CFNetwork.framework", false);
project.AddFrameworkToProject (targetId, "Foundation.framework", false);
project.AddFrameworkToProject (targetId, "MobileCoreServices.framework", false);
project.AddFrameworkToProject (targetId, "QuartzCore.framework", false);
project.AddFrameworkToProject (targetId, "Security.framework", false);
project.AddFrameworkToProject (targetId, "StoreKit.framework", false);
project.AddFrameworkToProject (targetId, "SystemConfiguration.framework", false);
project.AddFrameworkToProject (targetId, "WebKit.framework", false);
project.AddFileToBuild (targetId, project.AddFile ("usr/lib/libz.tbd", "Frameworks/libz.tbd", PBXSourceTree.Sdk));
// Custom Link Flag
project.AddBuildProperty (targetId, "OTHER_LDFLAGS", "-ObjC");
File.WriteAllText (projectPath, project.WriteToString ());
}
}
}
#endif
我在其他插件中遇到了同样的问题,长话短说我已经将其更改为:
PBXProject proj = new PBXProject();
proj.ReadFromFile(projPath);
string target = proj.TargetGuidByName("Unity-iPhone");
所以 ironsource 说要这样做..
#if UNITY_2019_3_OR_NEWER
string targetId = project.GetUnityFrameworkTargetGuid();
#else
string targetId = project.TargetGuidByName(PBXProject.GetUnityTargetName());
#endif
他们还说 "This is Unity's and Apple's bug but you can try this" 这显然完全是胡扯。他们为什么不通过添加这些行来修复他们的 SDK?