SpaceMadness / lunar-unity-console

High-performance Unity iOS/Android logger built with native platform UI
https://www.assetstore.unity3d.com/en/#!/content/43800
Other
833 stars 112 forks source link

iOS: Undefined symbols for architecture arm64 in ___lunar_console_destroy #184

Open fknr opened 3 years ago

fknr commented 3 years ago

We recently updated from 1.6.2 to 1.8.0 and after that we noticed that sometimes our ios builds fail with this error message:

[12:49:42]: ▸ ⚠️ ld: arm64 function not 4-byte aligned: _unwind_tester from /Users/macmini22/jenkins/workspace/tend_Frontend-multibranch_master/frontend/BuildPipeline/builds/ios/Libraries/libiPhone-lib.a(unwind_test_arm64.o) [12:49:44]: ▸ ❌ Undefined symbols for architecture arm64 [12:49:44]: ▸ > Symbol: _lunar_console_destroy [12:49:44]: ▸ > Referenced from: PlatformIOSlunar_console_destroy_mD0698819CB28342B7F21B9CCDC0DF4DBCB3797E4 in LunarConsole.o [12:49:47]: ▸ ❌ ld: symbol(s) not found for architecture arm64 [12:49:47]: ▸ ❌ clang: error: linker command failed with exit code 1 (use -v to see invocation)

The strange thing is that in most in most of the builds it works and also building the same code again fixes the issue. We are on Unity 2019.4.13f1 and build with XCode 12.1 (also happened on 11.3.x before)

weeeBox commented 3 years ago

Hey @fknr, can you check if lunar_unity_native_interface.m file is included in your Xcode project?

hfarrow commented 3 years ago

I experience a similar problem intermittently with both 1.6.1 and 1.8.1. It's relatively rare but it seems that the Xcode project is not modified to include LunarConsole files.

I don't have an example in front of me but going from memory, if you look in Xcode at the LunarConsole folder it's empty. I usually delete the Xcode project, and rebuild from Unity to fix it. I've been meaning to snoop around the build code but haven't had time so far.

weeeBox commented 3 years ago

Yes, I have seen it myself before. Not sure about the best solution at this point. One of the possible ways might be to forcibly update the Xcode project on every build.

idbrii commented 3 years ago

FYI, I had similar errors on LunarConsole 1.8.1 and Unity 2019.4.7 and I did not have lunar_unity_native_interface.m in my Xcode project.

Undefined symbols for architecture arm64:
  "___lunar_console_destroy", referenced from:
      _PlatformIOS___lunar_console_destroy_mD0698819CB28342B7F21B9CCDC0DF4DBCB3797E4 in LunarConsole.o
      _PlatformIOS_Destroy_m9A947243D241014A09E4F7B860D28C161B0B172E in LunarConsole.o
     (maybe you meant: _PlatformIOS___lunar_console_destroy_mD0698819CB28342B7F21B9CCDC0DF4DBCB3797E4)
  "___lunar_console_action_unregister", referenced from:
      _PlatformIOS___lunar_console_action_unregister_mF2271A0C4E29AC18C67D4162405C7986F512B53E in LunarConsole.o
      _PlatformIOS_OnActionUnregistered_mA795A6E80A8B1866AC32AA2809B20D7BF68BDAF0 in LunarConsole.o
     (maybe you meant: _PlatformIOS___lunar_console_action_unregister_mF2271A0C4E29AC18C67D4162405C7986F512B53E)
...
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I didn't have any luck trying to fix it after several attempts of deleting my build output directory, flipping the LUNAR_CONSOLE_EXPORT_IOS_FILES define, and messing with plugin import settings. But then when I reverted all my changes, defined LUNAR_CONSOLE_EXPORT_IOS_FILES, deleted my build output directory again, and restarted Unity it built correctly.

Restarting Unity seems to be the new link in the chain, so maybe if anyone else is encountering this issue, try that.

AntonPetrov83 commented 3 years ago

Hi, I have this issue in my CI setup.

This code is not executed because UNITY_IOS is not defined if the current platform is not the iOS:

#if UNITY_IOS || UNITY_IPHONE
        [PostProcessBuild(1000)]
        static void OnPostprocessBuild(BuildTarget target, string buildPath)
        {
            if (LunarConsoleConfig.consoleEnabled)
            {
                if (target == BuildTarget.iOS)
                {
                    OnPostprocessIOS(buildPath);
                }
            }
        }

When building from a script the current platform is switched when you invoke BuildPipeline.BuildPlayer(). So when you build Android you have your code compiled with Android as the current platform and this code is not there yet. So if you start building iOS next then this code won't execute. It will be executed on the next run after the current platform is switched to iOS.

See this issue: https://issuetracker.unity3d.com/issues/unity-ios-is-defined-and-the-post-processing-code-using-unityeditor-dot-ios-dot-xcode-is-called-only-then-if-ios-is-the-active-platform

In my case it was okay to remove those directives because I am forced to have Android and iOS support installed everywhere.

hfarrow commented 3 years ago

Interesting, I'm pretty sure I have had my active platform set to iOS before running a build, even when building from a script and still ran into this problem. I'll see if that is the case the next time I hit the problem.

Our build script only builds the active target. I'll also add a log statement to trust function so I can see if ran after a failed build.

AntonPetrov83 commented 3 years ago

Interesting, I'm pretty sure I have had my active platform set to iOS before running a build, even when building from a script and still ran into this problem. I'll see if that is the case the next time I hit the problem.

Our build script only builds the active target. I'll also add a log statement to trust function so I can see if ran after a failed build.

I think we can reproduce it in the editor: switch to non-iOS platform in Build Settings then execute an iOS build from the script through MenuItem.

hfarrow commented 3 years ago

It makes sense now. I realized my build script will silently switch to iOS or Android targets if the active target is Standalone.