适用于 Unity 的 Facebook Audience Network SDK
Facebook Audience Network SDK for Unity
我将 Unity Audience Network SDK 5.4.1
包导入到 unity,任何版本,它给我这个错误:
Assets\AudienceNetwork\Editor\AudienceNetworkPostprocess.cs(25,23): error CS0234: The type or namespace name 'iOS' does not exist in the namespace 'UnityEditor' (are you missing an assembly reference?)
如果我删除 ios 部分并尝试仅在 android 上工作 - 没有任何效果,我尝试播放奖励场景但出现此错误:
NullReferenceException: Object reference not set to an instance of an object
AudienceNetwork.Utility.AdUtility.IsInitialized () (at Assets/AudienceNetwork/Library/AdUtility.cs:50)
RewardedVideoAdScene.Awake () (at Assets/AudienceNetwork/Scenes/RewardedVideo/RewardedVideoAdScene.cs:21)
有没有办法让它工作?我做错了什么或遗漏了什么吗?
以前的插件有效吗?有任何链接吗?
谢谢。
不知道你删除了什么,第二个问题很难解决......
我们只能说它指的是行51
AndroidJavaObject context = currentActivity.Call<AndroidJavaObject>("getApplicationContext");
如果在 PC 上执行,currentActivity
最有可能是 null
,因为 50
行就在
之前
AndroidJavaObject currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
在这种情况下可能不起作用。
第一个听起来像 "bug"。
您可以使用 #if
pre-processors with UNITY_IOS
作为修补程序,至少可以像
那样消除编译器错误
/**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
* copy, modify, and distribute this software in source code or binary form for use
* in connection with the web services and APIs provided by Facebook.
*
* As with any software that integrates with the Facebook platform, your use of
* this software is subject to the Facebook Developer Principles and Policies
* [http://developers.facebook.com/policy/]. This copyright notice shall be
* included in all copies or substantial portions of the software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
namespace AudienceNetwork.Editor
{
using System.IO;
using UnityEditor;
using UnityEditor.Callbacks;
#if UNITY_IOS
using UnityEditor.iOS.Xcode;
#endif
using UnityEngine;
public static class XCodePostProcess
{
public static string AudienceNetworkFramework = "FBAudienceNetwork.framework";
public static string AudienceNetworkAAR = "AudienceNetwork.aar";
public static string FrameworkDependenciesKey = "FrameworkDependencies";
public static string RequiredFrameworks = "AdSupport;StoreKit;WebKit";
[PostProcessBuild(100)]
public static void OnPostProcessBuild(BuildTarget target, string path)
{
#if UNITY_IOS
if (target == BuildTarget.iOS) {
string projectPath = PBXProject.GetPBXProjectPath(path);
PBXProject project = new PBXProject();
project.ReadFromString(File.ReadAllText(projectPath));
string targetName = PBXProject.GetUnityTargetName();
string targetGUID = project.TargetGuidByName(targetName);
project.AddFrameworkToProject(targetGUID, "AdSupport.framework", false);
project.AddFrameworkToProject(targetGUID, "StoreKit.framework", false);
project.AddFrameworkToProject(targetGUID, "WebKit.framework", false);
File.WriteAllText(projectPath, project.WriteToString());
}
#endif
PluginImporter[] importers = PluginImporter.GetAllImporters();
PluginImporter iOSPlugin = null;
PluginImporter androidPlugin = null;
foreach (PluginImporter importer in importers)
{
if (importer.assetPath.Contains(AudienceNetworkFramework))
{
iOSPlugin = importer;
Debug.Log("Audience Network iOS plugin found at " + importer.assetPath + ".");
}
else if (importer.assetPath.Contains(AudienceNetworkAAR))
{
androidPlugin = importer;
Debug.Log("Audience Network Android plugin found at " + importer.assetPath + ".");
}
}
if (iOSPlugin != null)
{
iOSPlugin.SetCompatibleWithAnyPlatform(false);
iOSPlugin.SetCompatibleWithEditor(false);
iOSPlugin.SetCompatibleWithPlatform(BuildTarget.iOS, true);
iOSPlugin.SetPlatformData(BuildTarget.iOS, FrameworkDependenciesKey, RequiredFrameworks);
iOSPlugin.SaveAndReimport();
}
if (androidPlugin != null)
{
androidPlugin.SetCompatibleWithAnyPlatform(false);
androidPlugin.SetCompatibleWithEditor(false);
androidPlugin.SetCompatibleWithPlatform(BuildTarget.Android, true);
androidPlugin.SaveAndReimport();
}
}
}
}
不过,不保证这会解决您的所有问题。
Google Ads 有类似的错误并使用了相同的修补程序。
否则您可能需要考虑安装 IOS 构建支持,我想这也会使错误消失(但不必要地填充磁盘 space 当然,如果您只想构建Android)
解决方法: in AdUtility.cs 添加:
"#if UNITY_ANDROID && !UNITY_EDITOR"
internal static bool IsInitialized()
{
#if UNITY_ANDROID && !UNITY_EDITOR
AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
我将 Unity Audience Network SDK 5.4.1
包导入到 unity,任何版本,它给我这个错误:
Assets\AudienceNetwork\Editor\AudienceNetworkPostprocess.cs(25,23): error CS0234: The type or namespace name 'iOS' does not exist in the namespace 'UnityEditor' (are you missing an assembly reference?)
如果我删除 ios 部分并尝试仅在 android 上工作 - 没有任何效果,我尝试播放奖励场景但出现此错误:
NullReferenceException: Object reference not set to an instance of an object AudienceNetwork.Utility.AdUtility.IsInitialized () (at Assets/AudienceNetwork/Library/AdUtility.cs:50) RewardedVideoAdScene.Awake () (at Assets/AudienceNetwork/Scenes/RewardedVideo/RewardedVideoAdScene.cs:21)
有没有办法让它工作?我做错了什么或遗漏了什么吗? 以前的插件有效吗?有任何链接吗? 谢谢。
不知道你删除了什么,第二个问题很难解决......
我们只能说它指的是行51
AndroidJavaObject context = currentActivity.Call<AndroidJavaObject>("getApplicationContext");
如果在 PC 上执行,currentActivity
最有可能是 null
,因为 50
行就在
AndroidJavaObject currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
在这种情况下可能不起作用。
第一个听起来像 "bug"。
您可以使用 #if
pre-processors with UNITY_IOS
作为修补程序,至少可以像
/**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
* copy, modify, and distribute this software in source code or binary form for use
* in connection with the web services and APIs provided by Facebook.
*
* As with any software that integrates with the Facebook platform, your use of
* this software is subject to the Facebook Developer Principles and Policies
* [http://developers.facebook.com/policy/]. This copyright notice shall be
* included in all copies or substantial portions of the software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
namespace AudienceNetwork.Editor
{
using System.IO;
using UnityEditor;
using UnityEditor.Callbacks;
#if UNITY_IOS
using UnityEditor.iOS.Xcode;
#endif
using UnityEngine;
public static class XCodePostProcess
{
public static string AudienceNetworkFramework = "FBAudienceNetwork.framework";
public static string AudienceNetworkAAR = "AudienceNetwork.aar";
public static string FrameworkDependenciesKey = "FrameworkDependencies";
public static string RequiredFrameworks = "AdSupport;StoreKit;WebKit";
[PostProcessBuild(100)]
public static void OnPostProcessBuild(BuildTarget target, string path)
{
#if UNITY_IOS
if (target == BuildTarget.iOS) {
string projectPath = PBXProject.GetPBXProjectPath(path);
PBXProject project = new PBXProject();
project.ReadFromString(File.ReadAllText(projectPath));
string targetName = PBXProject.GetUnityTargetName();
string targetGUID = project.TargetGuidByName(targetName);
project.AddFrameworkToProject(targetGUID, "AdSupport.framework", false);
project.AddFrameworkToProject(targetGUID, "StoreKit.framework", false);
project.AddFrameworkToProject(targetGUID, "WebKit.framework", false);
File.WriteAllText(projectPath, project.WriteToString());
}
#endif
PluginImporter[] importers = PluginImporter.GetAllImporters();
PluginImporter iOSPlugin = null;
PluginImporter androidPlugin = null;
foreach (PluginImporter importer in importers)
{
if (importer.assetPath.Contains(AudienceNetworkFramework))
{
iOSPlugin = importer;
Debug.Log("Audience Network iOS plugin found at " + importer.assetPath + ".");
}
else if (importer.assetPath.Contains(AudienceNetworkAAR))
{
androidPlugin = importer;
Debug.Log("Audience Network Android plugin found at " + importer.assetPath + ".");
}
}
if (iOSPlugin != null)
{
iOSPlugin.SetCompatibleWithAnyPlatform(false);
iOSPlugin.SetCompatibleWithEditor(false);
iOSPlugin.SetCompatibleWithPlatform(BuildTarget.iOS, true);
iOSPlugin.SetPlatformData(BuildTarget.iOS, FrameworkDependenciesKey, RequiredFrameworks);
iOSPlugin.SaveAndReimport();
}
if (androidPlugin != null)
{
androidPlugin.SetCompatibleWithAnyPlatform(false);
androidPlugin.SetCompatibleWithEditor(false);
androidPlugin.SetCompatibleWithPlatform(BuildTarget.Android, true);
androidPlugin.SaveAndReimport();
}
}
}
}
不过,不保证这会解决您的所有问题。
Google Ads 有类似的错误并使用了相同的修补程序。
否则您可能需要考虑安装 IOS 构建支持,我想这也会使错误消失(但不必要地填充磁盘 space 当然,如果您只想构建Android)
解决方法: in AdUtility.cs 添加:
"#if UNITY_ANDROID && !UNITY_EDITOR"
internal static bool IsInitialized()
{
#if UNITY_ANDROID && !UNITY_EDITOR
AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");