Example #1
0
    // Each platform SDK has a file that contains a version string constant which identifies the current build.
    // We append a suffix to this version string to identify that the platform SDK is being used from Unity rather
    // than standalone.
    private static bool AppendUnityVersion(BuildTarget buildTarget, bool internalSdkBuild)
    {
        Debug.Log("Appending Unity marker to MoPub platform SDK version string");
        var file  = Path.Combine(GetSdkSubdir(buildTarget, internalSdkBuild), FileWithVersionNumber[buildTarget]);
        var regex = RegexForVersionLine[buildTarget];
        var repl  = "+" + GetSdkVersionSuffix(buildTarget, internalSdkBuild);

        return(OS.Sed(file, regex, repl));
    }
Example #2
0
    public static void DoSDKMigration()
    {
        Debug.Log(MigrationBegin);

        if (DoesExist(RedundantDir))
        {
            OS.RmDir(RedundantDir);
        }
        if (DoesExist(RedundantJar))
        {
            OS.Rm(RedundantJar);
            var redundantJarDir         = RedundantJar.Remove(RedundantJar.LastIndexOf("/", StringComparison.Ordinal)) + "/";
            var redundantJarDirContents = OS.GetFileSystemEntries(redundantJarDir);
            if (!redundantJarDirContents.Any())
            {
                OS.RmDir(redundantJarDir);
            }
        }

        var allSucceeded = true;

        foreach (var entry in LocationMapping)
        {
            var source = Path.Combine("Assets", entry.Key);
            var dest   = Path.Combine("Assets", entry.Value);
            if (!DoesExist(source))
            {
                continue;
            }
            allSucceeded &= OS.Mv(source, dest);
        }

        bool showNote      = false;
        var  migrationNote = new StringBuilder(ManualMigrationNote);

        foreach (var entry in ManualMapping)
        {
            if (DoesExist(Path.Combine("Assets", entry.Key)))
            {
                showNote = true;
                migrationNote.Append(string.Format("'{0}' to '{1}'\n", entry.Key, entry.Value));
            }
        }
        if (showNote)
        {
            Debug.LogWarning(migrationNote);
        }

        if (!allSucceeded)
        {
            Debug.LogWarning(ManualFollowUpWarning);
        }
        AssetDatabase.Refresh();
        Debug.Log(MigrationEnd);
    }
    // The suffix to add to the platform MoPub SDK's version string.  For public builds this is simply "unity".  For
    // internal development builds, it is the git commit (short) SHA that we are building against.
    private static string GetSdkVersionSuffix(BuildTarget buildTarget, bool internalSdkBuild)
    {
        if (!internalSdkBuild)
        {
            return("unity");
        }
        // cd to appropriate git submodule directory and get the (shortened) SHA of the latest commit
        var dir     = GetSdkSubdir(buildTarget, internalSdkBuild);
        var githash = OS.RunForOutput("git", "rev-parse --short HEAD", dir) ?? "unknown";

        return(githash.Trim());
    }
    // Build the platform MoPub SDK using its native build system.
    private static bool BuildPlatformSdk(BuildTarget buildTarget, bool internalSdkBuild, bool debug)
    {
        Debug.LogFormat("Building MoPub platform SDK for {0} (internal: {1}, debug: {2})", buildTarget, internalSdkBuild, debug);
        switch (buildTarget)
        {
        case BuildTarget.Android:
#if UNITY_EDITOR_OSX
            const string cmd     = "bash";
            const string gradlew = "gradlew";
#elif UNITY_EDITOR_WIN
            const string cmd     = "cmd";
            const string gradlew = "/c gradlew.bat";
#endif // UNITY_EDITOR_OSX
            var sdkDir = GetSdkSubdir(buildTarget, internalSdkBuild);
            return(OS.Run(cmd, string.Format("{0} clean assemble{1}", gradlew, debug ? "Debug" : "Release"),
                          GetFullPath("mopub-android-sdk-unity"),
                          "SDK_DIR=" + Path.GetFileName(sdkDir),
                          "ANDROID_HOME=" + EditorPrefs.GetString("AndroidSdkRoot")));

#if UNITY_EDITOR_OSX
        case BuildTarget.iOS:
            var project = "mopub-ios-sdk-unity.xcodeproj";
            if (internalSdkBuild)
            {
                project = "internal-" + project;
            }
            var jsfile = GetFullPath("mopub-ios-sdk-unity/bin/MoPubSDKFramework.framework/MRAID.bundle/mraid.js");
            return(OS.Run("xcrun",
                          "xcodebuild"
                          + " -project " + project
                          + " -scheme \"MoPub for Unity\""
                          + " -configuration \"" + (debug ? "Debug" : "Release") + "\""
                          + " OTHER_CFLAGS=\"-fembed-bitcode -w\""
                          + " BITCODE_GENERATION_MODE=bitcode"
                          + " clean build",
                          GetFullPath("mopub-ios-sdk-unity"))
                   // Have to rename the .js file inside the framework so that Unity doesn't try to compile it...
                   // This rename is reverted in the MoPubPostBuildiOS script during an app build.
                   && OS.Mv(jsfile, jsfile + ".prevent_unity_compilation"));
#endif // UNITY_EDITOR_OSX
        default:
            Debug.LogError("Invalid build target: " + buildTarget);
            return(false);
        }
    }
