コード例 #1
0
    protected static void BuildAndroid(string fileName, BuildOptions opt, string[] mainScenes, string applicationIdentifier)
    {
        UnityEngine.Debug.Log("[####] Building " + fileName);
        EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.Android, BuildTarget.Android);
        PlayerSettings.applicationIdentifier = applicationIdentifier;
        SwrveBuildComponent.AndroidPreBuild();

        // Fix for ANDROID_HOME Unity bug
        FixAndroidHomeNotFound();

        // Build Android
#if UNITY_2018_1_OR_NEWER
        var summary = BuildPipeline.BuildPlayer(mainScenes, fileName, BuildTarget.Android, opt).summary;
        if (summary.result == UnityEditor.Build.Reporting.BuildResult.Failed)
        {
            throw new Exception("Build had " + summary.totalErrors + " errors");
        }
#else
        string error = BuildPipeline.BuildPlayer(mainScenes, fileName, BuildTarget.Android, opt);
        if (error != null && !error.Equals(string.Empty))
        {
            throw new Exception(error);
        }
#endif
        UnityEngine.Debug.Log("Built " + fileName);
    }
コード例 #2
0
    public static void SetPlotConfigKey(string platform, string writePath = null)
    {
        platform = platform.ToLower();

        string readPath = null;

        if ("android" == platform)
        {
            readPath = "Assets/Plugins/Android/SwrveLocationSDK/assets";
        }
        else if ("ios" == platform)
        {
            readPath = "Assets/Plugins/iOS/SwrveLocationSDK";
        }
        else
        {
            SwrveLog.Log(string.Format("{0} is an unknown platform, returning", platform));
            return;
        }
        if (!Directory.Exists(readPath))
        {
            return;
        }
        readPath = Path.Combine(readPath, "plotconfig.json");

        string plotToken = SwrveBuildComponent.GetPostProcessString(SwrveBuildComponent.PLOT_TOKEN_KEY);

        if (string.IsNullOrEmpty(plotToken))
        {
            SwrveLog.Log(string.Format("No plot token set in postprocess file, not adding plotconfig.json for {0}", platform));
            return;
        }

        if (string.IsNullOrEmpty(writePath))
        {
            writePath = readPath;
        }

        Dictionary <string, object> plotconfig =
            (Dictionary <string, object>)Json.Deserialize(File.ReadAllText(readPath));

        plotconfig[PLOT_PUBLIC_TOKEN_KEY] = plotToken;
        File.WriteAllText(writePath, Json.Serialize(plotconfig));
    }
コード例 #3
0
    protected static void BuildAndroid(string fileName, BuildOptions opt, string[] mainScenes, string packageName)
    {
        UnityEngine.Debug.Log("[####] Building " + fileName);
        EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTarget.Android);
        PlayerSettings.bundleIdentifier = packageName;
        SwrveBuildComponent.CorrectApplicationId();

        // Fix for ANDROID_HOME Unity bug
        FixAndroidHomeNotFound();

        // Build Android
        string error = BuildPipeline.BuildPlayer(mainScenes, fileName, BuildTarget.Android, opt);

        if (error != null && !error.Equals(string.Empty))
        {
            throw new Exception(error);
        }
        UnityEngine.Debug.Log("Built " + fileName);
    }
コード例 #4
0
    public static void SetAppGroupConfigKey(string platform, string writePath = null)
    {
        platform = platform.ToLower();

        string readPath = null;

        if ("ios" == platform)
        {
            readPath = "Assets/Plugins/iOS/SwrvePushExtension";
        }
        else
        {
            SwrveLog.Log(string.Format("{0} is an unknown platform, returning", platform));
            return;
        }
        if (!Directory.Exists(readPath))
        {
            return;
        }
        readPath = Path.Combine(readPath, "appgroupconfig.json");

        string appGroupIdItem = SwrveBuildComponent.GetPostProcessString(SwrveBuildComponent.APP_GROUP_ID_KEY);

        if (string.IsNullOrEmpty(appGroupIdItem))
        {
            SwrveLog.Log(string.Format("No App Group Id Key was set in postprocess file, not adding appgroupconfig.json for {0}", platform));
            return;
        }

        if (string.IsNullOrEmpty(writePath))
        {
            writePath = readPath;
        }

        Dictionary <string, object> groupconfig =
            (Dictionary <string, object>)Json.Deserialize(File.ReadAllText(readPath));

        groupconfig[APP_GROUP_ID_PUBLIC_KEY] = appGroupIdItem;
        File.WriteAllText(writePath, Json.Serialize(groupconfig));
    }
