콘텐츠로 이동

IPreprocessBuildWithReport로 광고 SDK 환경 설정 자동화

Adiscope 광고 SDK는 매체 id와 secret 값으로 통신한다. 앱은 원빌드로 여러 서버 환경에 접속하는데, 환경별 id·secret이 클라이언트와 광고 매체, API 서버 사이에 맞지 않아 DEV 환경에서 문제가 생겼다. 빌드할 때마다 해당 환경의 설정이 들어가도록 빌드 전처리로 자동화했다.

환경별 설정 파일을 Assets/Adiscope/Setting/<플랫폼>/<환경 이름>.json에 둔다. IPreprocessBuildWithReport를 구현해 빌드 직전에 현재 플랫폼과 환경에 맞는 JSON을 SDK 설정으로 가져오고 AssetDatabase.Refresh()로 반영한다.

using Adiscope;
using UnityEditor;
using UnityEditor.Build;
using UnityEditor.Build.Reporting;
using UnityEngine;
namespace BuildEditor.Editor
{
public class PreprocessBuild : IPreprocessBuildWithReport
{
public int callbackOrder { get { return 0; } }
public void OnPreprocessBuild(BuildReport report)
{
SetAdiscopeBundle();
}
public void SetAdiscopeBundle() //Adiscope Bundle Import 진행.
{
#if UNITY_ANDROID
AndroidAdiscopeBundleImport();
#elif UNITY_IOS
iOSAdiscopeBundleImport();
#endif
}
public void AndroidAdiscopeBundleImport()
{
// AndroidAdiscopeBundleImport 진행.
string androidJsonPath = GetAdiscopeAndroidServiceJsonPath();
bool result = FrameworkSettingsRegister.AdiscopeImportJson(androidJsonPath, string.Empty);
Debug.Log($"Android AdiscopeBundleImport result: {result} path: {androidJsonPath}");
AssetDatabase.Refresh();
}
public string GetAdiscopeAndroidServiceJsonPath()
{
return System.IO.Path.Combine(Application.dataPath, "Adiscope", "Setting", "Android", AppEnvironment.Instance.Value.Name+".json");
}
public void iOSAdiscopeBundleImport()
{
// iOSAdiscopeBundleImport 진행.
string iOSJsonPath = GetAdiscopeiOSServiceJsonPath();
bool result = FrameworkSettingsRegister.AdiscopeImportJson(string.Empty, iOSJsonPath);
Debug.Log($"iOS AdiscopeBundleImport result: {result} path: {iOSJsonPath}");
AssetDatabase.Refresh();
}
public string GetAdiscopeiOSServiceJsonPath()
{
return System.IO.Path.Combine(Application.dataPath, "Adiscope", "Setting", "iOS", AppEnvironment.Instance.Value.Name+".json");
}
}
}

플랫폼 분기는 UNITY_ANDROID/UNITY_IOS 전처리 지시문으로 나눈다.

런타임에는 광고 SDK 매니저 초기화 시점에 환경별 id·secret으로 SDK를 초기화한다.