1

我将 UnityAudience 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)

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

4

2 回答 2

0

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

我们只能说它指的是线51

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

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

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

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


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

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

于 2019-08-30T12:29:30.243 回答
0

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

"#if UNITY_ANDROID && !UNITY_EDITOR" 

internal static bool IsInitialized()
    {
#if UNITY_ANDROID && !UNITY_EDITOR
        AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
于 2019-09-15T23:45:27.860 回答