Search Unity

iOS Cloud Build - error: use of '@import' when modules are disabled

Discussion in 'Unity Build Automation' started by JonBuresh, Jun 4, 2015.

  1. JonBuresh

    JonBuresh

    Joined:
    Feb 21, 2015
    Posts:
    2
    Hi there,

    I've been attempting to produce an iOS build through Unity Cloud Build to no avail. Below is the log.

    I've searched around and it seems as though this error "error: use of '@IMpoRt' when modules are disabled" is thrown because the "Modules (C and Objective-C)" build setting isn't enabled in Xcode - however seeing as I'm using Cloud Build, I do not have access to this setting.

    Is there a way around this?

    Note: I am using the following plugins
    • Google Play Services
    • Google AdMob
     
  2. David-Berger

    David-Berger

    Unity Technologies

    Joined:
    Jul 16, 2014
    Posts:
    745
    Welcome to the forums!

    Can you make sure you updated the plugins to the latest version and try it again? Please let me know if it works then properly.
     
  3. JonBuresh

    JonBuresh

    Joined:
    Feb 21, 2015
    Posts:
    2
    Hi David,

    I went ahead and updated the plugins. I've also updated the project to Unity 5.1.1. I am no longer getting the original error but now I'm getting this:

    ! .xcworkspace file could not be found.

    Code (CSharp):
    1. 22072: [Unity] Refresh: elapses 0.159552 seconds
    2. 22073: [Unity] Refreshing native plugins compatible for Editor in 0.76 ms, found 0 plugins.
    3. 22074: [Unity] ----- Total AssetImport time: 0.137450s, AssetImport time: 0.000000s, Asset hashing: 0.000000s [0 B, 0.000000 mb/s]
    4. 22075: [Unity] Internal: Possible leak. All textures should be removed from IdMap when destructed using RemoveTexture(TextureID texid).
    5. 22076: [Unity] Cleanup mono
    6. 22077: [Unity] Unloading native extension module for target: iOS
    7. 22078: [Unity] Exiting batchmode successfully now!
    8. 22079:        Cleaning up
    9. 22080:  + Building exported player (iOS)
    10. 22081:        Detected Framework: /BUILD_PATH/jonburesh.brutal-badger.default-ios/temp.3U1y49
    11. 22082:        XCode
    12. 22083:  + Envrionment config:
    13. 22084:        LOG_VERBOSE=1
    14. 22085:        Setting CFBundleIdentifier=com.TeamAuroraGames.BrutalBadger
    15. 22086:        Signing with identity 'iPhone Distribution: Team Aurora, LLC (P276RFF7SJ)'
    16. 22087:  + Installing cocoapods:
    17. 22088: ! .xcworkspace file could not be found.
    18. 22089: ! build of 'default-ios' failed. compile failed
    19. 22090: uninstalling jonburesh/brutal-badger - 556b44761be674b37b28ed07.defaultP12
    20. 22091: MAC verified OK
    21. 22092: Removing certificate...
    22. 22093: uninstalling jonburesh/brutal-badger - 556b44761be674b37b28ed07.defaultMobileprovision
    23. 22094: Build step 'Execute shell' marked build as failure
    24. 22095: done.
    25. 22096: postbuildstatus finished successfully.
    26. 22097: Deleting project workspace...
    27. 22098: Finished: FAILURE
    28. Status: FAILED
    Any ideas? Thanks for the assistance thus far :) Full log is available here:

    https://www.dropbox.com/s/j2x61c3odvyvb8g/fullLog.txt?dl=0
     
  4. David-Berger

    David-Berger

    Unity Technologies

    Joined:
    Jul 16, 2014
    Posts:
    745
    Does it work locally properly? If you use the XCode Manipulation API to add the libraries make sure the XCode project work properly after exporting the project locally.
     
  5. Gonzalo Perretti

    Gonzalo Perretti

    Joined:
    Nov 30, 2012
    Posts:
    8
    Hi all.

    I'm having the same issue trying to build an iOS app using the cloud.
    The error is the following:

    Code (CSharp):
    1. 16186: [Unity] Cleanup mono
    2. 16187: [Unity] Unloading native extension module for target: iOS
    3. 16188: [Unity] Exiting batchmode successfully now!
    4. 16189:        Cleaning up
    5. 16190:  + Building exported player (ios)
    6. 16191:        Detected Framework: /BUILD_PATH/xxxxx.default-ios/temp.479vcT
    7. 16192:        XCode
    8. 16193:  + Envrionment config:
    9. 16194:        LOG_VERBOSE=1
    10. 16195:        Setting CFBundleIdentifier=com.xxxxx.xxxxx
    11. 16196:        Signing with identity 'xxxxx'
    12. 16197:  + Installing cocoapods:
    13. 16198: ! .xcworkspace file could not be found.
    14. 16199: ! build of 'default-ios' failed. compile failed
    Thanks in advanced.

    PS: The local build is working perfectly.
     
  6. Gonzalo Perretti

    Gonzalo Perretti

    Joined:
    Nov 30, 2012
    Posts:
    8
    Hi again, more info...
    I can see in the log:
    Code (CSharp):
    1. pod executable not found: /usr/bin/pod
    I don't know if it can be part of the error or not.
     
  7. MrWhoof

    MrWhoof

    Joined:
    Oct 6, 2012
    Posts:
    17
    I have the same issue, building locally works fine though. Has a solution to this been found?
     
  8. unitychrism

    unitychrism

    Joined:
    Sep 16, 2015
    Posts:
    122
    The .xcworkspace errors are related to attempts to use the cocoapods 'pod install' command as part of the build process, which Unity Cloud Build doesn't currently support. The manual method of installing the SDK frameworks should be used instead, followed by adding a post-export method to enable modules and eliminate those @IMpoRt errors you were seeing.

    1. Add the Google Ads resources to the project manually as they existed before.
    2. Below is an example PostBuildProcessor.cs script to post-export manipulate Xcode build settings. This code uses the Xcode Manipulation API to flip the switch for enabling modules. Note: If you already have a post-export method in use, just add the code you see in ProcessPostBuild method that manipulates Xcode project settings.

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEditor;
    3. using UnityEditor.Callbacks;
    4. using System.Collections;
    5. #if UNITY_IOS
    6. using UnityEditor.iOS.Xcode;
    7. #endif
    8. using System.IO;
    9. using System.Linq;
    10.  
    11. public class PostBuildProcessor : MonoBehaviour
    12. {
    13.     /**
    14.      * Runs when Post-Export method has been set to
    15.      * 'PostBuildProcessor.OnPostprocessBuildiOS' in your Unity Cloud Build
    16.      * target settings.
    17.      */
    18.     #if UNITY_CLOUD_BUILD
    19.     // This method is added in the Advanced Features Settings on UCB
    20.     // PostBuildProcessor.OnPostprocessBuildiOS
    21.     public static void OnPostprocessBuildiOS (string exportPath)
    22.     {
    23.         Debug.Log("[UNITY_CLOUD_BUILD] OnPostprocessBuildiOS");
    24.         ProcessPostBuild(BuildTarget.iPhone,exportPath);
    25.     }
    26.     #endif
    27.  
    28.     /**
    29.      * Runs after successful build of an iOS-targetted Unity project
    30.      * via the editor Build dialog.
    31.      */
    32.     [PostProcessBuild]
    33.     public static void OnPostprocessBuild (BuildTarget buildTarget, string path)
    34.     {
    35.         #if !UNITY_CLOUD_BUILD
    36.         Debug.Log ("[LOCAL BUILD] OnPostprocessBuild");
    37.         ProcessPostBuild (buildTarget, path);
    38.         #endif
    39.     }
    40.  
    41.     /**
    42.      * This ProcessPostBuild method will run via Unity Cloud Build, as well as
    43.      * locally when build target is iOS. Using the Xcode Manipulation API, it is
    44.      * possible to modify build settings values and also perform other actions
    45.      * such as adding custom frameworks. Link below is the reference documentation
    46.      * for the Xcode Manipulation API:
    47.      *
    48.      * http://docs.unity3d.com/ScriptReference/iOS.Xcode.PBXProject.html
    49.      */
    50.     private static void ProcessPostBuild (BuildTarget buildTarget, string path)
    51.     {
    52.         // This code will set modules to enabled in Xcode build settings
    53.         #if UNITY_IOS
    54.  
    55.         Debug.Log ("[UNITY_IOS] ProcessPostBuild - Xcode Manipulation API");
    56.  
    57.         // Go get pbxproj file
    58.         string projPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj";
    59.  
    60.         // PBXProject class represents a project build settings file,
    61.         // here is how to read that in.
    62.         PBXProject proj = new PBXProject ();
    63.         proj.ReadFromFile (projPath);
    64.  
    65.         // This is the Xcode target in the generated project
    66.         string target = proj.TargetGuidByName ("Unity-iPhone");
    67.  
    68.         // Here we go: Set 'Enable Modules' to YES to prevent errors using @import syntax
    69.         Debug.Log("Enabling modules: CLANG_ENABLE_MODULES = YES");
    70.         proj.AddBuildProperty(target, "CLANG_ENABLE_MODULES", "YES");
    71.  
    72.         // Write PBXProject object back to the file
    73.         proj.WriteToFile (projPath);
    74.  
    75.         #endif
    76.     }
    77. }
    78.  
    After building locally and opening the generated Xcode project, 'Enabled Modules (C and Objective-C)' should be set to 'YES' appropriately.

    3. On the settings page for your Unity Cloud Build target, add a UNITY_CLOUD_BUILD Scripting Define Symbol and specify the Post-Export Method Name as 'PostBuildProcessor.OnPostprocessBuildiOS'.

    At this point, the project should build successfully without @IMpoRt errors.

    Edit: Added the using directives at the top of the .cs script.
    Edit 2.0: Simplified read/write calls against Xcode manipulation API.
     
    Last edited: Oct 20, 2015
    lexi89puzzle and MechEthan like this.
  9. YBDDevelopment

    YBDDevelopment

    Joined:
    Jul 25, 2015
    Posts:
    3
    Hey,
    I am having the same problem when trying to build for ios:
    2959: + Installing cocoapods:
    2960: ! .xcworkspace file could not be found.
    2961: ! build of 'default-ios' failed. compile failed


    Android build succesfully...
    I added the code unitychrism gave to my project, still not working.
    I dont know if it s relevant but I am using unity ads and the google game service.
    Hope to get help with that:)

    Gonzalo Perretti did you found a solution to this?
    (I added the full log output)
     

    Attached Files:

    Last edited: Oct 24, 2015
  10. Gonzalo Perretti

    Gonzalo Perretti

    Joined:
    Nov 30, 2012
    Posts:
    8
    Hi, yes (I followed the unitychrism advice), I added the framework manually and removed the code that was referencing to cocoa pods in the file "GPGSPostBuild.cs" :

    1. Code (CSharp):
      1.  
      2. /*
      3.             //Copy the podfile into the project.
      4.             string podfile = "Assets/GooglePlayGames/Editor/Podfile.txt";
      5.             string destpodfile = pathToBuiltProject + "/Podfile";
      6.             if (!System.IO.File.Exists(destpodfile))
      7.             {
      8.                 FileUtil.CopyFileOrDirectory(podfile, destpodfile);
      9.             }
      10.             GPGSInstructionWindow w = EditorWindow.GetWindow<GPGSInstructionWindow>(
      11.                 true,
      12.                 "Building for IOS",
      13.                 true);
      14.             w.minSize = new Vector2(400, 300);
      15.             //w.UsingCocoaPod = CocoaPodHelper.Update(pathToBuiltProject);
      16.             */
    Also I'm using my own postprocess script.

    Folder structure and postprocess files are attached. Postprocess files should stay in the Editor folder under Assets.

    I hope this helps.
     

    Attached Files:

  11. Gonzalo Perretti

    Gonzalo Perretti

    Joined:
    Nov 30, 2012
    Posts:
    8
    unitychrism, I fixed the cocoa pods error and now I getting a new error:
    Code (CSharp):
    1.    [xcode] clang: error: linker command failed with exit code 1 (use -v to see invocation)
    2. 8709:        [xcode] Showing first 200 notices only
    3. 8710:        [xcode] Showing first 200 errors only
    4. 8711:        [xcode] ** BUILD FAILED **
    5. 8712:        [xcode] The following build commands failed:
    6. 8713:        [xcode]     Ld build/Unity-iPhone.build/Release-iphoneos/Unity-iPhone.build/Objects-normal/armv7/xxxxxxxxx normal armv7
    7. 8714:        [xcode]     Ld build/Unity-iPhone.build/Release-iphoneos/Unity-iPhone.build/Objects-normal/arm64/xxxxxxxxx normal arm64
    8. 8715:        [xcode] (2 failures)
    9. 8716: ! build of 'unity-iphone' failed. compile failed
    Could you help me with this error?
     
  12. David-Berger

    David-Berger

    Unity Technologies

    Joined:
    Jul 16, 2014
    Posts:
    745
    Do you use the Google Play plugin?
     
  13. Gonzalo Perretti

    Gonzalo Perretti

    Joined:
    Nov 30, 2012
    Posts:
    8
    Yes. I'm using Google Play.
     
  14. David-Berger

    David-Berger

    Unity Technologies

    Joined:
    Jul 16, 2014
    Posts:
    745
    Does it build properly without the plugin? It might be the plugin which does not work properly, in this case it might be worth talking to the plugin devs if they have ideas to resolve the issue.
     
  15. Gonzalo Perretti

    Gonzalo Perretti

    Joined:
    Nov 30, 2012
    Posts:
    8
    The locals builds are working fine and also I can upload the builds to testflight using the Application Loader. But I dont know what is causing the error in the cloud... I cant delete the plugins's code, because its working properly.

    Some other idea?
     
  16. David-Berger

    David-Berger

    Unity Technologies

    Joined:
    Jul 16, 2014
    Posts:
    745
    In the logs you will likely find

    Code (CSharp):
    1. [Unity] ERROR: postExportMethod 'GooglePlayGames.OnPostprocessBuild' failed, aborting.
    which is probably part of the post process part from google play, so something of the plugin which needs to be resolve by the devs of the plugin. If the source is available it might be possible to change that yourself. I'm not entirely sure if this has todo with that they use pod but it might be. Maybe @unitychrism has an idea.
     
  17. Gonzalo Perretti

    Gonzalo Perretti

    Joined:
    Nov 30, 2012
    Posts:
    8
    Nothing about postExport error but I found the following:

    Code (CSharp):
    1. ld: warning: ignoring file /BUILD_PATH/xxxxx-0c66d9b2-fa3a-4b1a-8854-886310e14a90.xxxxx.unity-iphone/temp.oZqjmR/Frameworks/GooglePlay/gpg.framework/gpg, file was built for unsupported file format ( 0x76 0x65 0x72 0x73 0x69 0x6F 0x6E 0x20 0x68 0x74 0x74 0x70 0x73 0x3A 0x2F 0x2F ) which is not the architecture being linked (armv7): /UNITY_PATH/workspace/workspace/workspace/xxxxxx-0c66d9b2-fa3a-4b1a-8854-886310e14a90.xxxxx.unity-iphone/temp.oZqjmR/Frameworks/GooglePlay/gpg.framework/gpg
    2. 5721: [xcode] Undefined symbols for architecture armv7:
     
  18. David-Berger

    David-Berger

    Unity Technologies

    Joined:
    Jul 16, 2014
    Posts:
    745
    Look like a library for armv7 might not link properly, can you make sure the library files (.a) are all checked in properly and available? But on the other side, it looks like it links the wrong library/framework so maybe that's not the issue here.
     
  19. Contract-killer

    Contract-killer

    Joined:
    Sep 21, 2012
    Posts:
    42
    HI I am geting this issue as I have a code which is exploding.
    David - berger, ca n you look into this issue, I face from past 4days
    some linkin g irrort hota
     

    Attached Files:

  20. Contract-killer

    Contract-killer

    Joined:
    Sep 21, 2012
    Posts:
    42
    When I am making xcode build getting them
     
  21. David-Berger

    David-Berger

    Unity Technologies

    Joined:
    Jul 16, 2014
    Posts:
    745
    Hey @Contract-killer, you might wanna reach out to CloudBuild Support they sure can advice :cool: