# Lỗi Undefined symbol khi build iOS

### <span style="white-space: pre-wrap;">Vấn đề </span>

Khi build iOS vẫn thành công. Có file .xcworkspace nhưng khi Archive lại gặp rất nhiều lỗi Undefined symbol như hình dưới.

[![image.png](https://knowledge.thanhdv.com/uploads/images/gallery/2025-12/scaled-1680-/image.png)](https://knowledge.thanhdv.com/uploads/images/gallery/2025-12/image.png)

### Nguyên nhân

Do các thư viện GoogleMobileAds, YandexMobileAds.... chưa được nhúng vào project.

### Giải pháp

#### Thêm thủ công vào .xcworkspace

<span style="white-space: pre-wrap;">Trong của sổ làm việc của XCode chọn project Unity-iPhone &gt; Targets Unity-iPhone &gt; General &gt; </span>**Frameworks, Libraries, and Embedded Content**

Nhấn + để thêm các thư viện còn thiếu. Ở trường hợp trên là GoogleMobileAds.xcframework và YandexMobileAds.xcframework.

[![image.png](https://knowledge.thanhdv.com/uploads/images/gallery/2025-12/scaled-1680-/IMvimage.png)](https://knowledge.thanhdv.com/uploads/images/gallery/2025-12/IMvimage.png)

#### Cách khác (không biết gọi là gì =)))))

Với XCode 26.5 khi thêm thủ công file .xcframework có thể sẽ gặp lỗi sau  
[![image.png](https://knowledge.thanhdv.com/uploads/images/gallery/2026-05/scaled-1680-/jMmimage.png)](https://knowledge.thanhdv.com/uploads/images/gallery/2026-05/jMmimage.png)

Lỗi này xảy ra với file YandexMobileAds.xcframework được tải trên internet.

<span style="white-space: pre-wrap;">Với trường hợp này chúng ta sẽ không thêm thủ công GoogleMobileAds.xcframework và YandexMobileAds.xcframework nữa. Giữ </span>**Frameworks, Libraries, and Embedded Content**<span style="white-space: pre-wrap;"> như ban đầu.</span>

<span style="white-space: pre-wrap;">Trên thanh menu bên trái của Xcode, mở folder Project &gt; Unity-iPhone &gt; Frameworks. </span>  
\- Nếu bạn thấy GoogleMobileAds và YandexMobileAds màu đỏ như hình thì chuột phải &gt; Delete &gt; Remove Reference  
\- Nếu không thì thôi :)))))  
[![image.png](https://knowledge.thanhdv.com/uploads/images/gallery/2026-05/scaled-1680-/gvcimage.png)](https://knowledge.thanhdv.com/uploads/images/gallery/2026-05/gvcimage.png)

Giờ sang phần Target &gt; Build Settings &gt; tìm "Framework Search Paths" &gt; Nháy đúp vào &lt;Multiple value&gt; và thêm 2 dòng lệnh sau  
<span style="white-space: pre-wrap;">- </span>`<span class="editor-theme-code">$(SRCROOT)/Pods/YandexMobileAds</span>`  
<span style="white-space: pre-wrap;">- </span>`<span class="editor-theme-code">$(SRCROOT)/Pods/Google-Mobile-Ads-SDK</span>`  
Đây là biến môi trường tự động trỏ đúng vào thư mục project của bạn.  
<span style="white-space: pre-wrap;">Nhìn sang bên cạnh nếu thấy </span>**non-recursive** thì nhớ chuyển nó thành **recursive.** Để báo cho XCode biết cần phải đi tìm file .xcframework trong các thư mục con.  
[![image.png](https://knowledge.thanhdv.com/uploads/images/gallery/2026-05/scaled-1680-/Ky1image.png)](https://knowledge.thanhdv.com/uploads/images/gallery/2026-05/Ky1image.png)

Tiếp tục, vẫn ở Build Settings, tìm "Other Linker Flags", nháy đúp vào và thêm lần lượt 4 dòng sau vào cuối.  
`<span class="editor-theme-code">-framework</span>`  
`<span class="editor-theme-code">YandexMobileAds</span>`  
`<span class="editor-theme-code">-framework</span>`  
`<span class="editor-theme-code">GoogleMobileAds</span>`  
[![image.png](https://knowledge.thanhdv.com/uploads/images/gallery/2026-05/scaled-1680-/XBcimage.png)](https://knowledge.thanhdv.com/uploads/images/gallery/2026-05/XBcimage.png)

Xong rồi, giờ build thôi :&gt;  
À quên, nhớ Clean Build Folder trước khi build nhé.

### Lưu ý

<span style="white-space: pre-wrap;">Framework được thêm vào nên có màu xanh (hoặc vàng) nhạt. Nếu màu đậm khả năng cao sẽ gặp lỗi </span>

[![image.png](https://knowledge.thanhdv.com/uploads/images/gallery/2025-12/scaled-1680-/9gTimage.png)](https://knowledge.thanhdv.com/uploads/images/gallery/2025-12/9gTimage.png)

<span style="white-space: pre-wrap;">Nếu gặp lỗi như trên có thể chọn </span>**framework từ một dự án khác**<span style="white-space: pre-wrap;"> đã Archive thành công để thêm vào.</span>

Nếu không có dự án cũ thì có thể tìm và tải file .xcframework trừ internet.

- <span style="white-space: pre-wrap;">Với GoogleMobileAds.xcframework có thể tham khảo </span>[link này](https://developers.google.com/admob/ios/download?hl=vi)<span style="white-space: pre-wrap;"> hoặc search google với từ khóa </span>**GoogleMobileAds.xcframework.**
- <span style="white-space: pre-wrap;">Với YandexMobileAds.xcframework có thể tham khảo </span>
    - [Link này](https://github.com/CocoaPods/Specs/tree/master/Specs/a/c/5/YandexMobileAds)<span style="white-space: pre-wrap;"> &gt; tìm phiên bản đang sử dụng &gt; tìm field source.http &gt; sử dụng link này để tải file zip có </span>**YandexMobileAds.xcframework.**  
        [![image.png](https://knowledge.thanhdv.com/uploads/images/gallery/2026-05/scaled-1680-/5dlimage.png)](https://knowledge.thanhdv.com/uploads/images/gallery/2026-05/5dlimage.png)
    - <span style="white-space: pre-wrap;">search google với từ khóa </span>**YandexMobileAds.xcframework.**