java Google Play Services Unity
我正在尝试使用谷歌推出的Jar解析器来添加Google Play服务-https://github.com/googlesamples/unity-jar-resolver来创建一个我们可以重用的插件,以便轻松地将Google Play服务添加到我们的项目中
我创建了他们的示例依赖类的副本:
// <copyright file="GPGSDependencies.cs" company="Google Inc.">
// Copyright (C) 2015 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
using System;
using System.Collections.Generic;
using UnityEditor;
/// Sample dependencies file. Change the class name and dependencies as required by your project, then
/// save the file in a folder named Editor (which can be a sub-folder of your plugin).
/// There can be multiple dependency files like this one per project, the resolver will combine them and process all
/// of them at once.
[InitializeOnLoad]
public class MyDependencies : AssetPostprocessor {
#if UNITY_ANDROID
/// <summary>Instance of the PlayServicesSupport resolver</summary>
public static object svcSupport;
#endif // UNITY_ANDROID
/// Initializes static members of the class.
static MyDependencies() {
//
//
// NOTE:
//
// UNCOMMENT THIS CALL TO MAKE THE DEPENDENCIES BE REGISTERED.
// THIS FILE IS ONLY A SAMPLE!!
//
RegisterDependencies();
//
}
/// <summary>
/// Registers the dependencies needed by this plugin.
/// </summary>
public static void RegisterDependencies() {
#if UNITY_ANDROID
RegisterAndroidDependencies();
#elif UNITY_IOS
RegisterIOSDependencies();
#endif
}
/// <summary>
/// Registers the 安卓 dependencies.
/// </summary>
public static void RegisterAndroidDependencies() {
// Setup the resolver using reflection as the module may not be
// available at compile time.
Type playServicesSupport = Google.VersionHandler.FindClass(
"Google.JarResolver", "Google.JarResolver.PlayServicesSupport");
if (playServicesSupport == null) {
return;
}
svcSupport = svcSupport ?? Google.VersionHandler.InvokeStaticMethod(
playServicesSupport, "CreateInstance",
new object[] {
"GooglePlayGames",
EditorPrefs.GetString("AndroidSdkRoot"),
"ProjectSettings"
});
// For example to depend on play-services-games version 9.6.0 you need to specify the
// package, artifact, and version as well as the packageId from the SDK manager in case
// a newer version needs to be downloaded to build.
Google.VersionHandler.InvokeInstanceMethod(
svcSupport, "DependOn",
new object[] {
"com.google.安卓.gms",
"play-services-games",
"9.6.0" },
namedArgs: new Dictionary<string, object>() {
{"packageIds", new string[] { "extra-google-m2repository" } }
});
// This example gets the com.安卓.support.support-v4 library, version 23.1 or greater.
// notice it is in a different package than the play-services libraries.
Google.VersionHandler.InvokeInstanceMethod(
svcSupport, "DependOn",
new object[] { "com.安卓.support", "support-v4", "23.1+" },
namedArgs: new Dictionary<string, object>() {
{"packageIds", new string[] { "extra-安卓-m2repository" } }
});
Google.VersionHandler.InvokeInstanceMethod(
svcSupport, "DependOn",
new object[] { "com.hyprmx.mediate", "HyprMediate-SDK", "1.1.0" });
}
/// <summary>
/// Registers the IOS dependencies.
/// </summary>
public static void RegisterIOSDependencies() {
// Setup the resolver using reflection as the module may not be
// available at compile time.
Type iosResolver = Google.VersionHandler.FindClass(
"Google.IOSResolver", "Google.IOSResolver");
if (iosResolver == null) {
return;
}
// Dependencies for iOS are added by referring to CocoaPods. The libraries and frameworkds are
// and added to the Unity project, so they will automatically be included.
//
// This example add the GooglePlayGames pod, version 5.0 or greater, disabling bitcode generation.
Google.VersionHandler.InvokeStaticMethod(
iosResolver, "AddPod",
new object[] { "GooglePlayGames" },
namedArgs: new Dictionary<string, object>() {
{ "version", "5.0+" },
{ "bitcodeEnabled", false },
});
}
// Handle delayed loading of the dependency resolvers.
private static void OnPostprocessAllAssets(
string[] importedAssets, string[] deletedAssets,
string[] movedAssets, string[] movedFromPath) {
foreach (string asset in importedAssets) {
if (asset.Contains("IOSResolver") ||
asset.Contains("JarResolver")) {
RegisterDependencies();
break;
}
}
}
}
然而,我在Unity中遇到了一个错误:Assets/Plugins/MyDependencies.cs(96,5): error CS0103: The name
Google'在当前上下文中不存在`
有什么想法可以让我更新代码,让谷歌能够解析,这样我就可以运行这个类了?看起来他们提供了dll
来帮助解决这个问题,但我不知道如何让他们解决。我试图使用using dll1
等来引用它们,但似乎没有找到它们
共 (0) 个答案