【问题标题】:Facebook Audience Network SDK for Unity适用于 Unity 的 Facebook Audience Network SDK
【发布时间】:2019-08-30 12:16:16
【问题描述】:

我将 Unity Audience Network SDK 5.4.1 包导入统一,任何版本,它给了我这个错误:

Assets\AudienceNetwork\Editor\AudienceNetworkPostprocess.cs(25,23):错误 CS0234:命名空间“UnityEditor”中不存在类型或命名空间名称“iOS”(您是否缺少程序集引用?)

如果我删除 ios 部分并尝试仅在 android 上工作 - 没有任何效果,我尝试播放奖励场景并收到此错误:

NullReferenceException:对象引用未设置为对象的实例 AudienceNetwork.Utility.AdUtility.IsInitialized ()(在 Assets/AudienceNetwork/Library/AdUtility.cs:50) RewardedVideoAdScene.Awake ()(在 Assets/AudienceNetwork/Scenes/RewardedVideo/RewardedVideoAdScene.cs:21)

有没有办法让它工作?我做错了什么或错过了什么? 以前的插件有效吗?有任何链接吗? 谢谢。

【问题讨论】:

    标签: facebook unity3d networking sdk audience


    【解决方案1】:

    在不知道你删除了什么的情况下,第二个问题很难解决......

    我们只能说它指的是51这一行

     AndroidJavaObject context = currentActivity.Call<AndroidJavaObject>("getApplicationContext");
    

    如果在 PC 上执行,currentActivity 最有可能是 null,因为之前的行 50

    AndroidJavaObject currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
    

    在这种情况下可能不起作用。


    第一个听起来像一个“错误”。

    您可以使用#if pre-processorsUNITY_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 构建支持,我猜这也会使错误消失(但如果您只想为 Android 构建,当然会不必要地填充磁盘空间)

    【讨论】:

    • 这正是我所做的,如果解决了第一个问题,当我去现场并尝试播放它时会出现第二个问题 - 我试图了解它为什么返回错误。
    • 嘿,我更新了答案的第一部分..我想问题是它可能无法在 PC 上运行(在编辑器中),而只能在手机上运行......对我来说听起来有点就像 Facebook 伙计们有点懒惰地抓住这些案例
    • 试图构建 - 它在间隙场景的构建中间卡住了很长时间并且没有进一步,我想知道他们什么时候会修复这个构建:(
    【解决方案2】:

    解决方案:在 AdUtility.cs 添加:

    "#if UNITY_ANDROID && !UNITY_EDITOR" 
    
    internal static bool IsInitialized()
        {
    #if UNITY_ANDROID && !UNITY_EDITOR
            AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-19
      相关资源
      最近更新 更多