Unity3D Exclude AdMob files for Windows Phone Export

128 views
Skip to first unread message

Binoj Daniel

unread,
Dec 29, 2015, 7:53:48 AM12/29/15
to Google Mobile Ads SDK Developers
How can i exclude GoogleMobileAds unity plugin files from being exported as part of the Windows Phone 8.1 Export?

I noticed in some files there are #if compilation directives.

Veer Arjun Busani

unread,
Dec 29, 2015, 10:50:51 AM12/29/15
to Google Mobile Ads SDK Developers
Hi Binoj,

Unfortunately, Unity does not support excluding certain packages or libraries from the build. But there is a workaround - 
  • The Unity compiler has a feature called Platform Dependent Compilation, which you can use to not have Ads running on certain platforms. For example - 
        #if UNITY_EDITOR
            string adUnitId = "unused";
        #elif UNITY_ANDROID
        string adUnitId = "ca-app-pub-33XXXXXXXX05/130XXXXXXX5";
        #elif UNITY_WSA_8_1
            string adUnitId = "unexpected_platform"; // Do not include you Ad Unit ID here
        #else
            string adUnitId = "unexpected_platform";
        #endif
This would essentially not show the Ads on those marked platforms. While there are other suggestions you can use, this would be the ideal way to not to have AdMob running on you Windows Phone platform.

Thanks,
Veer Arjun Busani
Mobile Ads SDK Team

Binoj Daniel

unread,
Dec 29, 2015, 11:02:51 AM12/29/15
to google-adm...@googlegroups.com
I noticed this but this still copies all the plugin files under a separate c# project when i export Windows Phone 8.1 project from Unity.
And due to this App certification fails.



Thanks,

Binoj Daniel
CouncilSoft Design Studio
DESIGN | BUILD | PROMOTE

Phone:
 +1-215-801-6036
Skype: CouncilSoft

Free Windows Bible App: www.BiblePronto.com
Technology Reviews: www.CodeRewind.com



--

---
You received this message because you are subscribed to a topic in the Google Groups "Google Mobile Ads SDK Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-admob-ads-sdk/AQkVgPvWwH8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-admob-ads...@googlegroups.com.
To post to this group, send email to google-adm...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Veer Arjun Busani

unread,
Dec 29, 2015, 11:37:23 AM12/29/15
to Google Mobile Ads SDK Developers
Hi Binoj,

Like I suggested the other workaround would be to build a script to move the package depending on the platform. For example, use the same macros to determine the platform and then delete them manually. I also found this discussion, which also contains certain pseudo code, that might be helpful in your case.

Binoj Daniel

unread,
Dec 29, 2015, 11:42:59 AM12/29/15
to google-adm...@googlegroups.com
AdMob plugin is not a single dll. There are class files also. That thread is not at all clear on how to handle it.


Thanks,

Binoj Daniel
CouncilSoft Design Studio
DESIGN | BUILD | PROMOTE

Phone:
 +1-215-801-6036
Skype: CouncilSoft

Free Windows Bible App: www.BiblePronto.com
Technology Reviews: www.CodeRewind.com



--

Veer Arjun Busani

unread,
Dec 29, 2015, 2:21:13 PM12/29/15
to Google Mobile Ads SDK Developers
Hi Binoj,

The referred discussion was only meant as an example. In your case I would suggest you either completely delete the plugins folder or move it temporarily.  
  • One way would be to remove both the plugins folder (Assets/GoogleMobileAds and Assets/Plugins) manually while building for Windows Phone. This way you know that they won't be included in the build.
  • Next would be to use a source control system, like GIT and then branch out the Windows Mobile build while including the Mobile Ads Unity plugin. This would be an ideal way to essentially separate out the plugin from the other platforms.
  • The other would be to write a script to delete or to move the plugin folders. For example - 
  • Declare your variables
private static string googleMobileAdsLocation = Application.dataPath + "/GoogleMobileAds";
private static string googleAdMobPluginsLocation = Application.dataPath + "/Plugins";
  • Delete them like this
    #if UNITY_EDITOR
    string adUnitId = "unused";
    #elif UNITY_ANDROID

    string adUnitId = "ca-app-pub-610XXXXXX4/330XXXXXX67";
    #else
    FileUtil.DeleteFileOrDirectory (googleMobileAdsLocation);
    FileUtil.DeleteFileOrDirectory (googleAdMobPluginsLocation);
    #endif
Do let us know if this works for you.

Binoj Daniel

unread,
Dec 29, 2015, 2:37:44 PM12/29/15
to google-adm...@googlegroups.com
ok, im going to try this. And where am i going to run or attach this script? On the export settings for windows?


Thanks,

Binoj Daniel
CouncilSoft Design Studio
DESIGN | BUILD | PROMOTE

Phone:
 +1-215-801-6036
Skype: CouncilSoft

Free Windows Bible App: www.BiblePronto.com
Technology Reviews: www.CodeRewind.com



--

Binoj Daniel

unread,
Dec 29, 2015, 2:40:12 PM12/29/15
to google-adm...@googlegroups.com
So i will have to delete the folders on windows phone and then same script copies it back to the same place after export is done?

Veer Arjun Busani

unread,
Dec 29, 2015, 4:06:29 PM12/29/15
to Google Mobile Ads SDK Developers
Hi Binoj,

The third option can be done using Player Build Pipeline. Basically, this is used to build your project for different platforms using Editor script. Essentially you can include pre and post build conditions. For instance - 
  • In one of the scripts (lets say Menu.cs), first include these frameworks - 
