@@ -480,6 +480,13 @@ protected override bool Read(string filename, Logger logger) {
480
480
// Whether to statically link framework in the Podfile.
481
481
private const string PREFERENCE_PODFILE_STATIC_LINK_FRAMEWORKS =
482
482
PREFERENCE_NAMESPACE + "PodfileStaticLinkFrameworks" ;
483
+ // Whether to add Dummy.swift to the generated Xcode project as a workaround to support pods
484
+ // with Swift Framework.
485
+ private const string PREFERENCE_SWIFT_FRAMEWORK_SUPPORT_WORKAROUND =
486
+ PREFERENCE_NAMESPACE + "SwiftFrameworkSupportWorkaroundEnabled" ;
487
+ // The Swift Language Version (SWIFT_VERSION) to update to the generated Xcode Project.
488
+ private const string PREFERENCE_SWIFT_LANGUAGE_VERSION =
489
+ PREFERENCE_NAMESPACE + "SwiftLanguageVersion" ;
483
490
// Whether to add an main target to Podfile for Unity 2019.3+.
484
491
private const string PREFERENCE_PODFILE_ALWAYS_ADD_MAIN_TARGET =
485
492
PREFERENCE_NAMESPACE + "PodfileAlwaysAddMainTarget" ;
@@ -499,6 +506,8 @@ protected override bool Read(string filename, Logger logger) {
499
506
PREFERENCE_SKIP_POD_INSTALL_WHEN_USING_WORKSPACE_INTEGRATION ,
500
507
PREFERENCE_PODFILE_ADD_USE_FRAMEWORKS ,
501
508
PREFERENCE_PODFILE_STATIC_LINK_FRAMEWORKS ,
509
+ PREFERENCE_SWIFT_FRAMEWORK_SUPPORT_WORKAROUND ,
510
+ PREFERENCE_SWIFT_LANGUAGE_VERSION ,
502
511
PREFERENCE_PODFILE_ALWAYS_ADD_MAIN_TARGET ,
503
512
PREFERENCE_PODFILE_ALLOW_PODS_IN_MULTIPLE_TARGETS
504
513
} ;
@@ -1038,6 +1047,34 @@ public static bool PodfileStaticLinkFrameworks {
1038
1047
}
1039
1048
}
1040
1049
1050
+ /// <summary>
1051
+ /// Ehether to enable Swift Framework support workaround.
1052
+ /// If enabled, iOS Resolver adds a Dummy.swift to the generated Xcode project, and change build
1053
+ // properties in order to properly include Swift Standard Libraries.
1054
+ /// </summary>
1055
+ public static bool SwiftFrameworkSupportWorkaroundEnabled {
1056
+ get { return settings . GetBool ( PREFERENCE_SWIFT_FRAMEWORK_SUPPORT_WORKAROUND ,
1057
+ defaultValue : false ) ; }
1058
+ set {
1059
+ settings . SetBool ( PREFERENCE_SWIFT_FRAMEWORK_SUPPORT_WORKAROUND , value ) ;
1060
+ }
1061
+ }
1062
+
1063
+ /// <summary>
1064
+ /// The value used to set Xcode build property: Swift Language Version (SWIFT_VERSION).
1065
+ /// It is default to "5" but Xcode may add or remove options over time.
1066
+ /// If blank, iOS Resolver will not override the build property.
1067
+ /// Please check the build property "Swift Language Version" options in Xcode project first
1068
+ /// before changing this value.
1069
+ /// </summary>
1070
+ public static string SwiftLanguageVersion {
1071
+ get { return settings . GetString ( PREFERENCE_SWIFT_LANGUAGE_VERSION ,
1072
+ defaultValue : "5.0" ) ; }
1073
+ set {
1074
+ settings . SetString ( PREFERENCE_SWIFT_LANGUAGE_VERSION , value ) ;
1075
+ }
1076
+ }
1077
+
1041
1078
/// <summary>
1042
1079
/// Whether to add the main target to Podfile for Unity 2019.3+. True by default.
1043
1080
/// If true, iOS Resolver will add the following lines to Podfile, on top of 'UnityFramework'
@@ -1838,6 +1875,21 @@ public static void OnPostProcessPatchProject(BuildTarget buildTarget,
1838
1875
PatchProject ( buildTarget , pathToBuiltProject ) ;
1839
1876
}
1840
1877
1878
+ /// <summary>
1879
+ /// Post-processing build step to add dummy swift file
1880
+ /// </summary>
1881
+ [ PostProcessBuildAttribute ( BUILD_ORDER_PATCH_PROJECT ) ]
1882
+ public static void OnPostProcessAddDummySwiftFile ( BuildTarget buildTarget ,
1883
+ string pathToBuiltProject ) {
1884
+ if ( ! InjectDependencies ( ) ||
1885
+ ! PodfileGenerationEnabled ||
1886
+ ! PodfileAddUseFrameworks ||
1887
+ ! SwiftFrameworkSupportWorkaroundEnabled ) {
1888
+ return ;
1889
+ }
1890
+ AddDummySwiftFile ( buildTarget , pathToBuiltProject ) ;
1891
+ }
1892
+
1841
1893
/// <summary>
1842
1894
/// Get Xcode target names using a method that works across all Unity versions.
1843
1895
/// </summary>
@@ -1935,13 +1987,50 @@ internal static void PatchProject(
1935
1987
File . WriteAllText ( pbxprojPath , project . WriteToString ( ) ) ;
1936
1988
}
1937
1989
1990
+ internal static void AddDummySwiftFile (
1991
+ BuildTarget buildTarget , string pathToBuiltProject ) {
1992
+ string pbxprojPath = GetProjectPath ( pathToBuiltProject ) ;
1993
+ var project = new UnityEditor . iOS . Xcode . PBXProject ( ) ;
1994
+ project . ReadFromString ( File . ReadAllText ( pbxprojPath ) ) ;
1995
+
1996
+ string DUMMY_SWIFT_FILE_NAME = "Dummy.swift" ;
1997
+ string DUMMY_SWIFT_FILE_CONTENT =
1998
+ "// Generated by External Dependency Manager for Unity\n " +
1999
+ "import Foundation" ;
2000
+ string dummySwiftPath = Path . Combine ( pathToBuiltProject , DUMMY_SWIFT_FILE_NAME ) ;
2001
+ if ( ! File . Exists ( dummySwiftPath ) ) {
2002
+ File . WriteAllText ( dummySwiftPath , DUMMY_SWIFT_FILE_CONTENT ) ;
2003
+ }
2004
+
2005
+ foreach ( var target in GetXcodeTargetGuids ( project , includeAllTargets : false ) ) {
2006
+ project . AddFileToBuild (
2007
+ target ,
2008
+ project . AddFile ( DUMMY_SWIFT_FILE_NAME ,
2009
+ DUMMY_SWIFT_FILE_NAME ,
2010
+ UnityEditor . iOS . Xcode . PBXSourceTree . Source ) ) ;
2011
+ if ( ! string . IsNullOrEmpty ( SwiftLanguageVersion ) ) {
2012
+ project . SetBuildProperty ( target , "SWIFT_VERSION" , SwiftLanguageVersion ) ;
2013
+ }
2014
+
2015
+ // These build properties are only required for multi-target Xcode project, which is
2016
+ // generated from 2019.3+.
2017
+ if ( MultipleXcodeTargetsSupported ) {
2018
+ project . SetBuildProperty ( target , "CLANG_ENABLE_MODULES" , "YES" ) ;
2019
+ project . SetBuildProperty ( target , "ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES" , "YES" ) ;
2020
+ }
2021
+ }
2022
+
2023
+ File . WriteAllText ( pbxprojPath , project . WriteToString ( ) ) ;
2024
+ }
2025
+
1938
2026
/// <summary>
1939
2027
/// Post-processing build step to generate the podfile for ios.
1940
2028
/// </summary>
1941
2029
[ PostProcessBuildAttribute ( BUILD_ORDER_GEN_PODFILE ) ]
1942
2030
public static void OnPostProcessGenPodfile ( BuildTarget buildTarget ,
1943
2031
string pathToBuiltProject ) {
1944
2032
if ( ! InjectDependencies ( ) || ! PodfileGenerationEnabled ) return ;
2033
+ Log ( "OnPostProcessGenPodfile!" , level : LogLevel . Error ) ;
1945
2034
GenPodfile ( buildTarget , pathToBuiltProject ) ;
1946
2035
}
1947
2036
0 commit comments