コード例 #5
0
    private static void CorrectXCodeProject(string pathToProject, bool writeOut)
    {
        string path      = Path.Combine(Path.Combine(pathToProject, "Unity-iPhone.xcodeproj"), "project.pbxproj");
        string xcodeproj = File.ReadAllText(path);

        // 1. Make sure it can run on devices and emus!
        xcodeproj = SetValueOfXCodeGroup("SDKROOT", xcodeproj, "\"iphoneos\"");

        // 2. Enable Objective C exceptions
        xcodeproj = xcodeproj.Replace("GCC_ENABLE_OBJC_EXCEPTIONS = NO;", "GCC_ENABLE_OBJC_EXCEPTIONS = YES;");

        // 3. Remove Android content that gets injected in the XCode project
        xcodeproj = Regex.Replace(xcodeproj, @"^.*Libraries/Plugins/Android/SwrveSDKPushSupport.*$", "", RegexOptions.Multiline);

        // 4. Add required frameworks for Conversations
        PBXProject project = new PBXProject();

        project.ReadFromString(xcodeproj);
#if UNITY_2019_3_OR_NEWER
        string targetGuid = project.GetUnityFrameworkTargetGuid();
#else
        string targetGuid = project.TargetGuidByName("Unity-iPhone");
#endif
        project.AddFrameworkToProject(targetGuid, "Webkit.framework", true /*weak*/);

        // 6. Add conversations resources to bundle
        if (!AddFolderToProject(project, targetGuid, "Assets/Plugins/iOS/SwrveConversationSDK/Resources", pathToProject, "Libraries/Plugins/iOS/SwrveConversationSDK/Resources"))
        {
            UnityEngine.Debug.LogError("Swrve SDK - Could not find the Conversation resources folder in your project. If you want to use Conversations please contact [email protected]");
        }

        // 7. Add the required frameworks for push notifications
        project.AddFrameworkToProject(targetGuid, "UserNotifications.framework", true /*weak*/);
        project.AddFrameworkToProject(targetGuid, "UserNotificationsUI.framework", true /*weak*/);

        // 8. Add framework required for SwrveCommmonSDK for SwrveUtils. It needs CoreTelephony.framework
        project.AddFrameworkToProject(targetGuid, "CoreTelephony.framework", false /*weak*/);

        string appGroupIndentifier = SwrveBuildComponent.GetPostProcessString(SwrveBuildComponent.APP_GROUP_ID_KEY);

        if (string.IsNullOrEmpty(appGroupIndentifier))
        {
            SwrveLog.Log("Swrve iOS Rich Push requires an iOSAppGroupIdentifier set in the postprocess.json file. Without it there will be no influence tracking and potential errors.");
        }
        else
        {
            // 8. Add Extension Target for Push
            project = AddExtensionToProject(project, pathToProject);

            // 9. Add Entitlements to project
            project.AddCapability(targetGuid, PBXCapabilityType.AppGroups, null, false);
            project.AddCapability(targetGuid, PBXCapabilityType.PushNotifications, null, false);
        }

        // Write changes to the Xcode project
        xcodeproj = project.WriteToString();
        if (writeOut)
        {
            File.WriteAllText(path, xcodeproj);
        }
    }
コード例 #6
0
    // Enables Advanced Push Capabilities
    private static PBXProject AddExtensionToProject(PBXProject project, string pathToProject)
    {
        PBXProject proj = project;

#if UNITY_2019_3_OR_NEWER
        string mainTarget = proj.GetUnityMainTargetGuid();
#else
        string mainTarget = proj.TargetGuidByName(PBXProject.GetUnityTargetName());
#endif

        // Add Push files to the extension
        CopyFolder("Assets/Plugins/iOS/SwrvePushExtension", pathToProject + "/SwrvePushExtension");

        string extensionTarget = proj.AddAppExtension(mainTarget, "SwrvePushExtension", PlayerSettings.applicationIdentifier + ".ServiceExtension", "SwrvePushExtension/Info.plist");

        // Ensure Service Files are part of the Build Phases
        proj.AddFile(pathToProject + "/SwrvePushExtension/NotificationService.h", "SwrvePushExtension/NotificationService.h");
        proj.AddFileToBuild(extensionTarget, proj.AddFile(pathToProject + "/SwrvePushExtension/NotificationService.m", "SwrvePushExtension/NotificationService.m"));

        // Add TeamID from Player Settings to project
        proj.SetTeamId(extensionTarget, PlayerSettings.iOS.appleDeveloperTeamID);

        // Add Extension Common
        if (!AddFolderToProject(proj, extensionTarget, "Assets/Plugins/iOS/SwrveSDKCommon", pathToProject, "SwrvePushExtension/SwrveSDKCommon"))
        {
            UnityEngine.Debug.LogError("Swrve SDK - Could not find the Common folder in the extension. If you want to use Rich Push please contact [email protected]");
        }

        // Add Frameworks needed for SwrveSDKCommon
        proj.AddFrameworkToProject(extensionTarget, "AudioToolbox.framework", false /*weak*/);
        proj.AddFrameworkToProject(extensionTarget, "AVFoundation.framework", true /*weak*/);
        proj.AddFrameworkToProject(extensionTarget, "CFNetwork.framework", false /*weak*/);
        proj.AddFrameworkToProject(extensionTarget, "CoreGraphics.framework", false /*weak*/);
        proj.AddFrameworkToProject(extensionTarget, "CoreMedia.framework", false /*weak*/);
        proj.AddFrameworkToProject(extensionTarget, "CoreMotion.framework", false /*weak*/);
        proj.AddFrameworkToProject(extensionTarget, "CoreVideo.framework", false /*weak*/);
        proj.AddFrameworkToProject(extensionTarget, "CoreTelephony.framework", false /*weak*/);
        proj.AddFrameworkToProject(extensionTarget, "Foundation.framework", false /*not weak*/);
        proj.AddFrameworkToProject(extensionTarget, "iAd.framework", false /*weak*/);
        proj.AddFrameworkToProject(extensionTarget, "MediaPlayer.framework", true /*weak*/);
        proj.AddFrameworkToProject(extensionTarget, "UIKit.framework", true /*weak*/);
        proj.AddFrameworkToProject(extensionTarget, "AdSupport.framework", false /*not weak*/);

        // Add Notification Frameworks
        proj.AddFrameworkToProject(extensionTarget, "UserNotifications.framework", false /*not weak*/);
        proj.AddFrameworkToProject(extensionTarget, "UserNotificationsUI.framework", false /*not weak*/);

        // Update Build Settings for Compatibility
        proj.AddBuildProperty(extensionTarget, "CLANG_ENABLE_OBJC_ARC", "YES");
        proj.AddBuildProperty(extensionTarget, "IPHONEOS_DEPLOYMENT_TARGET", "10.0");
        proj.AddBuildProperty(extensionTarget, "TARGETED_DEVICE_FAMILY", "1,2");
        proj.AddBuildProperty(extensionTarget, "ARCHS", "$(ARCHS_STANDARD)");

        // Add appgroupconfig.json to XCode project
        string appGroupIndentifier = SwrveBuildComponent.GetPostProcessString(SwrveBuildComponent.APP_GROUP_ID_KEY);
        string appGroupConfig      = "appgroupconfig.json";
        // Add the app group config so it can be read at run-time by the main app and the service extension
        SwrveBuildComponent.SetAppGroupConfigKey("ios", Path.Combine(pathToProject + "/SwrvePushExtension", appGroupConfig));
        proj.AddFileToBuild(extensionTarget, proj.AddFile(pathToProject + "/SwrvePushExtension/" + appGroupConfig, "SwrvePushExtension/" + appGroupConfig));
        proj.AddFileToBuild(mainTarget, proj.AddFile(pathToProject + "/SwrvePushExtension/" + appGroupConfig, "SwrvePushExtension/" + appGroupConfig));

        // Edit template entitlements file
        string entitlementContents = File.ReadAllText(pathToProject + "/SwrvePushExtension/SwrvePushExtension.entitlements");
        entitlementContents = entitlementContents.Replace("<string>APP_GROUP_TEMP</string>", "<string>" + appGroupIndentifier + "</string>");
        File.WriteAllText(pathToProject + "/SwrvePushExtension/SwrvePushExtension.entitlements", entitlementContents);

        // Add entitlements file to service extension
        proj.AddFileToBuild(extensionTarget, proj.AddFile(pathToProject + "/SwrvePushExtension/SwrvePushExtension.entitlements", "SwrvePushExtension/SwrvePushExtension.entitlements"));
        proj.AddCapability(extensionTarget, PBXCapabilityType.AppGroups, "SwrvePushExtension/SwrvePushExtension.entitlements", false);

        // Return edited project
        return(proj);
    }