using System;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
using System.IO;
  • Then you need to create a Menu Item. Essentially, this is done to make a build from the editor itself without actually using the File -> Build & Run. Once you have imported the essentials, use this code - 

#if UNITY_EDITOR

    private static string googleMobileAdsLocation = Application.dataPath + "/GoogleMobileAds";

    private static string googleMobileAdsLocationNew = Application.dataPath + "/Temp/GoogleMobileAds";


    private static string googleAdMobPluginsLocation = Application.dataPath + "/Plugins";

    private static string googleAdMobPluginsLocationNew = Application.dataPath + "/Temp/Plugins";

    private static string m_sBuildPath =  Application.dataPath + "/Build/Test.apk";
    private static string[] m_Scenes = { "Assets/Main.unity" };

    [MenuItem("Tools/Build for Android")]
    private static void NewMenuOption()
    {
        //rename the file by moving it
        File.Move(googleMobileAdsLocation, googleMobileAdsLocationNew);
        File.Move(googleAdMobPluginsLocation, googleAdMobPluginsLocationNew);

        //re-import the database
        AssetDatabase.Refresh();

        //build the file
        BuildOptions Options = BuildOptions.None;
        BuildPipeline.BuildPlayer(m_Scenes, m_sBuildPath, BuildTarget.Android, Options);

        //rename back
        File.Move(googleMobileAdsLocationNew, googleMobileAdsLocation);
        File.Move(googleAdMobPluginsLocationNew, googleAdMobPluginsLocation);

        //re re-import the database
        AssetDatabase.Refresh();
    }
    #endif
  • Notice in the code that both the folders GoogleMobileAds and Plugins are actually moved using File.Move. You can create your own path to ensure that it does not get included in the build directory. It could be like Application.dataPath + "/../Test/";. Essentially one step down from the Assets folder.
  • Note that is for Android build but you can replace the BuildTarget to any other platform and the m_sBuildPath  to Test.exe. Do ensure that you actually create those Temp directories manually.
  • Once that is done, simply run the script in the editor and now you would find a menu item being added at Tools -> Build for Android.
  • If for some reason the compiler says unable to copy or file/directory does not exist, you find your complete build in ~path-to-project/Temp/Staging Area/. 
You could also read about Player Build Pipeline here.

Binoj Daniel

unread,
Dec 29, 2015, 5:09:07 PM12/29/15
to google-adm...@googlegroups.com
Thanks Veer this is surely more helpful. Now, if I use this approach to build for windows platform. Will it use retain and use all the player settings including all the graphics assets i uploaded to the player settings for windows?


Thanks,

Binoj Daniel
CouncilSoft Design Studio
DESIGN | BUILD | PROMOTE

Phone:
 +1-215-801-6036
Skype: CouncilSoft

Free Windows Bible App: www.BiblePronto.com
Technology Reviews: www.CodeRewind.com



Veer Arjun Busani

unread,
Dec 29, 2015, 5:22:57 PM12/29/15
to Google Mobile Ads SDK Developers
Hi Binoj,

Yes. Just make sure that you include all of the scenes that you wanna have in the string[] m_Scenes = { "Assets/Main.unity" }; array. The folders that you won't be having in the build are Assets/GoogleMobileAds and Assets/Plugins. The code removes them before you call the BuildPipeline.BuildPlayer and moves them back to the Assets folder once done. 

Also in any of the script files that uses the Mobile Ads plugin, just make sure you use the compiler macros to run only for those specific platforms.

Do let us know how it went.

Binoj Daniel

unread,
Dec 29, 2015, 9:14:02 PM12/29/15
to google-adm...@googlegroups.com
I tried the script. I see some moving activity of the plugin folder. But not the other. And i do not see anything in the build destination folder.


Thanks,

Binoj Daniel
CouncilSoft Design Studio
DESIGN | BUILD | PROMOTE

Phone:
 +1-215-801-6036
Skype: CouncilSoft

Free Windows Bible App: www.BiblePronto.com
Technology Reviews: www.CodeRewind.com



--

Veer Arjun Busani

unread,
Dec 30, 2015, 10:40:22 AM12/30/15
to Google Mobile Ads SDK Developers
Hi Binoj,

I have been testing on a Mac and was able to successfully create builds for Android and iOS. You could simply do this - 
  • Create a folder named Android in the Assets. I would also suggest you first try and simply build the player without any pre or post build conditions. And -
BuildPipeline.BuildPlayer(m_Scenes, "Android", BuildTarget.Android, Options);
  • There is also a guideline on how to do so in Windows. Another one using Version Control System for iOS, which also could be useful.
  • Apart from this, it also might be more efficient if you were to rename the plugin itself by looping through the file names and removing the extensions. And post build, rename them back.
You could get the file names like this - 
DirectoryInfo dir = new DirectoryInfo(googleMobileAdsLocation);
FileInfo[] info = dir.GetFiles("*.*");
foreach (FileInfo f in info) {
}
And then use AssetDatabase to rename them.
Do try to see if there are any more discussion here as this is more related to Unity then the SDK implementation.

Binoj Daniel

unread,
Dec 30, 2015, 11:02:00 AM12/30/15
to google-adm...@googlegroups.com
I think you pointed out the problem. I'm using Unity Personal. I m not going to venture into pro until i see my first game doing good.
Thanks for all your help.


Thanks,

Binoj Daniel
CouncilSoft Design Studio
DESIGN | BUILD | PROMOTE

Phone:
 +1-215-801-6036
Skype: CouncilSoft

Free Windows Bible App: www.BiblePronto.com
Technology Reviews: www.CodeRewind.com



--
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages