接入Moloco广告适配器

This commit is contained in:
chenxi 2023-08-09 22:10:47 +08:00
parent 704fc389cb
commit e38ce4e68e
20 changed files with 390 additions and 2 deletions

View File

@ -27,8 +27,8 @@ public class JenkinsAdapter {
// 设置版本号
PlayerSettings.bundleVersion = buildInfo.version;
//Jenkins要求自动构建最低ios8.0
PlayerSettings.iOS.targetOSVersionString = "12.0";
//SDK要求
PlayerSettings.iOS.targetOSVersionString = "13.0";
//设置Build每次需要增加
PlayerSettings.iOS.buildNumber = versionCode.ToString();
// 隐藏ios的横条

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 670c734afec8948daad6b8918af41394
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: af13f2fbe7195455d9536a2fe52da40a
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,42 @@
// https://stackoverflow.com/questions/55492214/the-annotation-for-nullable-reference-types-should-only-be-used-in-code-within-a
#nullable enable
using UnityEngine;
using System;
namespace MolocoSdk
{
public class AndroidDelegate : PlatformDelegate
{
internal const string PACKAGE_PREFIX = "com.moloco.sdk.publisher";
public void SetPrivacy(PrivacySettings privacySettings){
var molocoPrivacyJavaClasspath = "com.moloco.sdk.adapter.MolocoPrivacy";
using (var MolocoPrivacyJavaClass = new AndroidJavaClass(molocoPrivacyJavaClasspath))
using (var privacySettingsJavaObject = new AndroidJavaObject($"{molocoPrivacyJavaClasspath}$PrivacySettings"))
{
privacySettingsJavaObject.Set("isUserConsent", privacySettings.IsUserConsent.ToBooleanJavaObject());
privacySettingsJavaObject.Set("isAgeRestrictedUser", privacySettings.IsAgeRestrictedUser.ToBooleanJavaObject());
privacySettingsJavaObject.Set("isDoNotSell", privacySettings.IsDoNotSell.ToBooleanJavaObject());
MolocoPrivacyJavaClass.CallStatic("setPrivacy", privacySettingsJavaObject);
}
}
}
internal static class BooleanExtensions
{
internal static AndroidJavaObject? ToBooleanJavaObject(this Boolean? me)
{
using (var BooleanJavaClass = new AndroidJavaClass("java.lang.Boolean")){
var trueJavaObject = BooleanJavaClass.GetStatic<AndroidJavaObject>("TRUE");
var falseJavaObject = BooleanJavaClass.GetStatic<AndroidJavaObject>("FALSE");
if (me == true) return trueJavaObject;
if (me == false) return falseJavaObject;
}
return null;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: bdacfb2821b5a4918826f91ba4729b3b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: bffe607feaf904ee290c809158c77c3e
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<dependencies>
<androidPackages>
<androidPackage spec="com.moloco.sdk.adapters:ironsource:1.2.3.0">
</androidPackage>
</androidPackages>
<!-- <iosPods>
<iosPod name="MolocoCustomAdapterIronSource" version="~>1.1.0">
</iosPod>
</iosPods> -->
</dependencies>

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 899fc029e9d4a447982d2cbb27acbb2e
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,37 @@
using UnityEngine;
using System;
namespace MolocoSdk
{
public static class MolocoSDK
{
private static readonly PlatformDelegate platformDelegate;
static MolocoSDK()
{
#if UNITY_ANDROID
platformDelegate = new AndroidDelegate();
#endif
#if UNITY_IOS
platformDelegate = new IOSDelegate();
#endif
}
public static void SetPrivacy(PrivacySettings privacySettings)
{
platformDelegate.SetPrivacy(privacySettings);
}
}
public class PrivacySettings
{
public Boolean? IsUserConsent = null;
public Boolean? IsAgeRestrictedUser = null;
public Boolean? IsDoNotSell = null;
}
interface PlatformDelegate {
void SetPrivacy(PrivacySettings privacySettings);
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5930914c0f5874f3899743518ce73c90
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a6e954e58c56fb2438b5c2f66d8666e8
labels:
- al_max
- al_max_export_path-MaxSdk\Mediation\Moloco
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 426b254cd1fef6e4db1a41f112457ab2
labels:
- al_max
- al_max_export_path-MaxSdk\Mediation\Moloco\Editor
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<dependencies>
<androidPackages>
<androidPackage spec="com.moloco.sdk.adapters:applovin:1.2.3.0">
</androidPackage>
</androidPackages>
<iosPods>
<iosPod name="MolocoCustomAdapterAppLovin" version="1.1.0" />
</iosPods>
</dependencies>

View File

@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: b8ccb62a3dfc260408cd3e5c0301f442
labels:
- al_max
- al_max_export_path-MaxSdk\Mediation\Moloco\Editor\ALMolocoAdapterDependencies.xml
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5a5da0169be5d8043a9f70b3d4e5c4f2
labels:
- al_max
- al_max_export_path-MaxSdk\Mediation\Moloco\Scripts
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5a4d578a58b1e00428f053687d290717
labels:
- al_max
- al_max_export_path-MaxSdk\Mediation\Moloco\Scripts\Editor
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,90 @@
#if UNITY_IOS || UNITY_IPHONE
using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEditor.iOS.Xcode;
using UnityEditor.iOS.Xcode.Extensions;
namespace Moloco.IOS.Scripts.Editor
{
public class MolocoPostProcessBuildiOS
{
#if !UNITY_2019_3_OR_NEWER
private const string UnityMainTargetName = "Unity-iPhone";
#endif
private static readonly List<string> DynamicLibrariesToEmbed = new List<string>
{
"MolocoSDK.xcframework",
"MolocoCustomAdapter.xcframework"
};
private static void EmbedDynamicLibrariesIfNeeded(string buildPath, PBXProject project, string targetGuid)
{
// Check that the Pods directory exists (it might not if a publisher is building with Generate Podfile setting disabled in EDM).
var podsDirectory = Path.Combine(buildPath, "Pods");
if (!Directory.Exists(podsDirectory)) return;
var dynamicLibraryPathsPresentInProject = new List<string>();
foreach (var dynamicLibraryToSearch in DynamicLibrariesToEmbed)
{
// both .framework and .xcframework are directories, not files
var directories =
Directory.GetDirectories(podsDirectory, dynamicLibraryToSearch, SearchOption.AllDirectories);
if (directories.Length <= 0) continue;
var dynamicLibraryAbsolutePath = directories[0];
var index = dynamicLibraryAbsolutePath.LastIndexOf("Pods");
var relativePath = dynamicLibraryAbsolutePath.Substring(index);
dynamicLibraryPathsPresentInProject.Add(relativePath);
}
if (dynamicLibraryPathsPresentInProject.Count <= 0) return;
#if UNITY_2019_3_OR_NEWER
foreach (var dynamicLibraryPath in dynamicLibraryPathsPresentInProject)
{
var fileGuid = project.AddFile(dynamicLibraryPath, dynamicLibraryPath);
project.AddFileToEmbedFrameworks(targetGuid, fileGuid);
}
#else
string runpathSearchPaths;
#if UNITY_2018_2_OR_NEWER
runpathSearchPaths = project.GetBuildPropertyForAnyConfig(targetGuid, "LD_RUNPATH_SEARCH_PATHS");
#else
runpathSearchPaths = "$(inherited)";
#endif
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
}
[PostProcessBuildAttribute(int.MaxValue)]
public static void MolocoPostProcessPbxProject(BuildTarget buildTarget, string buildPath)
{
var projectPath = PBXProject.GetPBXProjectPath(buildPath);
var project = new PBXProject();
project.ReadFromFile(projectPath);
#if UNITY_2019_3_OR_NEWER
var unityMainTargetGuid = project.GetUnityMainTargetGuid();
var unityFrameworkTargetGuid = project.GetUnityFrameworkTargetGuid();
#else
var unityMainTargetGuid = project.TargetGuidByName(UnityMainTargetName);
var unityFrameworkTargetGuid = project.TargetGuidByName(UnityMainTargetName);
#endif
EmbedDynamicLibrariesIfNeeded(buildPath, project, unityMainTargetGuid);
project.WriteToFile(projectPath);
}
}
}
#endif

View File

@ -0,0 +1,14 @@
fileFormatVersion: 2
guid: c29941b1bf9c06a498d360afd9b42404
labels:
- al_max
- al_max_export_path-MaxSdk\Mediation\Moloco\Scripts\Editor\MolocoPostProcessBuildiOS.cs
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,63 @@
#if UNITY_IOS || UNITY_IPHONE
using System.IO;
using System.Linq;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEngine;
namespace Moloco.Scripts.Editor
{
public class PodfileEditor
{
[PostProcessBuild(45)] // Add to the Podfile after it's generated (40) but before "pod install" (50)
public static void OnPostProcessBuild(BuildTarget buildTarget, string pathToBuiltProject)
{
if (buildTarget != BuildTarget.iOS)
{
return;
}
string podfilePath = Path.Combine(pathToBuiltProject, "Podfile");
if (File.Exists(podfilePath))
{
var codeSigningStyle = PlayerSettings.iOS.appleEnableAutomaticSigning ? "Automatic" : "Manual";
var teamId = PlayerSettings.iOS.appleDeveloperTeamID;
var provisioningProfileId = PlayerSettings.iOS.iOSManualProvisioningProfileID;
var provisioningProfileType = PlayerSettings.iOS.iOSManualProvisioningProfileType;
string[] molocoTargets =
{
"MolocoSDKiOS-MolocoSDK",
"MolocoCustomAdapter-MolocoCustomAdapter",
"MolocoCustomAdapterAppLovin-MolocoCustomAdapterAppLovin",
"MolocoCustomAdapterIronSource-MolocoCustomAdapterIronSource"
};
var molocoTargetsString = string.Join(", ", molocoTargets.Select(element => $"'{element}'"));
using var sw = File.AppendText(podfilePath);
sw.WriteLine("\n\n\npost_install do |installer|");
sw.WriteLine(" installer.pods_project.targets.each do |target|");
sw.WriteLine(" target.build_configurations.each do |config|");
sw.WriteLine(" if [" + molocoTargetsString + "].include? target.name");
sw.WriteLine(" config.build_settings['CODE_SIGN_STYLE'] = '" + codeSigningStyle + "'");
sw.WriteLine(" config.build_settings['DEVELOPMENT_TEAM'] = '" + teamId + "'");
if (!PlayerSettings.iOS.appleEnableAutomaticSigning)
{
sw.WriteLine(" config.build_settings['PROVISIONING_PROFILE_APP'] = '" + provisioningProfileId + "\'");
}
sw.WriteLine(" end");
sw.WriteLine(" end");
sw.WriteLine(" end");
sw.WriteLine("end");
}
else
{
Debug.LogWarning("Podfile not found in the Xcode project.");
}
}
}
}
#endif

View File

@ -0,0 +1,14 @@
fileFormatVersion: 2
guid: f16af8bc1a3477645ad5e39ea50117c4
labels:
- al_max
- al_max_export_path-MaxSdk\Mediation\Moloco\Scripts\Editor\PodfileEditor.cs
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: