Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift Project Builds and runs but fails to Archive

I have a xcode project and running on the device, debug build everything is fine.

However when i try to archive the project im getting a segfault from the Swift Compiler:

0  swift                    0x0000000105c36608 llvm::sys::PrintStackTrace(__sFILE*) + 40
1  swift                    0x0000000105c36af4 SignalHandler(int) + 452
2  libsystem_platform.dylib 0x00007fff852705aa _sigtramp + 26
3  libsystem_platform.dylib 0x0000000000000002 _sigtramp + 2061040242
4  swift                    0x0000000105f51896            swift::TypeBase::getTypeOfMember(swift::Module*, swift::ValueDecl const*,    swift::LazyResolver*, swift::Type) + 534
5  swift                    0x00000001050eee38 swift::SILType::getFieldType(swift::VarDecl*, swift::SILModule&) const + 56
6  swift                    0x00000001051a1252 (anonymous namespace)::SILSROA::run() + 3602
7  swift                    0x000000010516b116 swift::SILPassManager::runFunctionPasses(llvm::ArrayRef<swift::SILFunctionTransform*>) + 310
8  swift                    0x000000010516b6f9 swift::SILPassManager::runOneIteration() + 761
9  swift                    0x000000010516b92b swift::SILPassManager::run() + 251
10 swift                    0x000000010516afbc swift::runSILOptimizationPasses(swift::SILModule&, swift::SILOptions const&) + 1644
11 swift                    0x0000000104ffb141 frontend_main(llvm::ArrayRef<char const*>, char const*, void*) + 3537
12 swift                    0x0000000104ffa35d main + 1533
13 libdyld.dylib            0x00007fff885d75fd start + 1
14 libdyld.dylib            0x0000000000000052 start + 2007140950

I have seen people talking about certain synta that can cause this kind of error, but does anyone know how to try and track down which bit(s) of the code is causing the segfault?

like image 717
Jozef Dransfield Avatar asked Jul 02 '14 16:07

Jozef Dransfield


People also ask

Why I can't archive in Xcode?

Archive menu option grayed out If you can't create an archive in Xcode, usually it's because you have the destination set to the simulator. Switch to an iOS device (it should work even if you don't have one connected).

How do I archive in iOS Build?

Navigate to your project's settings. Under iOS (or the target you want to build your app for) > Identity, you'll want to increment the Build number. For example, if the Build number was 1, you'll want to set it to 2. Then, in the top menu, under Product, click on Archive.

How do I archive a project in Swift?

in xcode 10.2 : make your project on Generic ios devices tab and go to product>archive to archive your project after if you want to see all your archived history go to windows>organizer tap .


2 Answers

I had a similar issue and the "solution" was to turn swift compiler code generation optimization level to -Onone in build settings for the release configuration. This is as of Xcode 6.0.1. Turning off swift compiler optimization

like image 175
wfbarksdale Avatar answered Sep 18 '22 09:09

wfbarksdale


before lowering optimization level (which is definitely not a way how to solve compilation problems, unless you're using some pretty neat low level stuff or some specialities).

Simply look what compiler is trying to tell you - yeap. it's not human readable log yet. But you can read, can't you?:)

I got problem like this.

While running pass #1059521 SILFunctionTransform "Constant Propagation" on SILFunction "@_TTSg5VSC29UIApplicationLaunchOptionsKeyS_s8Hashable5UIKit_P__CSo8NSObjectS2_S0_10ObjectiveC_Ps9AnyObject____TFs17_dictionaryUpCastu2_Rxs8Hashable0_S_rFGVs10Dictionaryxq__GS0_q0_q1__".

If you'll look closely at that mess, you will find that you're doing sort of upcasting, that's not allowed.

What does it mean? Look into your function

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?)

and find a place where you cast launchOptions as [NSObject : AnyObject]?

In swift 3 it has changed into [UIApplicationLaunchOptionsKey: Any]?. Remove that cast and update your code that awaits launchOptions as [NSObject : AnyObject]?.

If that helps, just turn on the amazing swift whole module optimization back + in case you don't have a clue what whole module optimization is -> read this article:

https://swift.org/blog/whole-module-optimizations/

like image 28
deathhorse Avatar answered Sep 20 '22 09:09

deathhorse