Example #5
0
    public static void DoMigration()
    {
        Debug.Log(MigrationBegin);

        if (Directory.Exists(RedundantDir))
        {
            OS.RmDir(RedundantDir);
        }

        var allSucceeded = true;

        foreach (var entry in LocationMapping)
        {
            var source = Path.Combine("Assets", entry.Key);
            var dest   = Path.Combine("Assets", entry.Value);
            if (!DoesExist(source))
            {
                continue;
            }
            allSucceeded &= OS.Mv(source, dest);
        }

        bool showNote      = false;
        var  migrationNote = new StringBuilder(ManualMigrationNote);

        foreach (var entry in ManualMapping)
        {
            if (DoesExist(Path.Combine("Assets", entry.Key)))
            {
                showNote = true;
                migrationNote.Append(string.Format("'{0}' to '{1}'\n", entry.Key, entry.Value));
            }
        }
        if (showNote)
        {
            Debug.LogWarning(migrationNote);
        }

        if (!allSucceeded)
        {
            Debug.LogWarning(ManualFollowUpWarning);
        }
        AssetDatabase.Refresh();
        Debug.Log(MigrationEnd);
    }
    private static bool CopyBuildArtifacts(BuildTarget buildTarget, bool internalSdkBuild, bool debug)
    {
        Debug.Log("Copying MoPub libraries to Unity project");
        var sdkDir = GetSdkSubdir(buildTarget, internalSdkBuild);

        switch (buildTarget)
        {
        case BuildTarget.Android: {
            const string destDir = "Assets/MoPub/Plugins/Android/MoPub.plugin";
            // Our wrapper jar.
            var jarDir = debug ? "debug" : "release";
            if (!OS.Cp(GetFullPath("mopub-android-sdk-unity/build/intermediates/bundles/" + jarDir + "/classes.jar"),
                       Path.Combine(destDir, "libs/mopub-unity-wrappers.jar")))
            {
                return(false);
            }
            // Platform SDK jars.
            var libCps = from lib in new[] { "base", "banner", "interstitial", "rewardedvideo", "native-static" }
            let src    = string.Format("{0}/mopub-sdk/mopub-sdk-{1}/build/intermediates/bundles/{2}/classes.jar",
                                       sdkDir, lib, jarDir)
                         let dst = string.Format("{0}/libs/mopub-sdk-{1}.jar", destDir, lib)
                                   select OS.Cp(src, dst);

            if (libCps.Contains(false))
            {
                return(false);
            }
            return(true);
        }

#if UNITY_EDITOR_OSX
        case BuildTarget.iOS: {
            const string destDir = "Assets/MoPub/Plugins/iOS";
            var          projDir = GetFullPath("mopub-ios-sdk-unity/bin");
            var          htmlDir = Path.Combine(sdkDir, "MoPubSDK/Resources");
            return(OS.Rsync(projDir, destDir, "*.h", "*.m", "*.mm", "*.framework") &&
                   OS.Rsync(htmlDir, Path.Combine(destDir, "MoPubSDKFramework.framework"), "*.html", "*.png"));
        }
#endif // UNITY_EDITOR_OSX
        default:
            Debug.LogError("Invalid build target: " + buildTarget);
            return(false);
        }
    }