Skip to content

Commit a629336

Browse files
authored
Merge pull request #313 from adjust/v504
Version 5.0.4
2 parents fe136c2 + 2a5ce38 commit a629336

18 files changed

+549
-423
lines changed

Assets/Adjust/Native/Editor/Dependencies.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<dependencies>
33
<androidPackages>
4-
<androidPackage spec="com.adjust.sdk:adjust-android:5.0.0">
4+
<androidPackage spec="com.adjust.sdk:adjust-android:5.0.1">
55
</androidPackage>
66
<androidPackage spec="com.android.installreferrer:installreferrer:2.2">
77
</androidPackage>

Assets/Adjust/Scripts/AdjustAndroid.cs

+322-291
Large diffs are not rendered by default.

Assets/Adjust/Scripts/AdjustiOS.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace AdjustSdk
88
#if UNITY_IOS
99
public class AdjustiOS
1010
{
11-
private const string sdkPrefix = "unity5.0.3";
11+
private const string sdkPrefix = "unity5.0.4";
1212

1313
// app callbacks as method parameters
1414
private static List<Action<bool>> appIsEnabledGetterCallbacks;

Assets/Adjust/Scripts/Editor/AdjustEditor.cs

+99-74
Original file line numberDiff line numberDiff line change
@@ -10,75 +10,21 @@
1010
#if UNITY_IOS
1111
using UnityEditor.iOS.Xcode;
1212
#endif
13+
#if UNITY_2019_3_OR_NEWER
14+
using UnityEditor.iOS.Xcode.Extensions;
15+
#endif
1316

1417
namespace AdjustSdk
1518
{
1619
public class AdjustEditor : AssetPostprocessor
1720
{
18-
[MenuItem("Assets/Adjust/Export Unity Package")]
19-
public static void ExportAdjustUnityPackage()
20-
{
21-
string exportedFileName = "Adjust.unitypackage";
22-
string assetsPath = "Assets/Adjust";
23-
List<string> assetsToExport = new List<string>();
24-
25-
// Adjust Assets.
26-
assetsToExport.Add(assetsPath + "/3rd Party/SimpleJSON.cs");
27-
28-
assetsToExport.Add(assetsPath + "/Android/adjust-android.jar");
29-
assetsToExport.Add(assetsPath + "/Android/AdjustAndroid.cs");
30-
assetsToExport.Add(assetsPath + "/Android/AdjustAndroidManifest.xml");
31-
32-
assetsToExport.Add(assetsPath + "/Editor/AdjustEditor.cs");
33-
assetsToExport.Add(assetsPath + "/Editor/AdjustSettings.cs");
34-
assetsToExport.Add(assetsPath + "/Editor/AdjustSettingsEditor.cs");
35-
assetsToExport.Add(assetsPath + "/Editor/AdjustCustomEditor.cs");
36-
assetsToExport.Add(assetsPath + "/Editor/AdjustEditorPreprocessor.cs");
37-
38-
assetsToExport.Add(assetsPath + "/ExampleGUI/ExampleGUI.cs");
39-
assetsToExport.Add(assetsPath + "/ExampleGUI/ExampleGUI.prefab");
40-
assetsToExport.Add(assetsPath + "/ExampleGUI/ExampleGUI.unity");
41-
42-
assetsToExport.Add(assetsPath + "/iOS/ADJAttribution.h");
43-
assetsToExport.Add(assetsPath + "/iOS/ADJConfig.h");
44-
assetsToExport.Add(assetsPath + "/iOS/ADJEvent.h");
45-
assetsToExport.Add(assetsPath + "/iOS/ADJEventFailure.h");
46-
assetsToExport.Add(assetsPath + "/iOS/ADJEventSuccess.h");
47-
assetsToExport.Add(assetsPath + "/iOS/ADJLogger.h");
48-
assetsToExport.Add(assetsPath + "/iOS/ADJSessionFailure.h");
49-
assetsToExport.Add(assetsPath + "/iOS/ADJSessionSuccess.h");
50-
assetsToExport.Add(assetsPath + "/iOS/ADJSubscription.h");
51-
assetsToExport.Add(assetsPath + "/iOS/Adjust.h");
52-
assetsToExport.Add(assetsPath + "/iOS/AdjustiOS.cs");
53-
assetsToExport.Add(assetsPath + "/iOS/AdjustSdk.a");
54-
assetsToExport.Add(assetsPath + "/iOS/AdjustUnity.h");
55-
assetsToExport.Add(assetsPath + "/iOS/AdjustUnity.mm");
56-
assetsToExport.Add(assetsPath + "/iOS/AdjustUnityDelegate.h");
57-
assetsToExport.Add(assetsPath + "/iOS/AdjustUnityDelegate.mm");
58-
59-
assetsToExport.Add(assetsPath + "/Prefab/Adjust.prefab");
60-
61-
assetsToExport.Add(assetsPath + "/Unity/Adjust.cs");
62-
assetsToExport.Add(assetsPath + "/Unity/AdjustAppStoreSubscription.cs");
63-
assetsToExport.Add(assetsPath + "/Unity/AdjustAttribution.cs");
64-
assetsToExport.Add(assetsPath + "/Unity/AdjustConfig.cs");
65-
assetsToExport.Add(assetsPath + "/Unity/AdjustEnvironment.cs");
66-
assetsToExport.Add(assetsPath + "/Unity/AdjustEvent.cs");
67-
assetsToExport.Add(assetsPath + "/Unity/AdjustEventFailure.cs");
68-
assetsToExport.Add(assetsPath + "/Unity/AdjustEventSuccess.cs");
69-
assetsToExport.Add(assetsPath + "/Unity/AdjustLogLevel.cs");
70-
assetsToExport.Add(assetsPath + "/Unity/AdjustPlayStoreSubscription.cs");
71-
assetsToExport.Add(assetsPath + "/Unity/AdjustSessionFailure.cs");
72-
assetsToExport.Add(assetsPath + "/Unity/AdjustSessionSuccess.cs");
73-
assetsToExport.Add(assetsPath + "/Unity/AdjustUtils.cs");
74-
75-
AssetDatabase.ExportPackage(
76-
assetsToExport.ToArray(),
77-
exportedFileName,
78-
ExportPackageOptions.IncludeDependencies | ExportPackageOptions.Interactive);
79-
}
21+
private const int AdjustEditorPostProcesssBuildPriority = 90;
22+
private const string TargetUnityIphonePodfileLine = "target 'Unity-iPhone' do";
23+
private const string UseFrameworksPodfileLine = "use_frameworks!";
24+
private const string UseFrameworksDynamicPodfileLine = "use_frameworks! :linkage => :dynamic";
25+
private const string UseFrameworksStaticPodfileLine = "use_frameworks! :linkage => :static";
8026

81-
[PostProcessBuild]
27+
[PostProcessBuild(AdjustEditorPostProcesssBuildPriority)]
8228
public static void OnPostprocessBuild(BuildTarget target, string projectPath)
8329
{
8430
RunPostBuildScript(target: target, projectPath: projectPath);
@@ -169,17 +115,9 @@ private static void RunPostBuildScript(BuildTarget target, string projectPath =
169115
Debug.Log("[Adjust]: Obj-C exceptions enabled successfully.");
170116
}
171117

172-
if (xcodeProject.ContainsFileByProjectPath("Libraries/Adjust/Native/iOS/AdjustSigSdk.a"))
173-
{
174-
if (!string.IsNullOrEmpty(xcodeTargetUnityFramework))
175-
{
176-
xcodeProject.AddBuildProperty(xcodeTargetUnityFramework, "OTHER_LDFLAGS", "-force_load $(PROJECT_DIR)/Libraries/Adjust/Native/iOS/AdjustSigSdk.a");
177-
}
178-
else
179-
{
180-
xcodeProject.AddBuildProperty(xcodeTarget, "OTHER_LDFLAGS", "-force_load $(PROJECT_DIR)/Libraries/Adjust/Native/iOS/AdjustSigSdk.a");
181-
}
182-
}
118+
// potential AdjustSigSdk.xcframework embedding
119+
Debug.Log("[Adjust]: Checking whether AdjustSigSdk.xcframework needs to be embedded or not...");
120+
EmbedAdjustSignatureIfNeeded(projectPath, xcodeProject, xcodeTarget);
183121

184122
// Save the changes to Xcode project file.
185123
xcodeProject.WriteToFile(xcodeProjectPath);
@@ -188,6 +126,93 @@ private static void RunPostBuildScript(BuildTarget target, string projectPath =
188126
}
189127

190128
#if UNITY_IOS
129+
// dynamic xcframework embedding logic adjusted and taken from:
130+
// https://github.com/AppLovin/AppLovin-MAX-Unity-Plugin/blob/master/DemoApp/Assets/MaxSdk/Scripts/IntegrationManager/Editor/AppLovinPostProcessiOS.cs
131+
private static void EmbedAdjustSignatureIfNeeded(string buildPath, PBXProject project, string targetGuid)
132+
{
133+
var podsDirectory = Path.Combine(buildPath, "Pods");
134+
135+
if (!Directory.Exists(podsDirectory) || !ShouldEmbedDynamicLibraries(buildPath))
136+
{
137+
Debug.Log("[Adjust]: No need to embed AdjustSigSdk.xcframework.");
138+
return;
139+
}
140+
141+
var dynamicLibraryPathToEmbed = GetAdjustSignaturePathToEmbed(podsDirectory, buildPath);
142+
if (dynamicLibraryPathToEmbed == null) {
143+
return;
144+
}
145+
146+
Debug.Log("[Adjust]: It needs to be embedded. Starting the embedding process...");
147+
#if UNITY_2019_3_OR_NEWER
148+
var fileGuid = project.AddFile(dynamicLibraryPathToEmbed, dynamicLibraryPathToEmbed);
149+
project.AddFileToEmbedFrameworks(targetGuid, fileGuid);
150+
#else
151+
string runpathSearchPaths;
152+
runpathSearchPaths = project.GetBuildPropertyForAnyConfig(targetGuid, "LD_RUNPATH_SEARCH_PATHS");
153+
runpathSearchPaths += string.IsNullOrEmpty(runpathSearchPaths) ? "" : " ";
154+
155+
// check if runtime search paths already contains the required search paths for dynamic libraries
156+
if (runpathSearchPaths.Contains("@executable_path/Frameworks")) {
157+
return;
158+
}
159+
160+
runpathSearchPaths += "@executable_path/Frameworks";
161+
project.SetBuildProperty(targetGuid, "LD_RUNPATH_SEARCH_PATHS", runpathSearchPaths);
162+
#endif
163+
Debug.Log("[Adjust]: Embedding process completed.");
164+
}
165+
166+
private static bool ShouldEmbedDynamicLibraries(string buildPath)
167+
{
168+
var podfilePath = Path.Combine(buildPath, "Podfile");
169+
if (!File.Exists(podfilePath)) {
170+
return false;
171+
}
172+
173+
// if the Podfile doesn't have a `Unity-iPhone` target, we should embed the dynamic libraries
174+
var lines = File.ReadAllLines(podfilePath);
175+
var containsUnityIphoneTarget = lines.Any(line => line.Contains(TargetUnityIphonePodfileLine));
176+
if (!containsUnityIphoneTarget) {
177+
return true;
178+
}
179+
180+
// if the Podfile does not have a `use_frameworks! :linkage => static` line, we should not embed the dynamic libraries
181+
var useFrameworksStaticLineIndex = Array.FindIndex(lines, line => line.Contains(UseFrameworksStaticPodfileLine));
182+
if (useFrameworksStaticLineIndex == -1) {
183+
return false;
184+
}
185+
186+
// if more than one of the `use_frameworks!` lines are present, CocoaPods will use the last one
187+
var useFrameworksLineIndex = Array.FindIndex(lines, line => line.Trim() == UseFrameworksPodfileLine); // check for exact line to avoid matching `use_frameworks! :linkage => static/dynamic`
188+
var useFrameworksDynamicLineIndex = Array.FindIndex(lines, line => line.Contains(UseFrameworksDynamicPodfileLine));
189+
190+
// check if `use_frameworks! :linkage => :static` is the last line of the three
191+
// if it is, we should embed the dynamic libraries
192+
return useFrameworksLineIndex < useFrameworksStaticLineIndex && useFrameworksDynamicLineIndex < useFrameworksStaticLineIndex;
193+
}
194+
195+
private static string GetAdjustSignaturePathToEmbed(string podsDirectory, string buildPath)
196+
{
197+
var adjustSignatureFrameworkToEmbed = "AdjustSigSdk.xcframework";
198+
199+
// both .framework and .xcframework are directories, not files
200+
var directories = Directory.GetDirectories(podsDirectory, adjustSignatureFrameworkToEmbed, SearchOption.AllDirectories);
201+
if (directories.Length <= 0) {
202+
return null;
203+
}
204+
205+
var dynamicLibraryAbsolutePath = directories[0];
206+
var relativePath = GetDynamicLibraryRelativePath(dynamicLibraryAbsolutePath);
207+
return relativePath;
208+
}
209+
210+
private static string GetDynamicLibraryRelativePath(string dynamicLibraryAbsolutePath)
211+
{
212+
var index = dynamicLibraryAbsolutePath.LastIndexOf("Pods", StringComparison.Ordinal);
213+
return dynamicLibraryAbsolutePath.Substring(index);
214+
}
215+
191216
private static void HandlePlistIosChanges(string projectPath)
192217
{
193218
const string UserTrackingUsageDescriptionKey = "NSUserTrackingUsageDescription";

Assets/Adjust/Scripts/Editor/AdjustSettings.cs

-8
Original file line numberDiff line numberDiff line change
@@ -56,35 +56,27 @@ public static AdjustSettings Instance
5656
}
5757

5858
var assetPath = AssetDatabase.GUIDToAssetPath(guids[0]).Replace("AdjustSettings.cs", "AdjustSettings.asset");
59-
Debug.Log("READ PATH = " + assetPath);
6059
// AdjustSettings.asset will be stored inside of the Adjust/Resources directory
6160
if (assetPath.StartsWith("Assets"))
6261
{
6362
// plugin located in Assets directory
6463
string rootDir = assetPath.Replace("/Adjust/Scripts/Editor/AdjustSettings.asset", "");
65-
Debug.Log("ROOT DIR = " + rootDir);
6664
string adjustResourcesPath = Path.Combine(rootDir, "Adjust/Resources");
67-
Debug.Log("ADJUST RESOURCES DIR = " + adjustResourcesPath);
6865
if (!Directory.Exists(adjustResourcesPath))
6966
{
70-
Debug.Log("CREATING ADJUST RESOURCES DIR = " + adjustResourcesPath);
7167
Directory.CreateDirectory(adjustResourcesPath);
7268
}
7369
assetPath = Path.Combine(rootDir, AdjustSettingsExportPath);
74-
Debug.Log("FINAL ASSET PATH = " + assetPath);
7570
}
7671
else
7772
{
7873
// plugin located in Packages folder
7974
string adjustResourcesPath = Path.Combine("Assets", "Adjust/Resources");
80-
Debug.Log("ADJUST RESOURCES DIR = " + adjustResourcesPath);
8175
if (!Directory.Exists(adjustResourcesPath))
8276
{
83-
Debug.Log("CREATING ADJUST RESOURCES DIR = " + adjustResourcesPath);
8477
Directory.CreateDirectory(adjustResourcesPath);
8578
}
8679
assetPath = Path.Combine("Assets", AdjustSettingsExportPath);
87-
Debug.Log("FINAL ASSET PATH = " + assetPath);
8880
}
8981

9082
AssetDatabase.CreateAsset(instance, assetPath);

Assets/Adjust/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "com.adjust.sdk",
3-
"version": "5.0.3",
3+
"version": "5.0.4",
44
"unity": "2019.4",
55
"displayName": "Adjust",
66
"license": "MIT",
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

Assets/Test/TestApp/TestApp.prefab

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!1 &100000
4+
GameObject:
5+
m_ObjectHideFlags: 0
6+
m_CorrespondingSourceObject: {fileID: 0}
7+
m_PrefabInternal: {fileID: 100100000}
8+
serializedVersion: 6
9+
m_Component:
10+
- component: {fileID: 400000}
11+
- component: {fileID: 114599351951650296}
12+
m_Layer: 0
13+
m_Name: TestApp
14+
m_TagString: MainCamera
15+
m_Icon: {fileID: 0}
16+
m_NavMeshLayer: 0
17+
m_StaticEditorFlags: 0
18+
m_IsActive: 1
19+
--- !u!4 &400000
20+
Transform:
21+
m_ObjectHideFlags: 1
22+
m_CorrespondingSourceObject: {fileID: 0}
23+
m_PrefabInternal: {fileID: 100100000}
24+
m_GameObject: {fileID: 100000}
25+
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
26+
m_LocalPosition: {x: 0, y: 1, z: -10}
27+
m_LocalScale: {x: 1, y: 1, z: 1}
28+
m_Children: []
29+
m_Father: {fileID: 0}
30+
m_RootOrder: 0
31+
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
32+
--- !u!1001 &100100000
33+
Prefab:
34+
m_ObjectHideFlags: 1
35+
serializedVersion: 2
36+
m_Modification:
37+
m_TransformParent: {fileID: 0}
38+
m_Modifications: []
39+
m_RemovedComponents: []
40+
m_SourcePrefab: {fileID: 0}
41+
m_RootGameObject: {fileID: 100000}
42+
m_IsPrefabAsset: 1
43+
--- !u!114 &114599351951650296
44+
MonoBehaviour:
45+
m_ObjectHideFlags: 1
46+
m_CorrespondingSourceObject: {fileID: 0}
47+
m_PrefabInternal: {fileID: 100100000}
48+
m_GameObject: {fileID: 100000}
49+
m_Enabled: 1
50+
m_EditorHideFlags: 0
51+
m_Script: {fileID: 11500000, guid: c420967931ab34a33abb412b340a032b, type: 3}
52+
m_Name:
53+
m_EditorClassIdentifier:

Assets/Test/TestApp/TestApp.prefab.meta

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)