Skip to content

Instantly share code, notes, and snippets.

@dzolnai
Last active May 31, 2019 12:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dzolnai/1de788bba86ff4b52b5fc261b4312169 to your computer and use it in GitHub Desktop.
Save dzolnai/1de788bba86ff4b52b5fc261b4312169 to your computer and use it in GitHub Desktop.
Get Adobe Analytics library working on Unity
//
// Copyright (c) 2017 eppz! mobile, Gergely Borbás (SP)
//
// http://www.twitter.com/_eppz
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
// OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// From: https://gist.github.com/eppz/1ebbc1cf6a77741f56d63d3803e57ba3
using System.IO;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEditor.iOS.Xcode;
public class AdobeLocationFramework
{
[PostProcessBuildAttribute(1)]
public static void OnPostProcessBuild(BuildTarget target, string path)
{
if (target == BuildTarget.iOS)
{
// Read.
string projectPath = PBXProject.GetPBXProjectPath(path);
PBXProject project = new PBXProject();
project.ReadFromString(File.ReadAllText(projectPath));
string targetName = PBXProject.GetUnityTargetName();
string targetGUID = project.TargetGuidByName(targetName);
AddFrameworks(project, targetGUID);
// Write.
File.WriteAllText(projectPath, project.WriteToString());
}
}
static void AddFrameworks(PBXProject project, string targetGUID)
{
// Frameworks.
project.AddFrameworkToProject(targetGUID, "CoreLocation.framework", false);
project.AddFrameworkToProject(targetGUID, "libsqlite3.tbd", false);
// Add `-ObjC` to "Other Linker Flags".
project.AddBuildProperty(targetGUID, "OTHER_LDFLAGS", "-ObjC");
}
}
using System.IO;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEditor.iOS.Xcode;
using UnityEngine;
public static class CopyConfig
{
[PostProcessBuild]
public static void OnPostProcessBuild(BuildTarget target, string path)
{
Debug.Log( "Adobe Analytics Unity: Post build script starts");
if (target == BuildTarget.iOS)
{
// Get target for Xcode project
string projPath = PBXProject.GetPBXProjectPath(path);
var proj = new PBXProject();
proj.ReadFromString(File.ReadAllText(projPath));
string targetName = PBXProject.GetUnityTargetName();
string projectTarget = proj.TargetGuidByName(targetName);
proj.AddFileToBuild(projectTarget, proj.AddFile(Application.dataPath + "/Plugins/iOS/ADBMobileConfig.json", "ADBMobileConfig.json"));
File.WriteAllText(projPath, proj.WriteToString());
}
}
}
1. Import the Adobe Analytics Unity package
2. Add the two scripts above to your project
3. Replace Plugins/Android/adobeMobileLibrary-4.x.x.jar with the jar in https://github.com/Adobe-Marketing-Cloud/mobile-services/tree/master/sdks/Android/AdobeMobileLibrary
4. Replace ADBMobile.h and AdobeMobileLibrary.a in Plugins/iOS/ with the same files from here: https://github.com/Adobe-Marketing-Cloud/mobile-services/tree/master/sdks/iOS/AdobeMobileLibrary
This is working as of now (2019.05.31, current commit: https://github.com/Adobe-Marketing-Cloud/mobile-services/commit/e416c9d85f183d009fc0dd798e4a62c8aa4ef72f), might break later, though.
The location framework script fixes the iOS build error.
The copy config script fixes the issue that the library can't find the config because it is not included in the build.
Replacing the libraries fixes the issue that on startup the iOS app hangs for a few seconds.
Hopefully they will release a new version of the package soon, so you don't have to do all these to get it working properly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment