@@ -145,6 +145,11 @@ private static void BuildWindowsOS(String path)
145145
146146 private static void BuildWebGL ( String path )
147147 {
148+ // Check if the Unity project is in the expected location
149+ if ( ! IsProjectLocationValid ( path , "web" ) ) {
150+ return ;
151+ }
152+
148153 // Switch to Android standalone build.
149154 EditorUserBuildSettings . SwitchActiveBuildTarget ( BuildTargetGroup . Android , BuildTarget . Android ) ;
150155
@@ -178,6 +183,11 @@ private static void BuildWebGL(String path)
178183
179184 private static void DoBuildAndroid ( String buildPath , bool isPlugin , bool isReleaseBuild )
180185 {
186+ // Check if the Unity project is in the expected location
187+ if ( ! IsProjectLocationValid ( AndroidExportPath , "android" ) ) {
188+ return ;
189+ }
190+
181191 // Switch to Android standalone build.
182192 EditorUserBuildSettings . SwitchActiveBuildTarget ( BuildTargetGroup . Android , BuildTarget . Android ) ;
183193
@@ -359,6 +369,11 @@ private static void ModifyAndroidGradle(bool isPlugin)
359369
360370 private static void BuildIOS ( String path , bool isReleaseBuild )
361371 {
372+ // Check if the Unity project is in the expected location
373+ if ( ! IsProjectLocationValid ( path , "ios" ) ) {
374+ return ;
375+ }
376+
362377 bool abortBuild = false ;
363378
364379 // abort iOS export if #UNITY_IOS is false.
@@ -773,6 +788,21 @@ private static async void BuildUnityFrameworkArchive()
773788
774789 }
775790
791+
792+ // check if the Unity project is in the expected location
793+ private static bool IsProjectLocationValid ( string unityLibraryPath , string platform )
794+ {
795+ // android, ios and web use platform/unityLibrary, move up one step.
796+ string platformPath = Path . Combine ( unityLibraryPath , "../" ) ;
797+ if ( ! Directory . Exists ( platformPath ) )
798+ {
799+ Debug . LogError ( $ "Could not find the Flutter project { platform } folder. Make sure the Unity project folder is located in '<flutter-project>/unity/<unity-project-folder>' .") ;
800+ Debug . Log ( $ "-- Build: Failed --") ;
801+ return false ;
802+ }
803+ return true ;
804+ }
805+
776806 //#endregion
777807 }
778808}
0 commit comments