Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 5.0.4 #313

Merged
merged 15 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Assets/Adjust/Native/Editor/Dependencies.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<dependencies>
<androidPackages>
<androidPackage spec="com.adjust.sdk:adjust-android:5.0.0">
<androidPackage spec="com.adjust.sdk:adjust-android:5.0.1">
</androidPackage>
<androidPackage spec="com.android.installreferrer:installreferrer:2.2">
</androidPackage>
Expand Down
613 changes: 322 additions & 291 deletions Assets/Adjust/Scripts/AdjustAndroid.cs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Assets/Adjust/Scripts/AdjustiOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace AdjustSdk
#if UNITY_IOS
public class AdjustiOS
{
private const string sdkPrefix = "unity5.0.3";
private const string sdkPrefix = "unity5.0.4";

// app callbacks as method parameters
private static List<Action<bool>> appIsEnabledGetterCallbacks;
Expand Down
173 changes: 99 additions & 74 deletions Assets/Adjust/Scripts/Editor/AdjustEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,75 +10,21 @@
#if UNITY_IOS
using UnityEditor.iOS.Xcode;
#endif
#if UNITY_2019_3_OR_NEWER
using UnityEditor.iOS.Xcode.Extensions;
#endif

namespace AdjustSdk
{
public class AdjustEditor : AssetPostprocessor
{
[MenuItem("Assets/Adjust/Export Unity Package")]
public static void ExportAdjustUnityPackage()
{
string exportedFileName = "Adjust.unitypackage";
string assetsPath = "Assets/Adjust";
List<string> assetsToExport = new List<string>();

// Adjust Assets.
assetsToExport.Add(assetsPath + "/3rd Party/SimpleJSON.cs");

assetsToExport.Add(assetsPath + "/Android/adjust-android.jar");
assetsToExport.Add(assetsPath + "/Android/AdjustAndroid.cs");
assetsToExport.Add(assetsPath + "/Android/AdjustAndroidManifest.xml");

assetsToExport.Add(assetsPath + "/Editor/AdjustEditor.cs");
assetsToExport.Add(assetsPath + "/Editor/AdjustSettings.cs");
assetsToExport.Add(assetsPath + "/Editor/AdjustSettingsEditor.cs");
assetsToExport.Add(assetsPath + "/Editor/AdjustCustomEditor.cs");
assetsToExport.Add(assetsPath + "/Editor/AdjustEditorPreprocessor.cs");

assetsToExport.Add(assetsPath + "/ExampleGUI/ExampleGUI.cs");
assetsToExport.Add(assetsPath + "/ExampleGUI/ExampleGUI.prefab");
assetsToExport.Add(assetsPath + "/ExampleGUI/ExampleGUI.unity");

assetsToExport.Add(assetsPath + "/iOS/ADJAttribution.h");
assetsToExport.Add(assetsPath + "/iOS/ADJConfig.h");
assetsToExport.Add(assetsPath + "/iOS/ADJEvent.h");
assetsToExport.Add(assetsPath + "/iOS/ADJEventFailure.h");
assetsToExport.Add(assetsPath + "/iOS/ADJEventSuccess.h");
assetsToExport.Add(assetsPath + "/iOS/ADJLogger.h");
assetsToExport.Add(assetsPath + "/iOS/ADJSessionFailure.h");
assetsToExport.Add(assetsPath + "/iOS/ADJSessionSuccess.h");
assetsToExport.Add(assetsPath + "/iOS/ADJSubscription.h");
assetsToExport.Add(assetsPath + "/iOS/Adjust.h");
assetsToExport.Add(assetsPath + "/iOS/AdjustiOS.cs");
assetsToExport.Add(assetsPath + "/iOS/AdjustSdk.a");
assetsToExport.Add(assetsPath + "/iOS/AdjustUnity.h");
assetsToExport.Add(assetsPath + "/iOS/AdjustUnity.mm");
assetsToExport.Add(assetsPath + "/iOS/AdjustUnityDelegate.h");
assetsToExport.Add(assetsPath + "/iOS/AdjustUnityDelegate.mm");

assetsToExport.Add(assetsPath + "/Prefab/Adjust.prefab");

assetsToExport.Add(assetsPath + "/Unity/Adjust.cs");
assetsToExport.Add(assetsPath + "/Unity/AdjustAppStoreSubscription.cs");
assetsToExport.Add(assetsPath + "/Unity/AdjustAttribution.cs");
assetsToExport.Add(assetsPath + "/Unity/AdjustConfig.cs");
assetsToExport.Add(assetsPath + "/Unity/AdjustEnvironment.cs");
assetsToExport.Add(assetsPath + "/Unity/AdjustEvent.cs");
assetsToExport.Add(assetsPath + "/Unity/AdjustEventFailure.cs");
assetsToExport.Add(assetsPath + "/Unity/AdjustEventSuccess.cs");
assetsToExport.Add(assetsPath + "/Unity/AdjustLogLevel.cs");
assetsToExport.Add(assetsPath + "/Unity/AdjustPlayStoreSubscription.cs");
assetsToExport.Add(assetsPath + "/Unity/AdjustSessionFailure.cs");
assetsToExport.Add(assetsPath + "/Unity/AdjustSessionSuccess.cs");
assetsToExport.Add(assetsPath + "/Unity/AdjustUtils.cs");

AssetDatabase.ExportPackage(
assetsToExport.ToArray(),
exportedFileName,
ExportPackageOptions.IncludeDependencies | ExportPackageOptions.Interactive);
}
private const int AdjustEditorPostProcesssBuildPriority = 90;
private const string TargetUnityIphonePodfileLine = "target 'Unity-iPhone' do";
private const string UseFrameworksPodfileLine = "use_frameworks!";
private const string UseFrameworksDynamicPodfileLine = "use_frameworks! :linkage => :dynamic";
private const string UseFrameworksStaticPodfileLine = "use_frameworks! :linkage => :static";

[PostProcessBuild]
[PostProcessBuild(AdjustEditorPostProcesssBuildPriority)]
public static void OnPostprocessBuild(BuildTarget target, string projectPath)
{
RunPostBuildScript(target: target, projectPath: projectPath);
Expand Down Expand Up @@ -169,17 +115,9 @@ private static void RunPostBuildScript(BuildTarget target, string projectPath =
Debug.Log("[Adjust]: Obj-C exceptions enabled successfully.");
}

if (xcodeProject.ContainsFileByProjectPath("Libraries/Adjust/Native/iOS/AdjustSigSdk.a"))
{
if (!string.IsNullOrEmpty(xcodeTargetUnityFramework))
{
xcodeProject.AddBuildProperty(xcodeTargetUnityFramework, "OTHER_LDFLAGS", "-force_load $(PROJECT_DIR)/Libraries/Adjust/Native/iOS/AdjustSigSdk.a");
}
else
{
xcodeProject.AddBuildProperty(xcodeTarget, "OTHER_LDFLAGS", "-force_load $(PROJECT_DIR)/Libraries/Adjust/Native/iOS/AdjustSigSdk.a");
}
}
// potential AdjustSigSdk.xcframework embedding
Debug.Log("[Adjust]: Checking whether AdjustSigSdk.xcframework needs to be embedded or not...");
EmbedAdjustSignatureIfNeeded(projectPath, xcodeProject, xcodeTarget);

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

#if UNITY_IOS
// dynamic xcframework embedding logic adjusted and taken from:
// https://github.com/AppLovin/AppLovin-MAX-Unity-Plugin/blob/master/DemoApp/Assets/MaxSdk/Scripts/IntegrationManager/Editor/AppLovinPostProcessiOS.cs
private static void EmbedAdjustSignatureIfNeeded(string buildPath, PBXProject project, string targetGuid)
{
var podsDirectory = Path.Combine(buildPath, "Pods");

if (!Directory.Exists(podsDirectory) || !ShouldEmbedDynamicLibraries(buildPath))
{
Debug.Log("[Adjust]: No need to embed AdjustSigSdk.xcframework.");
return;
}

var dynamicLibraryPathToEmbed = GetAdjustSignaturePathToEmbed(podsDirectory, buildPath);
if (dynamicLibraryPathToEmbed == null) {
return;
}

Debug.Log("[Adjust]: It needs to be embedded. Starting the embedding process...");
#if UNITY_2019_3_OR_NEWER
var fileGuid = project.AddFile(dynamicLibraryPathToEmbed, dynamicLibraryPathToEmbed);
project.AddFileToEmbedFrameworks(targetGuid, fileGuid);
#else
string runpathSearchPaths;
runpathSearchPaths = project.GetBuildPropertyForAnyConfig(targetGuid, "LD_RUNPATH_SEARCH_PATHS");
runpathSearchPaths += string.IsNullOrEmpty(runpathSearchPaths) ? "" : " ";

// check if runtime search paths already contains the required search paths for dynamic libraries
if (runpathSearchPaths.Contains("@executable_path/Frameworks")) {
return;
}

runpathSearchPaths += "@executable_path/Frameworks";
project.SetBuildProperty(targetGuid, "LD_RUNPATH_SEARCH_PATHS", runpathSearchPaths);
#endif
Debug.Log("[Adjust]: Embedding process completed.");
}

private static bool ShouldEmbedDynamicLibraries(string buildPath)
{
var podfilePath = Path.Combine(buildPath, "Podfile");
if (!File.Exists(podfilePath)) {
return false;
}

// if the Podfile doesn't have a `Unity-iPhone` target, we should embed the dynamic libraries
var lines = File.ReadAllLines(podfilePath);
var containsUnityIphoneTarget = lines.Any(line => line.Contains(TargetUnityIphonePodfileLine));
if (!containsUnityIphoneTarget) {
return true;
}

// if the Podfile does not have a `use_frameworks! :linkage => static` line, we should not embed the dynamic libraries
var useFrameworksStaticLineIndex = Array.FindIndex(lines, line => line.Contains(UseFrameworksStaticPodfileLine));
if (useFrameworksStaticLineIndex == -1) {
return false;
}

// if more than one of the `use_frameworks!` lines are present, CocoaPods will use the last one
var useFrameworksLineIndex = Array.FindIndex(lines, line => line.Trim() == UseFrameworksPodfileLine); // check for exact line to avoid matching `use_frameworks! :linkage => static/dynamic`
var useFrameworksDynamicLineIndex = Array.FindIndex(lines, line => line.Contains(UseFrameworksDynamicPodfileLine));

// check if `use_frameworks! :linkage => :static` is the last line of the three
// if it is, we should embed the dynamic libraries
return useFrameworksLineIndex < useFrameworksStaticLineIndex && useFrameworksDynamicLineIndex < useFrameworksStaticLineIndex;
}

private static string GetAdjustSignaturePathToEmbed(string podsDirectory, string buildPath)
{
var adjustSignatureFrameworkToEmbed = "AdjustSigSdk.xcframework";

// both .framework and .xcframework are directories, not files
var directories = Directory.GetDirectories(podsDirectory, adjustSignatureFrameworkToEmbed, SearchOption.AllDirectories);
if (directories.Length <= 0) {
return null;
}

var dynamicLibraryAbsolutePath = directories[0];
var relativePath = GetDynamicLibraryRelativePath(dynamicLibraryAbsolutePath);
return relativePath;
}

private static string GetDynamicLibraryRelativePath(string dynamicLibraryAbsolutePath)
{
var index = dynamicLibraryAbsolutePath.LastIndexOf("Pods", StringComparison.Ordinal);
return dynamicLibraryAbsolutePath.Substring(index);
}

private static void HandlePlistIosChanges(string projectPath)
{
const string UserTrackingUsageDescriptionKey = "NSUserTrackingUsageDescription";
Expand Down
8 changes: 0 additions & 8 deletions Assets/Adjust/Scripts/Editor/AdjustSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,35 +56,27 @@ public static AdjustSettings Instance
}

var assetPath = AssetDatabase.GUIDToAssetPath(guids[0]).Replace("AdjustSettings.cs", "AdjustSettings.asset");
Debug.Log("READ PATH = " + assetPath);
// AdjustSettings.asset will be stored inside of the Adjust/Resources directory
if (assetPath.StartsWith("Assets"))
{
// plugin located in Assets directory
string rootDir = assetPath.Replace("/Adjust/Scripts/Editor/AdjustSettings.asset", "");
Debug.Log("ROOT DIR = " + rootDir);
string adjustResourcesPath = Path.Combine(rootDir, "Adjust/Resources");
Debug.Log("ADJUST RESOURCES DIR = " + adjustResourcesPath);
if (!Directory.Exists(adjustResourcesPath))
{
Debug.Log("CREATING ADJUST RESOURCES DIR = " + adjustResourcesPath);
Directory.CreateDirectory(adjustResourcesPath);
}
assetPath = Path.Combine(rootDir, AdjustSettingsExportPath);
Debug.Log("FINAL ASSET PATH = " + assetPath);
}
else
{
// plugin located in Packages folder
string adjustResourcesPath = Path.Combine("Assets", "Adjust/Resources");
Debug.Log("ADJUST RESOURCES DIR = " + adjustResourcesPath);
if (!Directory.Exists(adjustResourcesPath))
{
Debug.Log("CREATING ADJUST RESOURCES DIR = " + adjustResourcesPath);
Directory.CreateDirectory(adjustResourcesPath);
}
assetPath = Path.Combine("Assets", AdjustSettingsExportPath);
Debug.Log("FINAL ASSET PATH = " + assetPath);
}

AssetDatabase.CreateAsset(instance, assetPath);
Expand Down
2 changes: 1 addition & 1 deletion Assets/Adjust/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "com.adjust.sdk",
"version": "5.0.3",
"version": "5.0.4",
"unity": "2019.4",
"displayName": "Adjust",
"license": "MIT",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
53 changes: 53 additions & 0 deletions Assets/Test/TestApp/TestApp.prefab
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &100000
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
serializedVersion: 6
m_Component:
- component: {fileID: 400000}
- component: {fileID: 114599351951650296}
m_Layer: 0
m_Name: TestApp
m_TagString: MainCamera
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &400000
Transform:
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 100000}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 1, z: -10}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1001 &100100000
Prefab:
m_ObjectHideFlags: 1
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications: []
m_RemovedComponents: []
m_SourcePrefab: {fileID: 0}
m_RootGameObject: {fileID: 100000}
m_IsPrefabAsset: 1
--- !u!114 &114599351951650296
MonoBehaviour:
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 100000}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c420967931ab34a33abb412b340a032b, type: 3}
m_Name:
m_EditorClassIdentifier:
8 changes: 8 additions & 0 deletions Assets/Test/TestApp/TestApp.prefab.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading