Skip to content

Commit 256994f

Browse files
committed
Add options to support Swift frameworks
The settings are availabe through iOS Resolver Settings menu or through code. - An option to add "use_frameworks!" in the Podfile. True by default. - An option to link frameworks statically. False by default. - An option to add the main target to Podfile for Unity 2019.3+. True by default. Bug: 174515725 Change-Id: Ieb55a61dc824c6e47428e59b9ff710cb3cde6e4a
1 parent 9627093 commit 256994f

File tree

2 files changed

+131
-3
lines changed

2 files changed

+131
-3
lines changed

source/IOSResolver/src/IOSResolver.cs

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,15 @@ protected override bool Read(string filename, Logger logger) {
455455
// Whether to skip pod install when using workspace integration.
456456
private const string PREFERENCE_SKIP_POD_INSTALL_WHEN_USING_WORKSPACE_INTEGRATION =
457457
PREFERENCE_NAMESPACE + "SkipPodInstallWhenUsingWorkspaceIntegration";
458+
// Whether to add "use_frameworks!" in the Podfile.
459+
private const string PREFERENCE_PODFILE_ADD_USE_FRAMEWORKS =
460+
PREFERENCE_NAMESPACE + "PodfileAddUseFrameworks";
461+
// Whether to statically link framework in the Podfile.
462+
private const string PREFERENCE_PODFILE_STATIC_LINK_FRAMEWORKS =
463+
PREFERENCE_NAMESPACE + "PodfileStaticLinkFrameworks";
464+
// Whether to add an main target to Podfile for Unity 2019.3+.
465+
private const string PREFERENCE_PODFILE_ALWAYS_ADD_MAIN_TARGET =
466+
PREFERENCE_NAMESPACE + "PodfileAlwaysAddMainTarget";
458467
// List of preference keys, used to restore default settings.
459468
private static string[] PREFERENCE_KEYS = new [] {
460469
PREFERENCE_COCOAPODS_INSTALL_ENABLED,
@@ -464,7 +473,10 @@ protected override bool Read(string filename, Logger logger) {
464473
PREFERENCE_POD_TOOL_EXECUTION_VIA_SHELL_ENABLED,
465474
PREFERENCE_AUTO_POD_TOOL_INSTALL_IN_EDITOR,
466475
PREFERENCE_WARN_UPGRADE_WORKSPACE,
467-
PREFERENCE_SKIP_POD_INSTALL_WHEN_USING_WORKSPACE_INTEGRATION
476+
PREFERENCE_SKIP_POD_INSTALL_WHEN_USING_WORKSPACE_INTEGRATION,
477+
PREFERENCE_PODFILE_ADD_USE_FRAMEWORKS,
478+
PREFERENCE_PODFILE_STATIC_LINK_FRAMEWORKS,
479+
PREFERENCE_PODFILE_ALWAYS_ADD_MAIN_TARGET
468480
};
469481

470482
// Whether the xcode extension was successfully loaded.
@@ -765,7 +777,7 @@ public static void SettingsDialog() {
765777
/// version of Unity supports multiple Xcode build targets, for example if Unity supports use
766778
/// as a library or framework.
767779
/// </summary>
768-
private static bool MultipleXcodeTargetsSupported {
780+
internal static bool MultipleXcodeTargetsSupported {
769781
get {
770782
return typeof(UnityEditor.iOS.Xcode.PBXProject).GetMethod(
771783
"GetUnityMainTargetGuid", Type.EmptyTypes) != null;
@@ -929,6 +941,52 @@ public static bool SkipPodInstallWhenUsingWorkspaceIntegration {
929941
value); }
930942
}
931943

944+
/// <summary>
945+
/// Whether to add "use_frameworks!" in the Podfile. True by default.
946+
/// If true, iOS Resolver adds the following line to Podfile.
947+
///
948+
/// use_frameworks!
949+
/// </summary>
950+
public static bool PodfileAddUseFrameworks {
951+
get { return settings.GetBool(PREFERENCE_PODFILE_ADD_USE_FRAMEWORKS,
952+
defaultValue: true); }
953+
set {
954+
settings.SetBool(PREFERENCE_PODFILE_ADD_USE_FRAMEWORKS, value);
955+
}
956+
}
957+
958+
/// <summary>
959+
/// Whether to statically link framework in the Podfile. False by default.
960+
/// If true and PodfileAddUseFrameworks is true, iOS Resolver adds the following line to Podfile.
961+
///
962+
/// use_frameworks! :linkage => :static
963+
/// </summary>
964+
public static bool PodfileStaticLinkFrameworks {
965+
get { return settings.GetBool(PREFERENCE_PODFILE_STATIC_LINK_FRAMEWORKS,
966+
defaultValue: false); }
967+
set {
968+
settings.SetBool(PREFERENCE_PODFILE_STATIC_LINK_FRAMEWORKS, value);
969+
}
970+
}
971+
972+
/// <summary>
973+
/// Whether to add the main target to Podfile for Unity 2019.3+. True by default.
974+
/// If true, iOS Resolver will add the following lines to Podfile, on top of 'UnityFramework'
975+
/// target.
976+
///
977+
/// target 'Unity-iPhone' do
978+
/// end
979+
///
980+
/// This target will empty by default.
981+
/// </summary>
982+
public static bool PodfileAlwaysAddMainTarget {
983+
get { return settings.GetBool(PREFERENCE_PODFILE_ALWAYS_ADD_MAIN_TARGET,
984+
defaultValue: true); }
985+
set {
986+
settings.SetBool(PREFERENCE_PODFILE_ALWAYS_ADD_MAIN_TARGET, value);
987+
}
988+
}
989+
932990
/// <summary>
933991
/// Whether to use project level settings.
934992
/// </summary>
@@ -1939,6 +1997,16 @@ public static void GenPodfile(BuildTarget buildTarget,
19391997
}
19401998
file.WriteLine("end");
19411999
}
2000+
2001+
if (MultipleXcodeTargetsSupported && PodfileAlwaysAddMainTarget) {
2002+
file.WriteLine(String.Format("target '{0}' do", "Unity-iPhone"));
2003+
file.WriteLine("end");
2004+
}
2005+
if (PodfileAddUseFrameworks) {
2006+
file.WriteLine( PodfileStaticLinkFrameworks ?
2007+
"use_frameworks! :linkage => :static" :
2008+
"use_frameworks!");
2009+
}
19422010
}
19432011

19442012
int versionCount = 0;

source/IOSResolver/src/IOSResolverSettingsDialog.cs

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ private class Settings {
3636
internal bool autoPodToolInstallInEditorEnabled;
3737
internal bool verboseLoggingEnabled;
3838
internal int cocoapodsIntegrationMenuIndex;
39+
internal bool podfileAddUseFrameworks;
40+
internal bool podfileStaticLinkFrameworks;
41+
internal bool podfileAlwaysAddMainTarget;
3942
internal bool useProjectSettings;
4043
internal EditorMeasurement.Settings analyticsSettings;
4144

@@ -49,6 +52,9 @@ internal Settings() {
4952
verboseLoggingEnabled = IOSResolver.VerboseLoggingEnabled;
5053
cocoapodsIntegrationMenuIndex = FindIndexFromCocoapodsIntegrationMethod(
5154
IOSResolver.CocoapodsIntegrationMethodPref);
55+
podfileAddUseFrameworks = IOSResolver.PodfileAddUseFrameworks;
56+
podfileStaticLinkFrameworks = IOSResolver.PodfileStaticLinkFrameworks;
57+
podfileAlwaysAddMainTarget = IOSResolver.PodfileAlwaysAddMainTarget;
5258
useProjectSettings = IOSResolver.UseProjectSettings;
5359
analyticsSettings = new EditorMeasurement.Settings(IOSResolver.analytics);
5460
}
@@ -63,6 +69,9 @@ internal void Save() {
6369
IOSResolver.VerboseLoggingEnabled = verboseLoggingEnabled;
6470
IOSResolver.CocoapodsIntegrationMethodPref =
6571
integrationMapping[cocoapodsIntegrationMenuIndex];
72+
IOSResolver.PodfileAddUseFrameworks = podfileAddUseFrameworks;
73+
IOSResolver.PodfileStaticLinkFrameworks = podfileStaticLinkFrameworks;
74+
IOSResolver.PodfileAlwaysAddMainTarget = podfileAlwaysAddMainTarget;
6675
IOSResolver.UseProjectSettings = useProjectSettings;
6776
analyticsSettings.Save();
6877
}
@@ -95,7 +104,7 @@ private static int FindIndexFromCocoapodsIntegrationMethod(
95104
}
96105

97106
public void Initialize() {
98-
minSize = new Vector2(400, 400);
107+
minSize = new Vector2(400, 650);
99108
position = new Rect(UnityEngine.Screen.width / 3, UnityEngine.Screen.height / 3,
100109
minSize.x, minSize.y);
101110
}
@@ -175,6 +184,48 @@ public void OnGUI() {
175184
"Assets > External Dependency Manager > iOS Resolver > Install Cocoapods");
176185
}
177186

187+
if (settings.podfileGenerationEnabled) {
188+
GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.Height(1));
189+
GUILayout.Label("Podfile Configurations", EditorStyles.largeLabel);
190+
EditorGUILayout.Separator();
191+
192+
GUILayout.BeginHorizontal();
193+
GUILayout.Label("Add use_frameworks! to Podfile", EditorStyles.boldLabel);
194+
settings.podfileAddUseFrameworks =
195+
EditorGUILayout.Toggle(settings.podfileAddUseFrameworks);
196+
GUILayout.EndHorizontal();
197+
198+
GUILayout.Label("Add the following line to Podfile. Required if any third-party " +
199+
"Unity packages depends on Swift frameworks.");
200+
if (settings.podfileStaticLinkFrameworks) {
201+
GUILayout.Label(" use_frameworks! :linkage => :static");
202+
} else {
203+
GUILayout.Label(" use_frameworks!");
204+
}
205+
206+
if (settings.podfileAddUseFrameworks) {
207+
GUILayout.BeginHorizontal();
208+
GUILayout.Label("Link frameworks statically", EditorStyles.boldLabel);
209+
settings.podfileStaticLinkFrameworks =
210+
EditorGUILayout.Toggle(settings.podfileStaticLinkFrameworks);
211+
GUILayout.EndHorizontal();
212+
}
213+
214+
if (IOSResolver.MultipleXcodeTargetsSupported) {
215+
GUILayout.BeginHorizontal();
216+
GUILayout.Label("Always add the main target to Podfile", EditorStyles.boldLabel);
217+
settings.podfileAlwaysAddMainTarget =
218+
EditorGUILayout.Toggle(settings.podfileAlwaysAddMainTarget);
219+
GUILayout.EndHorizontal();
220+
221+
GUILayout.Label("Add the following lines to Podfile.");
222+
GUILayout.Label(" target 'Unity-iPhone' do\n" +
223+
" end");
224+
}
225+
226+
GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.Height(1));
227+
}
228+
178229
settings.analyticsSettings.RenderGui();
179230

180231
GUILayout.BeginHorizontal();
@@ -223,6 +274,15 @@ public void OnGUI() {
223274
new KeyValuePair<string, string>(
224275
"cocoapodsIntegrationMethod",
225276
IOSResolver.CocoapodsIntegrationMethodPref.ToString()),
277+
new KeyValuePair<string, string>(
278+
"podfileAddUseFrameworks",
279+
IOSResolver.PodfileAddUseFrameworks.ToString()),
280+
new KeyValuePair<string, string>(
281+
"podfileStaticLinkFrameworks",
282+
IOSResolver.PodfileStaticLinkFrameworks.ToString()),
283+
new KeyValuePair<string, string>(
284+
"podfileAlwaysAddMainTarget",
285+
IOSResolver.PodfileAlwaysAddMainTarget.ToString()),
226286
},
227287
"Settings Save");
228288
settings.Save();

0 commit comments

Comments
 (0)