# Tổng hợp vấn đề với Unity.

Tổng hợp các vấn đề và cách giải quyết gặp phải trong quá trình phát triển game với Unity.

# Build Problems

### Không tăng Bundle Version Code khi build Android

#### Bundle Version Code là gì?

<span style="white-space:pre-wrap;">Bundle Version Code (BVC) là một </span>****số nguyên****<span style="white-space:pre-wrap;"> sử dụng để xác định phiên bản của ứng dụng. Số này </span>****không hiển thị cho người dùng**** nhưng rất quan trọng với Google Play Store và thiết bị Android để quản lý việc cập nhật ứng dụng.

****Khác với** `<strong class="editor-theme-bold editor-theme-code">Version</strong>`**<span style="white-space:pre-wrap;"> (version name) là một string để hiển thị cho người, mô tả về phiên bản ứng dụng.</span>

#### Đặc điểm chính

<span style="white-space:pre-wrap;">Là một </span>****số nguyên****<span style="white-space:pre-wrap;"> (0, 1, 2, 101...) được Unity khuyến nghị nên </span>****nhỏ hơn 100000 để**** [buildApkPerCpuArchitecture](https://docs.unity3d.com/ScriptReference/PlayerSettings.Android-buildApkPerCpuArchitecture.html)<span style="white-space:pre-wrap;"> có thể tạo ra version code hợp lệ.</span>

****Không hiển thị với người dùng.****

****Quan trọng**** cho việc cập nhật.

#### Vì sao cần tăng Bundle Version Code?

Như đã nói ở trên BVC được Google Play Store và Android sử dụng để xác định số phiên bản. Nên không thể cài đè một phiên bản có BVC nhỏ hơn phiên bản hiện tại hoặc trên Google Play Store, Google không chấp nhận việc cập nhật nếu bạn tải lên một phiên bản có BVC nhỏ hơn hoặc bằng phiên bản hiện tại.

#### Quy ước đánh số Bundle Version Code.

<span style="white-space:pre-wrap;">Dựa theo </span>****khuyến nghị của Unity,****<span style="white-space:pre-wrap;"> quy ước </span>****Semantic versioning****<span style="white-space:pre-wrap;"> ta có thể chia BVC thành 3 phần mỗi phần tương ứng với 2 chữ số tương ứng với </span>**`<strong class="editor-theme-bold editor-theme-code">MAJOR.MINOR.PATCH</strong>`**

<span style="white-space:pre-wrap;">Từ đó ta có công thức như sau </span>**`<strong class="editor-theme-bold editor-theme-code">bundleVersionCode = MAJOR*10000 + MINOR*100 + PATCH</strong>`**

#### Giải pháp hạn chế quên tăng Bundle Version Code!

<span style="white-space:pre-wrap;">Viết một script triển khai interface </span>[IPreprocessBuildWithReport](https://docs.unity3d.com/ScriptReference/Build.IPreprocessBuildWithReport.html)<span style="white-space:pre-wrap;"> để tự động tính BVC theo công thức trên.</span>

<span style="white-space:pre-wrap;">Tạo một của sổ Build Tools mới bằng </span>[EditorWindow](https://docs.unity3d.com/ScriptReference/EditorWindow.html)<span style="white-space:pre-wrap;"> để hiển thị các thông tin thường xuyên cần chỉnh sửa như Icon, BVC...</span>

****Hoặc kết hợp cả 2 cách trên.****

# Game Development Problems

Các vấn đề gặp phải trong quá trình phát triển game với Unity

# Các khớp bị cắt khi sử dụng Spine Animation.

#### Vấn đề

- Lỗi bị viền tại các khớp khi dùng spine animation.
- [![image.png](https://knowledge.thanhdv.com/uploads/images/gallery/2025-05/scaled-1680-/hWoimage.png)](https://knowledge.thanhdv.com/uploads/images/gallery/2025-05/hWoimage.png)

#### Lý do

- Do config export file không trùng với config trong Unity.

#### Giải pháp

- Sử dụng color space Gamma. (để trùng với export mặc định của Unity).
- <span style="white-space: pre-wrap;">Đọc thêm tại </span>[spine-unity Assets](https://esotericsoftware.com/spine-unity-assets#Advanced-Premultiplied-vs-Straight-Alpha-Export).

# Không thể using một namespace.

#### Vấn đề

- Không thể sử dụng một namespace dù đã thêm package chính xác và có thể sử dụng ở các flie khác.

#### Trường hợp cụ thể

- SoundsGood by MelenitasDev không thể using UnityEngine.AddressableAssets.

#### Lý do

- <span style="white-space: pre-wrap;">Các scripts được biên dịch thành một Assembly riêng biệt. Nếu namespace không được </span>****Assembly Definition Files (asmdef)****<span style="white-space: pre-wrap;"> tham chiếu thì sẽ không sử dụng được.</span>

#### Giải pháp

- Mở file Assembly Definition Files và thêm tham chiếu đến asmdef cần sử dụng (VD: Unity.Addressables…)[![image.png](https://knowledge.thanhdv.com/uploads/images/gallery/2025-05/scaled-1680-/PFoimage.png)](https://knowledge.thanhdv.com/uploads/images/gallery/2025-05/PFoimage.png)

# Copy một List

#### Vấn đề:

- <span style="white-space: pre-wrap;">Trong C# khi tạo một list mới bằng các </span>`<span class="editor-theme-code">List<T> list = new(otherList)</span>`<span style="white-space: pre-wrap;"> thì các phần tử của </span>`<span class="editor-theme-code">list</span>`<span style="white-space: pre-wrap;"> vẫn được tham chiếu đến các phần tử của </span>`<span class="editor-theme-code">otherList</span>`

#### Nguyên nhân:

- <span style="white-space: pre-wrap;">Trong C# khi sử dụng lệnh </span>`<span class="editor-theme-code">List<T> list = new(otherList)</span>`<span style="white-space: pre-wrap;"> chỉ tạo ra được một shallow copy (copy nông). Các phần tử vẫn được tham chiếu đến một vị trí.</span>

#### Giải pháp

- Tạo ra một deep copy (copy sâu)
    - Sử dụng vòng for duyệt và tạo mới từng phần tử sau đó thêm vào list mới.
    - Sử dụng Linq để tạo phần từ mới
        - `<span class="editor-theme-code">List<T> list = otherList.Select(e => new T()).ToList();</span>`
        - `<span class="editor-theme-code">List<T> list = otherList.ConvertAll(e => new T());</span>`

# Release sai cách khi sử dụng Addressables

#### Vấn đề.

Release sai cách khi sử dụng Addressables

Case 1: Early-Release. Với những assets cần sử dụng nhiều lần. Việc Release ngay khi load xong khiến cho mỗi lần cần sử dụng. Asset sẽ phải load từ ổ cứng lên.

```c#
public async UniTask<ICharacter> CreateCharacter(CharacterSheet.Row characterData)
{
    var handle = Addressables.LoadAssetAsync<GameObject>(characterData.PrefabAddr);
    await handle.Task;

    GameObject characterObj = resolver.Instantiate(handle.Result);

    handle.Release();
    return characterObj.GetComponent<ICharacter>();
}
```

<span style="white-space: pre-wrap;">Case 2: Cache chưa chính xác. Trong trường hơp này handle.Result đã được cache vào Dictionary nhưng handle lại bị release ngay sau đó. Tiềm ẩn vấn đề Value này sẽ được tham chiếu đến một "zombie object" gây ra lỗi </span>`<span class="editor-theme-code">NullReferenceException</span>`<span style="white-space: pre-wrap;"> hoặc </span>`<span class="editor-theme-code">ArgumentNullException</span>`

```c#
private Dictionary<string, GameObject> projectileCaches = new();

public async UniTask<IProjectile> CreateProjectile(ProjectileSheet.Row projectileData)
{
    if (!projectileCaches.TryGetValue(projectileData.Id, out var projectilePrefab))
    {
        var handle = Addressables.LoadAssetAsync<GameObject>(projectileData.PrefabAddr);
        await handle.Task;

        projectileCaches.TryAdd(projectileData.Id, handle.Result);
        projectilePrefab = handle.Result;

        handle.Release();

        DebugExtension.Log("Load from disk!!!", Color.red);
    }

    DebugExtension.Log("Load from cache!!!", Color.green);
    GameObject projectileObj = resolver.Instantiate(projectilePrefab);
    return projectileObj.GetComponent<IProjectile>();
}
```

#### Cơ chế đếm tham chiếu của Addressables

<span style="white-space: pre-wrap;">Addressables không hoạt động theo kiểu bật/tắt đơn giản mà sử dụng một cơ chế thông minh gọi là </span>****Reference Counting.****

Mỗi khi asset được load lên RAM bộ đếm tham chiếu sẽ tăng lên. Và ngược lại mỗi khi release bộ đếm tham chiếu sẽ giảm đi. Asset sẽ chỉ được unload khỏi ram khi ref-count trở về 0.

##### Ví dụ

`<span class="editor-theme-code">A.cs</span>`<span style="white-space: pre-wrap;"> gọi </span>`<span class="editor-theme-code">handleA = LoadAssetAsync(mySprite)</span>`

- `<span class="editor-theme-code">mySprite</span>`<span style="white-space: pre-wrap;"> được load vào RAM.</span>
- Ref-Count = 1

`<span class="editor-theme-code">B.cs</span>`<span style="white-space: pre-wrap;"> gọi </span>`<span class="editor-theme-code">handleA = LoadAssetAsync(mySprite)</span>`

- `<span class="editor-theme-code">mySprite</span>`<span style="white-space: pre-wrap;"> được lấy từ RAM</span>
- Ref-Count = 2

`<span class="editor-theme-code">A.cs</span>`<span style="white-space: pre-wrap;"> gọi </span>`<span class="editor-theme-code">handleA.Release()</span>`

- <span style="white-space: pre-wrap;">Ref-Count = 1 → </span>`<span class="editor-theme-code">mySprite</span>`<span style="white-space: pre-wrap;"> vẫn còn trên RAM</span>

<span style="white-space: pre-wrap;">Lúc này, nếu có </span>`<span class="editor-theme-code">C.cs</span>`<span style="white-space: pre-wrap;"> gọi </span>`<span class="editor-theme-code">handleC = LoadAssetAsync(mySprite)</span>`<span style="white-space: pre-wrap;"> thì </span>

- `<span class="editor-theme-code">mySprite</span>`<span style="white-space: pre-wrap;"> vẫn được lấy từ RAM.</span>
- Ref-Count = 2

<span style="white-space: pre-wrap;">Hoặc nếu </span>`<span class="editor-theme-code">B.cs</span>`<span style="white-space: pre-wrap;"> gọi </span>`<span class="editor-theme-code">handleB.Release()</span>`<span style="white-space: pre-wrap;"> thì </span>

- <span style="white-space: pre-wrap;">Ref-Count = 0. </span>
- `<span class="editor-theme-code">mySprite</span>`<span style="white-space: pre-wrap;"> bị unload khỏi RAM.</span>

<span style="white-space: pre-wrap;">Tiếp theo, nếu có bất kỳ scripts nào gọi gọi </span>`<span class="editor-theme-code">LoadAssetAsync(mySprite)</span>`<span style="white-space: pre-wrap;"> thì </span>`<span class="editor-theme-code">mySprite</span>`<span style="white-space: pre-wrap;"> sẽ được tải lại từ ổ cứng.</span>

#### Giải pháp

Với những object chỉ cần sử dụng một lần. Hoàn toàn có thể release ngay sau khi load.

<span style="white-space: pre-wrap;">Với những object sử dụng nhiều lần. Có thể sử dụng </span>****Addressables.InstantiateAsync()****<span style="white-space: pre-wrap;"> hoặc </span>****cache handle****<span style="white-space: pre-wrap;"> để có thể release khi không còn sử dụng đến nữa.</span>

```c#
// Cache handles
public class ProjectileFactory
{
    private Dictionary<string, AsyncOperationHandle<GameObject>> loadedPrefabs = new();

    public async UniTask PreloadProjectiles(List<ProjectileSheet.Row> allProjectileData)
    {
        foreach (var data in allProjectileData)
        {
            if (!loadedPrefabs.ContainsKey(data.Id))
            {
                var handle = Addressables.LoadAssetAsync<GameObject>(data.PrefabAddr);
                loadedPrefabs.Add(data.Id, handle);
            }
        }

        await UniTask.WhenAll(loadedPrefabs.Values.Select(h => h.AsUniTask()));
    }

    public IProjectile CreateProjectile(string projectileId)
    {
        if (loadedPrefabs.TryGetValue(projectileId, out var handle))
        {
            GameObject projectileObj = resolver.Instantiate(handle.Result);
            return projectileObj.GetComponent<IProjectile>();
        }
        return null;
    }
    
    public void UnloadAll()
    {
        foreach(var handle in loadedPrefabs.Values) Addressables.Release(handle);
        loadedPrefabs.Clear();
    }
}
```

# Release Problems

Vấn đề khi build release dự án Unity

# Build iOS thành công nhưng không có file .xcworkspace

#### Vấn đề

- Khi tích hợp đầy đủ các SDK, cocapods, build iOS trên Unity báo success nhưng không có file .xcworkspace để archive

#### Nguyên nhân

- Do lỗi các mạng quảng cáo không tương thích với phiên bản iOS tối thiểu
- Do các mạng quả cáo không tương thích với Mediation SDK
- ...

#### Giải pháp

1. <span style="white-space: pre-wrap;">Sử dụng terminal cd tới folder build iOS (VD: </span>`<span class="editor-theme-code">cd /Users/admin/Unity/Gang2022/Builds/558/iOS</span>`)
2. <span style="white-space: pre-wrap;">Chạy lệnh </span>`<span class="editor-theme-code">pod install</span>`<span style="white-space: pre-wrap;"> để build lại file .xcworkspace</span>
3. Đọc, kiểm tra lỗi và tiếp tục xử lý
    - <span style="white-space: pre-wrap;">Lỗi </span>`<span class="editor-theme-code">AppLovinMediationGoogleAdapter</span>`<span style="white-space: pre-wrap;"> không tương thích với </span>`<span class="editor-theme-code">Google-Mobile-Ads-SDK</span>`<span style="white-space: pre-wrap;"> =&gt; </span>****Sửa phiên bản** `<strong class="editor-theme-bold editor-theme-code">Google-Mobile-Ads-SDK</strong>` **trong file** `<strong class="editor-theme-bold editor-theme-code">Podfile</strong>`**
    
    ```bash
    [!] CocoaPods could not find compatible versions for pod "Google-Mobile-Ads-SDK":
      In Podfile:
        AppLovinMediationGoogleAdapter (= 12.5.0.0) was resolved to 12.5.0.0, which depends on
          Google-Mobile-Ads-SDK (= 12.5.0)
    
        Google-Mobile-Ads-SDK (~> 11.13.0)
    
    Specs satisfying the `Google-Mobile-Ads-SDK (~> 11.13.0), Google-Mobile-Ads-SDK (= 12.5.0)` dependency were found, but they required a higher minimum deployment target.
    ```
    
    
    - <span style="white-space: pre-wrap;">Lỗi </span>`<span class="editor-theme-code">AppLovinMediationMyTargetAdapter</span>`<span style="white-space: pre-wrap;"> yêu cầu </span>****phiên bản iOS tối thiểu****<span style="white-space: pre-wrap;"> cao hơn =&gt; </span>****trong** `<strong class="editor-theme-bold editor-theme-code">Podfile</strong>` **sửa dòng** `<strong class="editor-theme-bold editor-theme-code">platform :ios, 'iOS_version'</strong>`**<span style="white-space: pre-wrap;"> hoặc</span> ****thay đổi** `<strong class="editor-theme-bold editor-theme-code">Target minimum iOS Version</strong>` **trong Player Settings****
    
    ```bash
    [!] CocoaPods could not find compatible versions for pod "AppLovinMediationMyTargetAdapter":
    
      In Podfile:
        AppLovinMediationMyTargetAdapter (= 5.30.0.0)
    
    
    Specs satisfying the `AppLovinMediationMyTargetAdapter (= 5.30.0.0)` dependency were found, but they required a higher minimum deployment target.
    ```
4. Nếu không còn lỗi và đã có file .xcworkspace thì có thể thực hiện archive trên file .xcworkspace này

#### Lưu ý

- <span style="white-space: pre-wrap;">Dùng lệnh </span>`<span class="editor-theme-code">pod install --repo-update</span>`<span style="white-space: pre-wrap;"> để install đồng thời update tất cả các pod trong </span>`<span class="editor-theme-code">Podfile</span>`
- Dọn dẹp cache

```bash
pod cache clean --all
rm -rf ~/Library/Caches/CocoaPods
rm -rf Pods
rm -f Podfile.lock
```

# Tích hợp FacebookSDK - Open SSL not found

#### Vấn đề

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

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

#### Nguyên nhân

Do chưa cài đặt môi trường SSL và Java

#### Giải pháp

##### OpenSSL not found

1. Download and install OpenSSL.  
    [Win32/Win64 OpenSSL Installer for Windows - Shining Light Productions](http://slproweb.com/products/Win32OpenSSL.html)  
    Win32 OpenSSL v#.#.# (not Light)  
    OR Win64 OpenSSL v#.#.# (not Light)
2. Add the OpenSSL directory to your path.  
    <span style="white-space: pre-wrap;">Go to: </span>`<span class="editor-theme-code">Control Panel</span>`<span style="white-space: pre-wrap;"> → </span>`<span class="editor-theme-code">System</span>`<span style="white-space: pre-wrap;"> → </span>`<span class="editor-theme-code">Advanced system settings</span>`<span style="white-space: pre-wrap;"> → </span>`<span class="editor-theme-code">Environment Variables</span>`  
    <span style="white-space: pre-wrap;">Select the Variable </span>`<span class="editor-theme-code">Path</span>`<span style="white-space: pre-wrap;"> in the “System variables” window and click Edit.</span>
3. <span style="white-space: pre-wrap;">Add the path to your OpenSSL bin folder to the end of the “Variable value” text. e.g. I added </span>`<span class="editor-theme-code">;C:\Program Files\OpenSSL-Win64\bin</span>`<span style="white-space: pre-wrap;"> to the end of the value text.</span>  
    <span style="white-space: pre-wrap;">→ Take note, do not forget to add semi-colon </span>`<span class="editor-theme-code">;</span>`<span style="white-space: pre-wrap;"> before the </span>`<span class="editor-theme-code">C:/</span>`
4. Restart computer.

##### Keytool not found

1. 

# 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.**

# Tích hợp FacebookSDK - Lỗi khi Archive trong XCode

### Vấn đề

Dự án Unity có tích hợp FacebookSDK. Build iOS thành công nhưng khi Archive trong XCode lại gặp lỗi như hình.

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

### Nguyên nhân

Do xung đột phiên bản FacebookSDK trong Unity và trong XCode

Hoặc, do lỗi của phiên bản FacebookSDK

### Giải pháp

Kiểm tra xem phiên bản FacebookSDK trong Unity và trong Podfile (cùng thư mục với file .xcworkspace) có trùng nhau chưa. Nếu chưa hãy update lại FacebookSDK trong Unity rồi build lại.

Nếu đã trùng nhau nhưng vẫn gặp lỗi. Vấn đề khẳ năng cao là do phiên bản FacebookSDK. Tại đây có 2 cách giải quyết:

- <span style="white-space: pre-wrap;">Hạ xuống phiên bản FacebookSDK ổn định hơn. (Trong trường hợp này là </span>**17.0.1**, phiên bản gặp lỗi là **18.0.0**)
- Nếu tính năng bị lỗi là một tính năng mà bạn không sử dụng đến hãy xóa hoặc comment dòng code lỗi đó.
    - Tìm đến dòng code báo lỗi và comment lại trong XCode (vẫn phải thực hiện lại trong các lần build sau, trừ khi update FacebookSDK không gặp lỗi)
    - Trong Unity, FacebookSDK &gt; SDK &gt; Editor &gt; iOS &gt; Swift &gt; Comment các dòng code báo lỗi tương tự như trên (với cách này thì chỉ cần làm một lần)