@@ -205,6 +205,9 @@ public static SortedDictionary<int, List<string>>
205
205
// Name of the project within PODS_DIR that references downloaded Cocoapods.
206
206
private const string PODS_PROJECT_NAME = "Pods" ;
207
207
208
+ // Version of the Cocoapods installation.
209
+ private static string podsVersion = "" ;
210
+
208
211
// Search for a file up to a maximum search depth stopping the
209
212
// depth first search each time the specified file is found.
210
213
private static List < string > FindFile (
@@ -755,9 +758,11 @@ public static void OnPostProcessInstallPods(BuildTarget buildTarget,
755
758
// Require at least version 1.0.0
756
759
CommandLine . Result result ;
757
760
result = RunPodCommand ( "--version" , pathToBuiltProject ) ;
758
- if ( result . exitCode != 0 || result . stdout [ 0 ] == '0' ) {
761
+ if ( result . exitCode == 0 ) podsVersion = result . stdout . Trim ( ) ;
762
+
763
+ if ( result . exitCode != 0 || podsVersion [ 0 ] == '0' ) {
759
764
Log ( "Error running cocoapods. Please ensure you have at least " +
760
- "version 1.0.0. " + COCOAPOD_INSTALL_INSTRUCTIONS + "\n \n " +
765
+ "version 1.0.0. " + COCOAPOD_INSTALL_INSTRUCTIONS + "\n \n " +
761
766
"'" + POD_EXECUTABLE + " --version' returned status: " +
762
767
result . exitCode . ToString ( ) + "\n " +
763
768
"output: " + result . stdout , level : LogLevel . Error ) ;
@@ -770,8 +775,9 @@ public static void OnPostProcessInstallPods(BuildTarget buildTarget,
770
775
// We'll attempt to resolve the error by updating the pod repo -
771
776
// which is a slow operation - and retrying pod installation.
772
777
if ( result . exitCode != 0 ) {
773
- bool updateSucceeded =
774
- RunPodCommand ( "repo update" , pathToBuiltProject ) . exitCode != 0 ;
778
+ CommandLine . Result repoUpdateResult =
779
+ RunPodCommand ( "repo update" , pathToBuiltProject ) ;
780
+ bool repoUpdateSucceeded = repoUpdateResult . exitCode == 0 ;
775
781
776
782
// Second attempt result.
777
783
// This is isolated in case it fails, so we can just report the
@@ -786,14 +792,17 @@ public static void OnPostProcessInstallPods(BuildTarget buildTarget,
786
792
"result in an non-functional Xcode project.\n \n " +
787
793
"After the failure, \" pod repo update\" " +
788
794
"was executed and " +
789
- ( updateSucceeded ? "succeeded. " : "failed. " ) +
795
+ ( repoUpdateSucceeded ? "succeeded. " : "failed. " ) +
790
796
"\" pod install\" was then attempted again, and still " +
791
797
"failed. This may be due to a broken Cocoapods " +
792
798
"installation. See: " +
793
799
"https://guides.cocoapods.org/using/troubleshooting.html " +
794
800
"for potential solutions.\n \n " +
795
- "See the output below for details.\n \n " + result . stdout +
796
- "\n \n " + result . stderr , level : LogLevel . Error ) ;
801
+ "pod install output:\n \n " + result . stdout +
802
+ "\n \n " + result . stderr +
803
+ "\n \n \n " +
804
+ "pod repo update output:\n \n " + repoUpdateResult . stdout +
805
+ "\n \n " + repoUpdateResult . stderr , level : LogLevel . Error ) ;
797
806
return ;
798
807
}
799
808
}
@@ -968,49 +977,68 @@ public static void UpdateProjectDeps(
968
977
// Attempt to read per-file compile / build settings from the Pods
969
978
// project.
970
979
var podsProjectPath = GetProjectPath ( podsDir , PODS_PROJECT_NAME ) ;
971
- var podsProject = new UnityEditor . iOS . Xcode . PBXProject ( ) ;
972
- podsProject . ReadFromString ( File . ReadAllText ( podsProjectPath ) ) ;
973
- foreach ( var directory in Directory . GetDirectories ( podsDir ) ) {
974
- // Each pod will have a top level directory under the pods dir
975
- // named after the pod. Also, some pods have build targets in the
976
- // xcode project where each build target has the same name as the
977
- // pod such that pod Foo is in directory Foo with build target Foo.
978
- // Since we can't read the build targets from the generated Xcode
979
- // project using Unity's API, we scan the Xcode project for targets
980
- // to optionally retrieve build settings for each source file
981
- // the settings can be applied in the target project.
982
- var podTargetName = Path . GetFileName ( directory ) ;
983
- var podTargetGuid = podsProject . TargetGuidByName ( podTargetName ) ;
984
- Log ( String . Format ( "Looking for target: {0} guid: {1}" ,
985
- podTargetName , podTargetGuid ?? "null" ) ,
986
- verbose : true ) ;
987
- if ( podTargetGuid == null ) continue ;
988
- foreach ( var podPathProjectPath in podPathToProjectPaths ) {
989
- var podSourceFileGuid = podsProject . FindFileGuidByRealPath (
990
- podPathProjectPath . Key ) ;
991
- if ( podSourceFileGuid == null ) continue ;
992
- var podSourceFileCompileFlags =
993
- podsProject . GetCompileFlagsForFile ( podTargetGuid ,
994
- podSourceFileGuid ) ;
995
- if ( podSourceFileCompileFlags == null ) {
996
- continue ;
997
- }
998
- var targetSourceFileGuid = project . FindFileGuidByProjectPath (
999
- podPathProjectPath . Value ) ;
1000
- if ( targetSourceFileGuid == null ) {
1001
- Log ( "Unable to find " + podPathProjectPath . Value +
1002
- " in generated project" , level : LogLevel . Warning ) ;
1003
- continue ;
1004
- }
1005
- Log ( String . Format (
1006
- "Setting {0} compile flags to ({1})" ,
1007
- podPathProjectPath . Key ,
1008
- String . Join ( ", " ,
1009
- podSourceFileCompileFlags . ToArray ( ) ) ) ,
980
+ if ( File . Exists ( podsProjectPath ) ) {
981
+ var podsProject = new UnityEditor . iOS . Xcode . PBXProject ( ) ;
982
+ podsProject . ReadFromString ( File . ReadAllText ( podsProjectPath ) ) ;
983
+ foreach ( var directory in Directory . GetDirectories ( podsDir ) ) {
984
+ // Each pod will have a top level directory under the pods dir
985
+ // named after the pod. Also, some pods have build targets in
986
+ // the xcode project where each build target has the same name
987
+ // as the pod such that pod Foo is in directory Foo with build
988
+ // target Foo. Since we can't read the build targets from the
989
+ // generated Xcode project using Unity's API, we scan the Xcode
990
+ // project for targets to optionally retrieve build settings
991
+ // for each source file the settings can be applied in the
992
+ // target project.
993
+ var podTargetName = Path . GetFileName ( directory ) ;
994
+ var podTargetGuid =
995
+ podsProject . TargetGuidByName ( podTargetName ) ;
996
+ Log ( String . Format ( "Looking for target: {0} guid: {1}" ,
997
+ podTargetName , podTargetGuid ?? "null" ) ,
1010
998
verbose : true ) ;
1011
- project . SetCompileFlagsForFile ( target , targetSourceFileGuid ,
1012
- podSourceFileCompileFlags ) ;
999
+ if ( podTargetGuid == null ) continue ;
1000
+ foreach ( var podPathProjectPath in podPathToProjectPaths ) {
1001
+ var podSourceFileGuid = podsProject . FindFileGuidByRealPath (
1002
+ podPathProjectPath . Key ) ;
1003
+ if ( podSourceFileGuid == null ) continue ;
1004
+ var podSourceFileCompileFlags =
1005
+ podsProject . GetCompileFlagsForFile ( podTargetGuid ,
1006
+ podSourceFileGuid ) ;
1007
+ if ( podSourceFileCompileFlags == null ) {
1008
+ continue ;
1009
+ }
1010
+ var targetSourceFileGuid =
1011
+ project . FindFileGuidByProjectPath (
1012
+ podPathProjectPath . Value ) ;
1013
+ if ( targetSourceFileGuid == null ) {
1014
+ Log ( "Unable to find " + podPathProjectPath . Value +
1015
+ " in generated project" , level : LogLevel . Warning ) ;
1016
+ continue ;
1017
+ }
1018
+ Log ( String . Format (
1019
+ "Setting {0} compile flags to ({1})" ,
1020
+ podPathProjectPath . Key ,
1021
+ String . Join ( ", " ,
1022
+ podSourceFileCompileFlags . ToArray ( ) ) ) ,
1023
+ verbose : true ) ;
1024
+ project . SetCompileFlagsForFile (
1025
+ target , targetSourceFileGuid ,
1026
+ podSourceFileCompileFlags ) ;
1027
+ }
1013
1028
}
1029
+ } else if ( File . Exists ( podsProjectPath + ".xml" ) ) {
1030
+ // If neither the Pod pbxproj or pbxproj.xml are present pod
1031
+ // install failed earlier and an error has already been report.
1032
+ Log ( "Old Cocoapods installation detected (version: " +
1033
+ podsVersion + "). Unable to include " +
1034
+ "source pods, your project will not build.\n " +
1035
+ "\n " +
1036
+ "Older versions of the pod tool generate xml format Xcode " +
1037
+ "projects which can not be read by Unity's xcodeapi. To " +
1038
+ "resolve this issue update Cocoapods to at least version " +
1039
+ "1.1.0\n \n " +
1040
+ COCOAPOD_INSTALL_INSTRUCTIONS ,
1041
+ level : LogLevel . Error ) ;
1014
1042
}
1015
1043
1016
1044
File . WriteAllText ( pbxprojPath , project . WriteToString ( ) ) ;
0 commit comments