com.usercentrics.sdk 0.0.0-stage → 2.36.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Documentation/LICENSE +2 -0
- package/Documentation/LICENSE.meta +7 -0
- package/Documentation/README +169 -0
- package/Documentation/README.meta +7 -0
- package/Documentation.meta +8 -0
- package/Editor/ATTLocalizationMessageDrawer.cs +92 -0
- package/Editor/ATTLocalizationMessageDrawer.cs.meta +11 -0
- package/Editor/AssemblyInfo.cs +4 -0
- package/Editor/AssemblyInfo.cs.meta +11 -0
- package/Editor/Unity.UsercentricsEditor.asmdef +18 -0
- package/Editor/Unity.UsercentricsEditor.asmdef.meta +7 -0
- package/Editor/UsercentricsATTPostProcessor.cs +125 -0
- package/Editor/UsercentricsATTPostProcessor.cs.meta +11 -0
- package/Editor/UsercentricsAndroidPostBuild.cs +45 -0
- package/Editor/UsercentricsAndroidPostBuild.cs.meta +11 -0
- package/Editor/UsercentricsAndroidSdkCheck.cs +29 -0
- package/Editor/UsercentricsAndroidSdkCheck.cs.meta +11 -0
- package/Editor/UsercentricsDependencies.xml +18 -0
- package/Editor/UsercentricsDependencies.xml.meta +7 -0
- package/Editor/UsercentricsExternalDependencyManagerBuildCheck.cs +56 -0
- package/Editor/UsercentricsExternalDependencyManagerBuildCheck.cs.meta +11 -0
- package/Editor/UsercentricsExternalDependencyManagerCheck.cs +34 -0
- package/Editor/UsercentricsExternalDependencyManagerCheck.cs.meta +11 -0
- package/Editor/UsercentricsIOSBuildFixes.cs +171 -0
- package/Editor/UsercentricsIOSBuildFixes.cs.meta +11 -0
- package/Editor/UsercentricsPBXProjectExtensions.cs +281 -0
- package/Editor/UsercentricsPBXProjectExtensions.cs.meta +11 -0
- package/Editor/UsercentricsPodfilePatches.cs +116 -0
- package/Editor/UsercentricsPodfilePatches.cs.meta +11 -0
- package/Editor/UsercentricsSentryExcludePostBuild.cs +77 -0
- package/Editor/UsercentricsSentryExcludePostBuild.cs.meta +11 -0
- package/Editor/UsercentricsSentryGradleExclude.cs +189 -0
- package/Editor/UsercentricsSentryGradleExclude.cs.meta +11 -0
- package/Editor/UsercentricsWelcomeDialog.cs +76 -0
- package/Editor/UsercentricsWelcomeDialog.cs.meta +11 -0
- package/Editor.meta +8 -0
- package/Prefabs/ATTManager.prefab +47 -0
- package/Prefabs/ATTManager.prefab.meta +7 -0
- package/Prefabs/Usercentrics.prefab +74 -0
- package/Prefabs/Usercentrics.prefab.meta +7 -0
- package/Prefabs.meta +8 -0
- package/Scripts/AppTrackingTransparency/AppTrackingTransparencyManager.cs +59 -0
- package/Scripts/AppTrackingTransparency/AppTrackingTransparencyManager.cs.meta +11 -0
- package/Scripts/AppTrackingTransparency/Model/ATTLocalizationMessage.cs +15 -0
- package/Scripts/AppTrackingTransparency/Model/ATTLocalizationMessage.cs.meta +11 -0
- package/Scripts/AppTrackingTransparency/Model/AuthorizationStatus.cs +10 -0
- package/Scripts/AppTrackingTransparency/Model/AuthorizationStatus.cs.meta +11 -0
- package/Scripts/AppTrackingTransparency/Model/Language.cs +136 -0
- package/Scripts/AppTrackingTransparency/Model/Language.cs.meta +11 -0
- package/Scripts/AppTrackingTransparency/Model.meta +8 -0
- package/Scripts/AppTrackingTransparency.cs +60 -0
- package/Scripts/AppTrackingTransparency.cs.meta +11 -0
- package/Scripts/AppTrackingTransparency.meta +8 -0
- package/Scripts/Internal/AssemblyInfo.cs +3 -0
- package/Scripts/Internal/AssemblyInfo.cs.meta +11 -0
- package/Scripts/Internal/AutoInitialize.cs +42 -0
- package/Scripts/Internal/AutoInitialize.cs.meta +11 -0
- package/Scripts/Internal/BannerSettings.cs +165 -0
- package/Scripts/Internal/BannerSettings.cs.meta +11 -0
- package/Scripts/Internal/ConsentUpdateSubscriptionCoordinator.cs +42 -0
- package/Scripts/Internal/ConsentUpdateSubscriptionCoordinator.cs.meta +11 -0
- package/Scripts/Internal/Data.cs +960 -0
- package/Scripts/Internal/Data.cs.meta +11 -0
- package/Scripts/Internal/Errors.cs +22 -0
- package/Scripts/Internal/Errors.cs.meta +11 -0
- package/Scripts/Internal/FirstLayerStyleSettings.cs +248 -0
- package/Scripts/Internal/FirstLayerStyleSettings.cs.meta +11 -0
- package/Scripts/Internal/IUsercentrics.cs +45 -0
- package/Scripts/Internal/IUsercentrics.cs.meta +11 -0
- package/Scripts/Internal/InspectorLink.cs +27 -0
- package/Scripts/Internal/InspectorLink.cs.meta +11 -0
- package/Scripts/Internal/Singleton.cs +68 -0
- package/Scripts/Internal/Singleton.cs.meta +11 -0
- package/Scripts/Internal/StringParser.cs +41 -0
- package/Scripts/Internal/StringParser.cs.meta +11 -0
- package/Scripts/Internal/UCConstants.cs +13 -0
- package/Scripts/Internal/UCConstants.cs.meta +11 -0
- package/Scripts/Internal/UnityConsentModeAdapter.cs +78 -0
- package/Scripts/Internal/UnityConsentModeAdapter.cs.meta +11 -0
- package/Scripts/Internal/UsercentricsAndroid.cs +210 -0
- package/Scripts/Internal/UsercentricsAndroid.cs.meta +11 -0
- package/Scripts/Internal/UsercentricsIOS.cs +307 -0
- package/Scripts/Internal/UsercentricsIOS.cs.meta +11 -0
- package/Scripts/Internal.meta +8 -0
- package/Scripts/Unity.Usercentrics.asmdef +14 -0
- package/Scripts/Unity.Usercentrics.asmdef.meta +7 -0
- package/Scripts/Usercentrics.cs +1160 -0
- package/Scripts/Usercentrics.cs.meta +11 -0
- package/Scripts.meta +8 -0
- package/UsercentricsInstallGuard/Usercentrics.InstallGuard.asmdef +16 -0
- package/UsercentricsInstallGuard/Usercentrics.InstallGuard.asmdef.meta +7 -0
- package/UsercentricsInstallGuard/UsercentricsInstallGuard.cs +82 -0
- package/UsercentricsInstallGuard/UsercentricsInstallGuard.cs.meta +11 -0
- package/UsercentricsInstallGuard.meta +8 -0
- package/iOS/TrackingTransparencyManager.h +13 -0
- package/iOS/TrackingTransparencyManager.h.meta +27 -0
- package/iOS/TrackingTransparencyManager.mm +99 -0
- package/iOS/TrackingTransparencyManager.mm.meta +37 -0
- package/iOS/Usercentrics.mm +228 -0
- package/iOS/Usercentrics.mm.meta +37 -0
- package/iOS/UsercentricsATTManager.mm +21 -0
- package/iOS/UsercentricsATTManager.mm.meta +37 -0
- package/iOS.meta +8 -0
- package/link.xml +24 -0
- package/link.xml.meta +7 -0
- package/package.json +10 -4
- package/package.json.meta +7 -0
- package/README.md +0 -3
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
using System;
|
|
2
|
+
using System.Collections.Generic;
|
|
3
|
+
using UnityEditor;
|
|
4
|
+
using UnityEditor.Build;
|
|
5
|
+
using UnityEditor.Build.Reporting;
|
|
6
|
+
using UnityEngine;
|
|
7
|
+
|
|
8
|
+
namespace Unity.Usercentrics.Editor
|
|
9
|
+
{
|
|
10
|
+
// Warns at build time when the External Dependency Manager (EDM4U) is missing for the platform being built. Without it the
|
|
11
|
+
// native Usercentrics dependencies are not resolved: the build succeeds, but the app has no Usercentrics classes and fails at runtime.
|
|
12
|
+
// Only a warning: the dependencies can be wired in another way (for example added by hand), and a false failure would block a customer.
|
|
13
|
+
public class UsercentricsExternalDependencyManagerBuildCheck : IPreprocessBuildWithReport
|
|
14
|
+
{
|
|
15
|
+
public int callbackOrder => 0;
|
|
16
|
+
|
|
17
|
+
public void OnPreprocessBuild(BuildReport report)
|
|
18
|
+
{
|
|
19
|
+
// This check must never fail a build, so anything unexpected is reported as a warning and the check is skipped
|
|
20
|
+
try
|
|
21
|
+
{
|
|
22
|
+
var platform = report.summary.platform;
|
|
23
|
+
if (platform != BuildTarget.Android && platform != BuildTarget.iOS) return;
|
|
24
|
+
|
|
25
|
+
var loadedAssemblies = new List<string>();
|
|
26
|
+
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) loadedAssemblies.Add(assembly.GetName().Name);
|
|
27
|
+
|
|
28
|
+
if (platform == BuildTarget.Android)
|
|
29
|
+
{
|
|
30
|
+
if (!UsercentricsExternalDependencyManagerCheck.IsAndroidResolverLoaded(loadedAssemblies))
|
|
31
|
+
Debug.LogWarning(Message("Android", UsercentricsExternalDependencyManagerCheck.AndroidResolverAssembly));
|
|
32
|
+
}
|
|
33
|
+
else if (!UsercentricsExternalDependencyManagerCheck.IsIOSResolverLoaded(loadedAssemblies))
|
|
34
|
+
{
|
|
35
|
+
Debug.LogWarning(Message("iOS", UsercentricsExternalDependencyManagerCheck.IOSResolverAssembly));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
catch (Exception exception)
|
|
39
|
+
{
|
|
40
|
+
Debug.LogWarning("Usercentrics: the External Dependency Manager check failed and was skipped: " + exception.Message);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
private static string Message(string platform, string assembly)
|
|
45
|
+
{
|
|
46
|
+
return "Usercentrics: the External Dependency Manager (assembly '" + assembly + "') was not found, so the native " + platform +
|
|
47
|
+
" Usercentrics SDK will not be resolved from UsercentricsDependencies.xml and the app will fail at runtime because its " +
|
|
48
|
+
"Usercentrics classes are missing. Install it as a prerequisite. On Unity 2019.1 and newer, add the OpenUPM " +
|
|
49
|
+
"scoped registry (https://package.openupm.com, scope com.google.external-dependency-manager) and install the " +
|
|
50
|
+
"package com.google.external-dependency-manager in Window > Package Manager. On Unity 2018.4, which has no " +
|
|
51
|
+
"scoped registries, import the .unitypackage from https://github.com/googlesamples/unity-jar-resolver. " +
|
|
52
|
+
"This can be a false alarm if you add the native " +
|
|
53
|
+
platform + " dependencies yourself.";
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
using System;
|
|
2
|
+
using System.Collections.Generic;
|
|
3
|
+
|
|
4
|
+
namespace Unity.Usercentrics.Editor
|
|
5
|
+
{
|
|
6
|
+
// The External Dependency Manager (EDM4U) is a prerequisite and is not bundled in any Usercentrics package. It resolves the
|
|
7
|
+
// native Android and iOS dependencies declared in UsercentricsDependencies.xml, so without it a build succeeds but the app has
|
|
8
|
+
// no Usercentrics classes. Detection is by assembly name, never a compile reference: the Editor assembly must compile without it.
|
|
9
|
+
internal static class UsercentricsExternalDependencyManagerCheck
|
|
10
|
+
{
|
|
11
|
+
internal const string AndroidResolverAssembly = "Google.JarResolver";
|
|
12
|
+
internal const string IOSResolverAssembly = "Google.IOSResolver";
|
|
13
|
+
|
|
14
|
+
internal static bool IsAndroidResolverLoaded(IEnumerable<string> loadedAssemblyNames)
|
|
15
|
+
{
|
|
16
|
+
return Contains(loadedAssemblyNames, AndroidResolverAssembly);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
internal static bool IsIOSResolverLoaded(IEnumerable<string> loadedAssemblyNames)
|
|
20
|
+
{
|
|
21
|
+
return Contains(loadedAssemblyNames, IOSResolverAssembly);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
private static bool Contains(IEnumerable<string> names, string wanted)
|
|
25
|
+
{
|
|
26
|
+
if (names == null) return false;
|
|
27
|
+
foreach (string name in names)
|
|
28
|
+
{
|
|
29
|
+
if (string.Equals(name, wanted, StringComparison.Ordinal)) return true;
|
|
30
|
+
}
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
#if UNITY_IOS
|
|
2
|
+
using System.Linq;
|
|
3
|
+
using UnityEditor;
|
|
4
|
+
using UnityEditor.Callbacks;
|
|
5
|
+
using UnityEditor.iOS.Xcode;
|
|
6
|
+
|
|
7
|
+
namespace Unity.Usercentrics.Editor
|
|
8
|
+
{
|
|
9
|
+
internal static class UsercentricsIOSBuildFixes
|
|
10
|
+
{
|
|
11
|
+
private static readonly string[] UnityConfigNames =
|
|
12
|
+
{
|
|
13
|
+
"Debug", "Release", "ReleaseForRunning", "ReleaseForProfiling"
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// The linkage flip has to land inside EDM4U's own window: it writes the Podfile at build order 40 and
|
|
17
|
+
// runs `pod install` at 50, so a flip from the callback below (int.MaxValue) rewrites a Podfile that
|
|
18
|
+
// nothing reads again. The workspace then keeps the static layout, the app target has no
|
|
19
|
+
// "Embed Pods Frameworks" phase, and the app is killed by dyld at launch (MSDK-5360). Hits every
|
|
20
|
+
// CocoaPods customer with the dynamic package, because EDM4U's PodfileStaticLinkFrameworks defaults to
|
|
21
|
+
// true; the sample never caught it because its GvhProjectSettings.xml sets that to False and
|
|
22
|
+
// export-ios.sh runs `pod install` again afterwards.
|
|
23
|
+
[PostProcessBuild(UsercentricsPodfilePatches.PodfileLinkageBuildOrder)]
|
|
24
|
+
public static void OnPostProcessFixPodfileLinkage(BuildTarget target, string buildPath)
|
|
25
|
+
{
|
|
26
|
+
if (target != BuildTarget.iOS) return;
|
|
27
|
+
|
|
28
|
+
UsercentricsPodfilePatches.FixDynamicLinkage(buildPath);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Run last so all other post-processors have written their changes first.
|
|
32
|
+
[PostProcessBuild(int.MaxValue)]
|
|
33
|
+
public static void OnPostProcessBuild(BuildTarget target, string buildPath)
|
|
34
|
+
{
|
|
35
|
+
if (target != BuildTarget.iOS) return;
|
|
36
|
+
|
|
37
|
+
var projPath = PBXProject.GetPBXProjectPath(buildPath);
|
|
38
|
+
var proj = new PBXProject();
|
|
39
|
+
proj.ReadFromFile(projPath);
|
|
40
|
+
|
|
41
|
+
// On 2018.4 both names resolve to the same target, so Distinct() keeps the fixes from running twice
|
|
42
|
+
var targetGuids = new[]
|
|
43
|
+
{
|
|
44
|
+
proj.UnityMainTargetGuid(),
|
|
45
|
+
proj.UnityFrameworkTargetGuid(),
|
|
46
|
+
}.Distinct();
|
|
47
|
+
|
|
48
|
+
foreach (var guid in targetGuids)
|
|
49
|
+
{
|
|
50
|
+
RemoveMnoThumb(proj, guid);
|
|
51
|
+
AllowArm64Simulator(proj, guid);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
AddSwiftPackageResourceBundleCopyPhase(proj, proj.UnityFrameworkTargetGuid());
|
|
55
|
+
AddSwiftPackageFrameworksEmbedPhase(proj, proj.UnityMainTargetGuid());
|
|
56
|
+
|
|
57
|
+
proj.WriteToFile(projPath);
|
|
58
|
+
|
|
59
|
+
// Both patches are pure file edits and live in UsercentricsPodfilePatches so they can be unit-tested.
|
|
60
|
+
// FixDynamicLinkage normally runs in OnPostProcessFixPodfileLinkage above, inside EDM4U's window.
|
|
61
|
+
// Repeating it here is idempotent and covers the cases that window does not: no EDM4U at all, a
|
|
62
|
+
// Podfile written by something else after order 45, or a future EDM4U that reorders its callbacks.
|
|
63
|
+
// Then the Podfile is at least correct for the next `pod install` the customer runs by hand.
|
|
64
|
+
UsercentricsPodfilePatches.FixDynamicLinkage(buildPath);
|
|
65
|
+
|
|
66
|
+
var warning = UsercentricsPodfilePatches.RemoveStaticSdkFromAppTargetLinkLine(buildPath);
|
|
67
|
+
if (warning != null)
|
|
68
|
+
{
|
|
69
|
+
UnityEngine.Debug.LogWarning(warning);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// -mno-thumb is a 32-bit ARM flag. Xcode 12+ rejects it for both
|
|
74
|
+
// x86_64 and arm64 simulator targets. Unity adds it unconditionally
|
|
75
|
+
// to all build configurations, so we must remove it per-config.
|
|
76
|
+
private static void RemoveMnoThumb(PBXProject proj, string targetGuid)
|
|
77
|
+
{
|
|
78
|
+
foreach (var configName in UnityConfigNames)
|
|
79
|
+
{
|
|
80
|
+
var configGuid = proj.BuildConfigByName(targetGuid, configName);
|
|
81
|
+
if (string.IsNullOrEmpty(configGuid)) continue;
|
|
82
|
+
|
|
83
|
+
var flags = proj.GetBuildPropertyForConfig(configGuid, "OTHER_CFLAGS") ?? "";
|
|
84
|
+
if (!flags.Contains("-mno-thumb")) continue;
|
|
85
|
+
|
|
86
|
+
proj.SetBuildPropertyForConfig(
|
|
87
|
+
configGuid,
|
|
88
|
+
"OTHER_CFLAGS",
|
|
89
|
+
flags.Replace("-mno-thumb", "").Trim()
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Unity 2020.3 sets EXCLUDED_ARCHS[sdk=iphonesimulator*] = arm64 as a
|
|
95
|
+
// workaround for Intel Macs. On Apple Silicon the simulator runs natively
|
|
96
|
+
// on arm64, so this exclusion prevents the build from running entirely.
|
|
97
|
+
private static void AllowArm64Simulator(PBXProject proj, string targetGuid)
|
|
98
|
+
{
|
|
99
|
+
foreach (var configName in UnityConfigNames)
|
|
100
|
+
{
|
|
101
|
+
var configGuid = proj.BuildConfigByName(targetGuid, configName);
|
|
102
|
+
if (string.IsNullOrEmpty(configGuid)) continue;
|
|
103
|
+
|
|
104
|
+
proj.SetBuildPropertyForConfig(configGuid, "EXCLUDED_ARCHS[sdk=iphonesimulator*]", "");
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
private const string SpmBundleCopyPhaseName = "Copy Usercentrics UI resource bundle (SPM)";
|
|
109
|
+
|
|
110
|
+
// The -unity-static package points UsercentricsResourceLoader at the UnityFramework bundle (Usercentrics.mm,
|
|
111
|
+
// "bundleInit"): CocoaPods nests UsercentricsUIResources.bundle inside UnityFramework.framework. With Swift
|
|
112
|
+
// Package Manager the resource bundle (UsercentricsUI_UsercentricsUI.bundle) is built next to the products but
|
|
113
|
+
// never copied into the framework, because the Swift package product is linked into UnityFramework and the app
|
|
114
|
+
// only loads that framework at runtime. The UI then fatals with "[USERCENTRICS] Cannot load bundle" when the
|
|
115
|
+
// first layer is shown. Copy the bundle into UnityFramework.framework while the framework is built (before it
|
|
116
|
+
// is embedded and signed). No-op for CocoaPods builds, where the bundle does not exist in the products dir.
|
|
117
|
+
// cp -L (dereference) is required: in an `xcodebuild archive` the bundle in BUILT_PRODUCTS_DIR is a symlink to
|
|
118
|
+
// IntermediateBuildFilesPath/UninstalledProducts/<sdk>/, and a plain cp -R would copy the link itself, leaving
|
|
119
|
+
// a dangling symlink inside the .app (CTS-5050).
|
|
120
|
+
private static void AddSwiftPackageResourceBundleCopyPhase(PBXProject proj, string frameworkTargetGuid)
|
|
121
|
+
{
|
|
122
|
+
if (string.IsNullOrEmpty(frameworkTargetGuid)) return;
|
|
123
|
+
if (proj.WriteToString().Contains(SpmBundleCopyPhaseName)) return;
|
|
124
|
+
|
|
125
|
+
const string script =
|
|
126
|
+
"BUNDLE=\"${BUILT_PRODUCTS_DIR}/UsercentricsUI_UsercentricsUI.bundle\"\n" +
|
|
127
|
+
"DEST=\"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}\"\n" +
|
|
128
|
+
"if [ -d \"$BUNDLE\" ]; then\n" +
|
|
129
|
+
" rm -rf \"$DEST/UsercentricsUI_UsercentricsUI.bundle\"\n" +
|
|
130
|
+
" cp -RL \"$BUNDLE\" \"$DEST/\"\n" +
|
|
131
|
+
"fi\n";
|
|
132
|
+
proj.AddShellScriptBuildPhase(frameworkTargetGuid, SpmBundleCopyPhaseName, "/bin/sh", script);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
private const string SpmFrameworksEmbedPhaseName = "Embed Usercentrics frameworks (SPM)";
|
|
136
|
+
|
|
137
|
+
// With Swift Package Manager Usercentrics.framework and UsercentricsUI.framework are binary targets that
|
|
138
|
+
// get linked into UnityFramework (the package is attached to that target only), and nothing embeds them:
|
|
139
|
+
// the app only embeds UnityFramework. On a device or in an archive dyld then fails at launch with
|
|
140
|
+
// "Library not loaded: @rpath/UsercentricsUI.framework/UsercentricsUI". Running from Xcode on a simulator
|
|
141
|
+
// hides it, because Xcode adds the build products folder to the framework search path. Copy the dynamic
|
|
142
|
+
// frameworks into the app and sign them. Only added when the project references the Usercentrics Swift
|
|
143
|
+
// package, so CocoaPods projects get no new build phase. The script copies nothing for static frameworks
|
|
144
|
+
// (the -unity-static package), which must not be placed in the app's Frameworks folder. cp -L for the
|
|
145
|
+
// same reason as above: in an archive the products folder holds symlinks (CTS-5050).
|
|
146
|
+
private static void AddSwiftPackageFrameworksEmbedPhase(PBXProject proj, string appTargetGuid)
|
|
147
|
+
{
|
|
148
|
+
if (string.IsNullOrEmpty(appTargetGuid)) return;
|
|
149
|
+
|
|
150
|
+
var content = proj.WriteToString();
|
|
151
|
+
if (!content.Contains("usercentrics-spm")) return;
|
|
152
|
+
if (content.Contains(SpmFrameworksEmbedPhaseName)) return;
|
|
153
|
+
|
|
154
|
+
const string script =
|
|
155
|
+
"DEST=\"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}\"\n" +
|
|
156
|
+
"for NAME in Usercentrics UsercentricsUI; do\n" +
|
|
157
|
+
" SRC=\"${BUILT_PRODUCTS_DIR}/${NAME}.framework\"\n" +
|
|
158
|
+
" [ -d \"$SRC\" ] || continue\n" +
|
|
159
|
+
" otool -hv \"$SRC/$NAME\" 2>/dev/null | grep -q DYLIB || continue\n" +
|
|
160
|
+
" mkdir -p \"$DEST\"\n" +
|
|
161
|
+
" rm -rf \"$DEST/${NAME}.framework\"\n" +
|
|
162
|
+
" cp -RL \"$SRC\" \"$DEST/\"\n" +
|
|
163
|
+
" if [ \"${CODE_SIGNING_ALLOWED}\" != \"NO\" ] && [ -n \"${EXPANDED_CODE_SIGN_IDENTITY}\" ]; then\n" +
|
|
164
|
+
" codesign --force --sign \"${EXPANDED_CODE_SIGN_IDENTITY}\" --preserve-metadata=identifier,entitlements \"$DEST/${NAME}.framework\"\n" +
|
|
165
|
+
" fi\n" +
|
|
166
|
+
"done\n";
|
|
167
|
+
proj.AddShellScriptBuildPhase(appTargetGuid, SpmFrameworksEmbedPhaseName, "/bin/sh", script);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
#endif
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (c) 2021 Mopsicus
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
The above copyright notice and this permission notice shall be included in all
|
|
10
|
+
copies or substantial portions of the Software.
|
|
11
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
12
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
13
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
14
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
15
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
16
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
17
|
+
SOFTWARE.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
#if UNITY_IOS
|
|
21
|
+
|
|
22
|
+
using System;
|
|
23
|
+
using System.Collections;
|
|
24
|
+
using System.Reflection;
|
|
25
|
+
using UnityEditor.iOS.Xcode;
|
|
26
|
+
using System.Linq;
|
|
27
|
+
|
|
28
|
+
namespace Unity.Usercentrics
|
|
29
|
+
{
|
|
30
|
+
static class UsercentricsPBXProjectExtensions
|
|
31
|
+
{
|
|
32
|
+
|
|
33
|
+
readonly static Type _guidList;
|
|
34
|
+
readonly static Type _pbxBuildFileData;
|
|
35
|
+
readonly static Type _pbxVariantGroupData;
|
|
36
|
+
readonly static FieldInfo _dataFileGroups;
|
|
37
|
+
readonly static FieldInfo _dataFileRefsField;
|
|
38
|
+
readonly static FieldInfo _groupChildren;
|
|
39
|
+
readonly static FieldInfo _groupName;
|
|
40
|
+
readonly static FieldInfo _groupPath;
|
|
41
|
+
readonly static FieldInfo _pbxObjectGUID;
|
|
42
|
+
readonly static FieldInfo _projectData;
|
|
43
|
+
readonly static FieldInfo _resourceFiles;
|
|
44
|
+
readonly static FieldInfo _variantGroupName;
|
|
45
|
+
readonly static PropertyInfo _fileRefsPath;
|
|
46
|
+
readonly static PropertyInfo _projectResoruces;
|
|
47
|
+
readonly static PropertyInfo _projectVariantGroups;
|
|
48
|
+
readonly static MethodInfo _dataFileRefsFieldObjects;
|
|
49
|
+
readonly static MethodInfo _fileRefDataCreateFromFile;
|
|
50
|
+
readonly static MethodInfo _groupsObjects;
|
|
51
|
+
readonly static MethodInfo _guidListAdd;
|
|
52
|
+
readonly static MethodInfo _guidListContains;
|
|
53
|
+
readonly static MethodInfo _pbxBuildFileDataCreateFromFile;
|
|
54
|
+
readonly static MethodInfo _projectBuildFilesAdd;
|
|
55
|
+
readonly static MethodInfo _projectFileRefsAdd;
|
|
56
|
+
readonly static MethodInfo _projectBuildFilesGetForSourceFile;
|
|
57
|
+
readonly static MethodInfo _resorucesObjects;
|
|
58
|
+
readonly static MethodInfo _variantGroupsAddEntry;
|
|
59
|
+
readonly static MethodInfo _variantGroupsObjects;
|
|
60
|
+
readonly static MethodInfo _variantGroupsSetPropertyString;
|
|
61
|
+
|
|
62
|
+
static UsercentricsPBXProjectExtensions()
|
|
63
|
+
{
|
|
64
|
+
|
|
65
|
+
/// <summary>
|
|
66
|
+
/// Namespace for assembly
|
|
67
|
+
/// </summary>
|
|
68
|
+
const string PBX_NAMESPACE = "UnityEditor.iOS.Xcode.PBX";
|
|
69
|
+
|
|
70
|
+
/// <summary>
|
|
71
|
+
/// Assembly
|
|
72
|
+
/// </summary>
|
|
73
|
+
Assembly assembly = typeof(PBXProject).Assembly;
|
|
74
|
+
|
|
75
|
+
/// <summary>
|
|
76
|
+
/// Flags list for reflection
|
|
77
|
+
/// </summary>
|
|
78
|
+
const BindingFlags flags = BindingFlags.Instance | BindingFlags.NonPublic;
|
|
79
|
+
|
|
80
|
+
_guidList = assembly.GetType($"{PBX_NAMESPACE}.GUIDList");
|
|
81
|
+
_pbxBuildFileData = assembly.GetType($"{PBX_NAMESPACE}.PBXBuildFileData");
|
|
82
|
+
_pbxVariantGroupData = assembly.GetType($"{PBX_NAMESPACE}.PBXVariantGroupData");
|
|
83
|
+
Type fileRefData = assembly.GetType($"{PBX_NAMESPACE}.PBXFileReferenceData");
|
|
84
|
+
Type group = assembly.GetType($"{PBX_NAMESPACE}.PBXGroupData");
|
|
85
|
+
Type pbxObject = assembly.GetType($"{PBX_NAMESPACE}.PBXObjectData");
|
|
86
|
+
Type fileGUIDListBase = assembly.GetType($"{PBX_NAMESPACE}.FileGUIDListBase");
|
|
87
|
+
Type pbxElementDict = assembly.GetType($"{PBX_NAMESPACE}.PBXElementDict");
|
|
88
|
+
Type pbxProjectSection = assembly.GetType($"{PBX_NAMESPACE}.PBXProjectSection");
|
|
89
|
+
_projectData = typeof(PBXProject).GetField("m_Data", flags);
|
|
90
|
+
_dataFileRefsField = _projectData.FieldType.GetField("fileRefs", flags);
|
|
91
|
+
_dataFileGroups = _projectData.FieldType.GetField("groups", flags);
|
|
92
|
+
_resourceFiles = fileGUIDListBase.GetField("files");
|
|
93
|
+
_pbxObjectGUID = pbxObject.GetField("guid");
|
|
94
|
+
_groupChildren = group.GetField("children");
|
|
95
|
+
_groupName = group.GetField("name");
|
|
96
|
+
_groupPath = group.GetField("path");
|
|
97
|
+
_variantGroupName = _pbxVariantGroupData.GetField("name");
|
|
98
|
+
_groupsObjects = _dataFileGroups.FieldType.GetMethod("GetObjects");
|
|
99
|
+
_dataFileRefsFieldObjects = _dataFileRefsField.FieldType.GetMethod("GetObjects");
|
|
100
|
+
_guidListAdd = _guidList.GetMethod("AddGUID");
|
|
101
|
+
_guidListContains = _guidList.GetMethod("Contains");
|
|
102
|
+
_fileRefDataCreateFromFile = fileRefData.GetMethod("CreateFromFile", BindingFlags.Static | BindingFlags.Public);
|
|
103
|
+
_pbxBuildFileDataCreateFromFile = GetCreateFromFileMethod();
|
|
104
|
+
_projectBuildFilesAdd = typeof(PBXProject).GetMethod("BuildFilesAdd", flags);
|
|
105
|
+
_projectFileRefsAdd = typeof(PBXProject).GetMethod("FileRefsAdd", flags);
|
|
106
|
+
_projectBuildFilesGetForSourceFile = typeof(PBXProject).GetMethod("BuildFilesGetForSourceFile", flags);
|
|
107
|
+
_fileRefsPath = fileRefData.GetProperty("path");
|
|
108
|
+
_projectResoruces = typeof(PBXProject).GetProperty("resources", flags);
|
|
109
|
+
_projectVariantGroups = typeof(PBXProject).GetProperty("variantGroups", flags);
|
|
110
|
+
_resorucesObjects = _projectResoruces.PropertyType.GetMethod("GetObjects");
|
|
111
|
+
_variantGroupsAddEntry = _projectVariantGroups.PropertyType.GetMethod("AddEntry");
|
|
112
|
+
_variantGroupsObjects = _projectVariantGroups.PropertyType.GetMethod("GetObjects");
|
|
113
|
+
_variantGroupsSetPropertyString = group.GetMethod("SetPropertyString", flags);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
private static MethodInfo GetCreateFromFileMethod()
|
|
117
|
+
{
|
|
118
|
+
return _pbxBuildFileData.GetMethods().Where(x => x.Name == "CreateFromFile" && x.GetParameters().Length == 3).ElementAt(0);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Unity 2019.3+ exports an app target and a UnityFramework target. Before that
|
|
122
|
+
// there is a single "Unity-iPhone" target holding both.
|
|
123
|
+
internal static string UnityMainTargetGuid(this PBXProject project)
|
|
124
|
+
{
|
|
125
|
+
#if UNITY_2019_3_OR_NEWER
|
|
126
|
+
return project.GetUnityMainTargetGuid();
|
|
127
|
+
#else
|
|
128
|
+
return project.TargetGuidByName("Unity-iPhone");
|
|
129
|
+
#endif
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
internal static string UnityFrameworkTargetGuid(this PBXProject project)
|
|
133
|
+
{
|
|
134
|
+
#if UNITY_2019_3_OR_NEWER
|
|
135
|
+
return project.GetUnityFrameworkTargetGuid();
|
|
136
|
+
#else
|
|
137
|
+
return project.TargetGuidByName("Unity-iPhone");
|
|
138
|
+
#endif
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/// <summary>
|
|
142
|
+
/// Add locale for file
|
|
143
|
+
/// </summary>
|
|
144
|
+
/// <param name="project">PBX project</param>
|
|
145
|
+
/// <param name="groupName">Filename to add variant</param>
|
|
146
|
+
/// <param name="code">Language code</param>
|
|
147
|
+
/// <param name="path">Relative path to *.lproj</param>
|
|
148
|
+
public static void AddLocaleVariantFile(this PBXProject project, string groupName, string code, string path)
|
|
149
|
+
{
|
|
150
|
+
path = path.Replace('\\', '/');
|
|
151
|
+
object variantGroups = _projectVariantGroups.GetValue(project);
|
|
152
|
+
ICollection variantGroupValues = _variantGroupsObjects.Invoke(variantGroups, null) as ICollection;
|
|
153
|
+
object group = null;
|
|
154
|
+
foreach (var value in variantGroupValues)
|
|
155
|
+
{
|
|
156
|
+
string name = _variantGroupName.GetValue(value) as string;
|
|
157
|
+
if (name.Equals(groupName))
|
|
158
|
+
{
|
|
159
|
+
group = value;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
if (group == null)
|
|
163
|
+
{
|
|
164
|
+
string guid = Guid.NewGuid().ToString("N").Substring(8).ToUpper();
|
|
165
|
+
group = Activator.CreateInstance(_pbxVariantGroupData);
|
|
166
|
+
_variantGroupName.SetValue(group, groupName);
|
|
167
|
+
_groupPath.SetValue(group, groupName);
|
|
168
|
+
_pbxObjectGUID.SetValue(group, guid);
|
|
169
|
+
_groupChildren.SetValue(group, Activator.CreateInstance(_guidList));
|
|
170
|
+
_variantGroupsSetPropertyString.Invoke(group, new object[] { "isa", "PBXVariantGroup" });
|
|
171
|
+
_variantGroupsAddEntry.Invoke(variantGroups, new object[] { group });
|
|
172
|
+
}
|
|
173
|
+
string targetGuid = project.UnityMainTargetGuid();
|
|
174
|
+
string groupGuid = _pbxObjectGUID.GetValue(group) as string;
|
|
175
|
+
object buildFileData = _projectBuildFilesGetForSourceFile.Invoke(project, new object[] { targetGuid, groupGuid });
|
|
176
|
+
if (buildFileData == null)
|
|
177
|
+
{
|
|
178
|
+
object customData = project.GetGroupByName("CustomTemplate");
|
|
179
|
+
object children = _groupChildren.GetValue(customData);
|
|
180
|
+
_guidListAdd.Invoke(children, new object[] { groupGuid });
|
|
181
|
+
string buildFileGuid = project.AddFileRefToBuild(project.UnityMainTargetGuid(), groupGuid);
|
|
182
|
+
string buildPhaseGuid = project.GetResourcesBuildPhaseByTarget(targetGuid);
|
|
183
|
+
project.AddFileToResourceBuildPhase(buildPhaseGuid, buildFileGuid);
|
|
184
|
+
}
|
|
185
|
+
object fileRef = project.GetFileRefDataByPath(path);
|
|
186
|
+
if (fileRef == null)
|
|
187
|
+
{
|
|
188
|
+
fileRef = _fileRefDataCreateFromFile.Invoke(null, new object[] { path, code, PBXSourceTree.Source });
|
|
189
|
+
_projectFileRefsAdd.Invoke(project, new object[] { path, code, group, fileRef });
|
|
190
|
+
}
|
|
191
|
+
string fileRefsGuid = _pbxObjectGUID.GetValue(fileRef) as string;
|
|
192
|
+
object groupChildren = _groupChildren.GetValue(group);
|
|
193
|
+
bool result = (bool)_guidListContains.Invoke(groupChildren, new object[] { fileRefsGuid });
|
|
194
|
+
if (!result)
|
|
195
|
+
{
|
|
196
|
+
_guidListAdd.Invoke(groupChildren, new[] { fileRefsGuid });
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/// <summary>
|
|
201
|
+
/// Get file reference by path
|
|
202
|
+
/// </summary>
|
|
203
|
+
/// <param name="project">PBX project</param>
|
|
204
|
+
/// <param name="path">Path to directory</param>
|
|
205
|
+
/// <returns>File reference</returns>
|
|
206
|
+
static object GetFileRefDataByPath(this PBXProject project, string path)
|
|
207
|
+
{
|
|
208
|
+
object data = _projectData.GetValue(project);
|
|
209
|
+
object fileRefs = _dataFileRefsField.GetValue(data);
|
|
210
|
+
ICollection values = _dataFileRefsFieldObjects.Invoke(fileRefs, null) as ICollection;
|
|
211
|
+
foreach (object file in values)
|
|
212
|
+
{
|
|
213
|
+
string fileRefPath = _fileRefsPath.GetValue(file) as string;
|
|
214
|
+
if (fileRefPath.Equals(path))
|
|
215
|
+
{
|
|
216
|
+
return file;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return null;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/// <summary>
|
|
223
|
+
/// Get group by custom name
|
|
224
|
+
/// </summary>
|
|
225
|
+
/// <param name="project">PBX project</param>
|
|
226
|
+
/// <param name="name">Name</param>
|
|
227
|
+
/// <returns>Group</returns>
|
|
228
|
+
static object GetGroupByName(this PBXProject project, string name)
|
|
229
|
+
{
|
|
230
|
+
object data = _projectData.GetValue(project);
|
|
231
|
+
object groups = _dataFileGroups.GetValue(data);
|
|
232
|
+
ICollection groupsValues = _groupsObjects.Invoke(groups, null) as ICollection;
|
|
233
|
+
foreach (var group in groupsValues)
|
|
234
|
+
{
|
|
235
|
+
string groupName = _groupName.GetValue(group) as string;
|
|
236
|
+
if (groupName.Equals(name))
|
|
237
|
+
{
|
|
238
|
+
return group;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
return null;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
/// <summary>
|
|
246
|
+
/// Add file reference to build
|
|
247
|
+
/// </summary>
|
|
248
|
+
/// <param name="project">PBX project</param>
|
|
249
|
+
/// <param name="target">Target GUID</param>
|
|
250
|
+
/// <param name="guid">Group GUID</param>
|
|
251
|
+
/// <returns>Reference of file</returns>
|
|
252
|
+
static string AddFileRefToBuild(this PBXProject project, string target, string guid)
|
|
253
|
+
{
|
|
254
|
+
object data = _pbxBuildFileDataCreateFromFile.Invoke(null, new object[] { guid, false, null });
|
|
255
|
+
_projectBuildFilesAdd.Invoke(project, new object[] { target, data });
|
|
256
|
+
return _pbxObjectGUID.GetValue(data) as string;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/// <summary>
|
|
260
|
+
/// Add file to resources
|
|
261
|
+
/// </summary>
|
|
262
|
+
/// <param name="project">PBX project</param>
|
|
263
|
+
/// <param name="buildPhaseGuid">Build GUID</param>
|
|
264
|
+
/// <param name="fileGuid">File GUID to add</param>
|
|
265
|
+
static void AddFileToResourceBuildPhase(this PBXProject project, string buildPhaseGuid, string fileGuid)
|
|
266
|
+
{
|
|
267
|
+
object resources = _projectResoruces.GetValue(project);
|
|
268
|
+
ICollection values = _resorucesObjects.Invoke(resources, null) as ICollection;
|
|
269
|
+
foreach (object value in values)
|
|
270
|
+
{
|
|
271
|
+
string guid = _pbxObjectGUID.GetValue(value) as string;
|
|
272
|
+
if (guid.Equals(buildPhaseGuid))
|
|
273
|
+
{
|
|
274
|
+
object files = _resourceFiles.GetValue(value);
|
|
275
|
+
_guidListAdd.Invoke(files, new object[] { fileGuid });
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
#endif
|