Skip to content

Commit 47d230f

Browse files
Mobile Ads Developer Relationscopybara-github
authored andcommitted
Add support for building from source with preview features.
PiperOrigin-RevId: 791274969
1 parent 8eb80d4 commit 47d230f

16 files changed

+282
-0
lines changed

source/plugin/Assets/GoogleMobileAds/Api/MobileAds.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,18 @@ public static void OpenAdInspector(Action<AdInspectorError> adInspectorClosedAct
283283
});
284284
}
285285

286+
public static void HelloWorld()
287+
{
288+
Instance.client.HelloWorld();
289+
}
290+
291+
#if GMA_PREVIEW_FEATURES
292+
public static void HelloWorldPreview()
293+
{
294+
Instance.client.HelloWorldPreview();
295+
}
296+
#endif
297+
286298
internal static IClientFactory GetClientFactory() {
287299
if (clientFactory == null) {
288300
String typeName = null;

source/plugin/Assets/GoogleMobileAds/Common/IMobileAdsClient.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,11 @@ void Preload(List<PreloadConfiguration> configurations,
7777
/// </summary>
7878
/// <param name="onAdInspectorClosed">Called when ad inspector UI closes.</param>
7979
void OpenAdInspector(Action<AdInspectorErrorClientEventArgs> adInspectorClosedAction);
80+
81+
void HelloWorld();
82+
83+
#if GMA_PREVIEW_FEATURES
84+
void HelloWorldPreview();
85+
#endif
8086
}
8187
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using UnityEditor;
2+
using UnityEditor.Build;
3+
using UnityEditor.Build.Reporting;
4+
using UnityEditor.iOS.Xcode;
5+
6+
namespace GoogleMobileAds.Editor
7+
{
8+
public class BuildPostProcessor: IPostprocessBuildWithReport
9+
{
10+
11+
public int callbackOrder { get { return 1; } }
12+
13+
public void OnPostprocessBuild(BuildReport report)
14+
{
15+
if (report.summary.platform != BuildTarget.iOS)
16+
{
17+
return;
18+
}
19+
20+
string projectPath = PBXProject.GetPBXProjectPath(report.summary.outputPath);
21+
var project = new PBXProject();
22+
project.ReadFromFile(projectPath);
23+
string unityFrameworkTargetGuid = project.GetUnityFrameworkTargetGuid();
24+
string scriptingDefineSymbols = PlayerSettings.GetScriptingDefineSymbolsForGroup(
25+
BuildTargetGroup.iOS);
26+
bool isPreviewEnabled = scriptingDefineSymbols.Contains("GMA_PREVIEW_FEATURES");
27+
28+
if (isPreviewEnabled)
29+
{
30+
// This is equivalent to adding `-DGMA_PREVIEW_FEATURES=1` to the compiler flags.
31+
project.AddBuildProperty(unityFrameworkTargetGuid,
32+
"GCC_PREPROCESSOR_DEFINITIONS",
33+
"GMA_PREVIEW_FEATURES=1");
34+
35+
UnityEngine.Debug.Log("GMA Preview Features enabled for iOS build.");
36+
}
37+
38+
project.WriteToFile(projectPath);
39+
}
40+
}
41+
}

source/plugin/Assets/GoogleMobileAds/Editor/BuildPostProcessor.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

source/plugin/Assets/GoogleMobileAds/Platforms/Android/MobileAdsClient.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,18 @@ public Version GetSDKVersion()
146146
return new Version(versionString);
147147
}
148148

149+
public void HelloWorld()
150+
{
151+
Debug.Log("Hello from MobileAdsClient!");
152+
}
153+
154+
#if GMA_PREVIEW_FEATURES
155+
public void HelloWorldPreview()
156+
{
157+
Debug.Log("Hello from MobileAdsClient Preview!");
158+
}
159+
#endif
160+
149161
#region Callbacks from OnInitializationCompleteListener.
150162

151163
public void onInitializationComplete(AndroidJavaObject initStatus)

source/plugin/Assets/GoogleMobileAds/Platforms/Unity/MobileAdsClient.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,5 +219,17 @@ public void DestroyAdInspector()
219219
AdBehaviour.DestroyAd(dummyAd);
220220
prefabAd = null;
221221
}
222+
223+
public void HelloWorld()
224+
{
225+
Debug.Log("Hello from MobileAdsClient!");
226+
}
227+
228+
#if GMA_PREVIEW_FEATURES
229+
public void HelloWorldPreview()
230+
{
231+
Debug.Log("Hello from MobileAdsClient!");
232+
}
233+
#endif
222234
}
223235
}

source/plugin/Assets/GoogleMobileAds/Platforms/iOS/Externs.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -966,6 +966,15 @@ internal static extern IntPtr GADUAdapterResponseInfoAdError(
966966
internal static extern string GADUAdapterResponseInfoDescription(IntPtr error);
967967

968968
#endregion
969+
970+
[DllImport("__Internal")]
971+
internal static extern void HelloWorld();
972+
973+
#if GMA_PREVIEW_FEATURES
974+
[DllImport("__Internal")]
975+
internal static extern void HelloWorldPreview();
976+
#endif
977+
969978
}
970979
}
971980
#endif

source/plugin/Assets/GoogleMobileAds/Platforms/iOS/MobileAdsClient.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,18 @@ public void OpenAdInspector(Action<AdInspectorErrorClientEventArgs> onAdInspecto
145145
Externs.GADUPresentAdInspector(this.mobileAdsClientPtr, AdInspectorClosedCallback);
146146
}
147147

148+
public void HelloWorld()
149+
{
150+
Externs.HelloWorld();
151+
}
152+
153+
#if GMA_PREVIEW_FEATURES
154+
public void HelloWorldPreview()
155+
{
156+
Externs.HelloWorldPreview();
157+
}
158+
#endif
159+
148160
[MonoPInvokeCallback(typeof(GADUAdAvailableCallback))]
149161
private static void AdAvailableCallback(IntPtr mobileAdsClient, IntPtr config)
150162
{
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
#import <Foundation/Foundation.h>
3+
4+
@interface TestPlugin : NSObject
5+
6+
+ (void)HelloWorld;
7+
8+
@end

source/plugin/Assets/Plugins/iOS/TestPlugin.h.meta

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)