본문 바로가기
개발

XCode 14 이후 버전에서 Unity Cloud Build의 에러 해결 (ubiquity kvstore identifier Entitlement)

by 디지털옥수수 2023. 4. 24.

기존에는 유니티에서 제시해준 솔루션으로 빌드중이었으나 (Unity Cloud Build Xcode 10 release and build infrastructure changes - Unity Forum)

 

이번에 XCode 14 이상으로 데드라인이 변경되어 버전을 업그레이드 해보니 아래와 같은 오류를 또다시 만나게 되었다.

Provisioning profile doesn't match the entitlements file's value for the com.apple.developer.ubiquity-kvstore-identifier entitlement

 

이 문제 때문에 몇 주간 고생했는데 아래의 해결책으로 정상적으로 앱을 빌드할 수 있었다.

관련 문제를 나만 겪는건가 싶을 정도로 정보를 찾을 수 없어서

혹시라도 나와 같은 문제를 겪고 있는 분들이 있으면 도움이 될까 해서 글을 작성했다.

 

원인은 위 링크에서 말하듯 $(TeamIdentifierPrefix)를 제대로 인식하지 못하는 문제인 것 같고,

기존의 해결책이었던 fastlane gymfile 설정 "UseModernBuildSystem=NO" 도

XCode14부터는 제대로 작동하지 않는 것으로 추측된다.

 

 

1. UCB 빌드 타겟에서 Fastlane Gymfile 설정은 더이상 쓰지 않으므로 비활성화 한다. (기존에 설정했다면)

 

2. 아래 텍스트를 복사하여 "Unity-iPhone.entitlement"로 새 파일을 생성한다. 별표 텍스트 안의 "yourcompany.yourapp"은 본인의 앱에 맞게 직접 값을 변경해야 한다. VV77VOSOFT 값도 더미 값이므로 본인의 팀 ID를 입력해야 한다.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>com.apple.developer.icloud-container-identifiers</key>
	<array>
		<string>★★★iCloud.com.yourcompany.yourapp★★★</string>
	</array>
	<key>com.apple.developer.icloud-services</key>
	<array>
		<string>CloudKit</string>
	</array>
	<key>com.apple.developer.ubiquity-kvstore-identifier</key>
	<string>★★★VV77VOSOFT.com.yourcompany.yourapp★★★</string>
</dict>
</plist>

 

3. Unity-iPhone.entitlement 파일을 유니티 프로젝트에 넣는다.

 

4. 포스트 빌드 프로세스를 통해 "Unity-iPhone.entitlement" 파일을 빌드할 때 XCode 프로젝트에 넘겨준다.

using UnityEngine;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEditor.iOS.Xcode;
using System.Collections;
using System.IO;
using System;

public class EntitlementsPostProcess : ScriptableObject
{
    public DefaultAsset entitlementFile = null;

    [PostProcessBuild(999)] 
    public static void ChangeXcodePlist(BuildTarget buildTarget, string pathToBuiltProject)
    {
        if (buildTarget != BuildTarget.iOS)
            return;

        var dummy = ScriptableObject.CreateInstance<EntitlementsPostProcess>();
        var file = dummy.entitlementFile;
        ScriptableObject.DestroyImmediate(dummy);
        if (file == null)
        {
            return;
        }

        // xproj
        var proj_path = PBXProject.GetPBXProjectPath(pathToBuiltProject);
        var proj = new PBXProject();
        proj.ReadFromFile(proj_path);

        // Copy entitlements
        var target_name = "Unity-iPhone";
        var src = AssetDatabase.GetAssetPath(file);
        var file_name = Path.GetFileName(src);
        var dst = Path.Combine(pathToBuiltProject, target_name, file_name);
        FileUtil.CopyFileOrDirectory(src, dst);
        proj.AddFile(Path.Combine(target_name, file_name), file_name);

        string target_guid = proj.GetUnityMainTargetGuid();
        
        proj.AddBuildProperty(target_guid, "CODE_SIGN_ENTITLEMENTS", target_name + "/" + file_name);

        // End of proj write
        proj.WriteToFile(proj_path);
    }
}

 

5. 스크립트에 Unity-iPhone.entitlements를 연결해준다.

 

6. UCB로 빌드한다.

댓글