gpt4 book ai didi

java - Unity 的 GCM 插件,找不到方法 GCMRegistrar.checkDevice

转载 作者:行者123 更新时间:2023-12-01 14:35:03 25 4
gpt4 key购买 nike

我之前看过有关此问题的帖子,但似乎没有一个解决方案对我有用。

我下载/安装了 Eclipse for Mobile( http://www.eclipse.org/downloads/packages/eclipse-mobile-developers/junosr2 ),并创建了一个 Android 应用程序,然后使用从这个人的视频教程 ( http://www.youtube.com/watch?v=TazEIIoNVA0 ) 中找到的说明将其设为库,以便我可以将其放入 Unity 中。

当然,他的教程是针对Mobclix的,我正在尝试构建一个GCM插件,但过程是相似的。我想我已经包含了我需要的所有依赖项。在 Eclipse 中,在项目中我看到“Android 依赖项”,其中包括:classes.jar(包含 Unity 播放器 Hook )、gcm.jar 和 android-support-v4.jar。在“Android 4.2.2”下我看到“android.jar”。在“引用库”下,我看到classes.jar 和gcm.jar。在关于此错误的其他论坛帖子(例如: GCM : java.lang.noclassdeffounderror: com.google.android.gcm.GCMRegistrar )之后,我手动将 gcm.jar 和classes.jar 复制到“libs”文件夹(我使用的是 ADT 17),然后选择“添加到构建路径”。

完成所有这些后,当我在设备上部署测试时,我仍然看到 2 个错误,第一个是标题错误,其次是 NoClassDefFoundError。我已经测试了 3 种设备的兼容性,目前我使用的是 2.3.3 的 Motorola(所以它应该支持 GCM)。如果有人知道还有什么可能导致此问题,请告诉我。我对 Eclipse(甚至 Java)不太熟悉,所以我打赌它以某种方式存在于 Java 项目中。

我的 list :

<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="preferExternal" package="com.my.package.testapp" android:versionName="1.0" android:versionCode="1">

<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" />

<supports-screens
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
android:anyDensity="true"
/>

<application android:icon="@drawable/app_icon" android:label="@string/app_name" android:debuggable="false">

<activity android:name="com.unity3d.player.UnityPlayerProxyActivity" android:label="@string/app_name" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="my_test_scheme" android:host="*" />
</intent-filter>
</activity>

<activity
android:name="com.unity3d.player.UnityPlayerActivity"
android:label="@string/app_name"
android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen"
android:screenOrientation="portrait"
/>

<activity android:name="com.unity3d.player.UnityPlayerNativeActivity" android:label="@string/app_name" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:screenOrientation="portrait">
<meta-data android:name="android.app.lib_name" android:value="unity" />
<meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="false" />
</activity>

<activity
android:name="com.unity3d.player.VideoPlayer"
android:label="@string/app_name"
android:screenOrientation="behind"
android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen"
/>

<receiver
android:name="com.google.android.gcm.GCMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.my.package.testapp" />
</intent-filter>
</receiver>

<service android:name="com.my_provider.gcm.GCMIntentService" />
</application>

<uses-feature android:glEsVersion="0x00020000" />

<uses-permission android:name="com.my.package.testapp.permission.C2D_MESSAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

<permission
android:name="com.my.package.testapp.permission.C2D_MESSAGE"
android:protectionLevel="signature"
/>

</manifest>

我的Logcat:

I/Unity   (16312): MyApplication::MyApplication()
I/Unity (16312):
I/Unity (16312):
I/Unity (16312): (Filename: ./Runtime/ExportGenerated/AndroidManaged/UnityEngineDebug.cpp Line: 43)
I/Unity (16312):
D/dalvikvm(16344): GC_CONCURRENT freed 1309K, 55% free 3034K/6727K, external 1625K/2137K, paused 2ms+3ms
D/dalvikvm(16344): GC_CONCURRENT freed 539K, 54% free 3137K/6727K, external 1625K/2137K, paused 2ms+2ms
D/DeviceProfile(16344): ************************** Properties ****************************
D/DeviceProfile(16344): * android.vm.dexfile: true
D/DeviceProfile(16344): * file.encoding: UTF-8
D/DeviceProfile(16344): * file.separator: /
D/DeviceProfile(16344): * http.agent: Dalvik/1.4.0 (Linux; U; Android 2.3.4; LG-P999 Build/GRJ22)
D/DeviceProfile(16344): * java.boot.class.path: /system/framework/core.jar:/system/framework/bouncycastle.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/android.policy.jar:/system/framework/services.jar:/system/framework/core-junit.jar
D/DeviceProfile(16344): * java.class.path: .
D/DeviceProfile(16344): * java.class.version: 46.0
D/DeviceProfile(16344): * java.compiler:
D/DeviceProfile(16344): * java.ext.dirs:
D/DeviceProfile(16344): * java.home: /system
D/DeviceProfile(16344): * java.io.tmpdir: /sdcard
D/DeviceProfile(16344): * java.library.path: /vendor/lib:/system/lib
D/DeviceProfile(16344): * java.net.preferIPv6Addresses: true
D/DeviceProfile(16344): * java.runtime.name: Android Runtime
D/DeviceProfile(16344): * java.runtime.version: 0.9
D/DeviceProfile(16344): * java.specification.name: Dalvik Core Library
D/DeviceProfile(16344): * java.specification.vendor: The Android Project
D/DeviceProfile(16344): * java.specification.version: 0.9
D/DeviceProfile(16344): * java.vendor: The Android Project
D/DeviceProfile(16344): * java.vendor.url: http://www.android.com/
D/DeviceProfile(16344): * java.version: 0
D/DeviceProfile(16344): * java.vm.name: Dalvik
D/DeviceProfile(16344): * java.vm.specification.name: Dalvik Virtual Machine Specification
D/DeviceProfile(16344): * java.vm.specification.vendor: The Android Project
D/DeviceProfile(16344): * java.vm.specification.version: 0.9
D/DeviceProfile(16344): * java.vm.vendor: The Android Project
D/DeviceProfile(16344): * java.vm.vendor.url: http://www.android.com/
D/DeviceProfile(16344): * java.vm.version: 1.4.0
D/DeviceProfile(16344): * javax.net.ssl.trustStore: /system/etc/security/cacerts.bks
D/DeviceProfile(16344): * line.separator:
D/DeviceProfile(16344): * mngspkphone: true
D/DeviceProfile(16344): * os.arch: armv7l
D/DeviceProfile(16344): * os.name: Linux
D/DeviceProfile(16344): * os.version: 2.6.32.9
D/DeviceProfile(16344): * path.separator: :
D/DeviceProfile(16344): * recording.auto-focus: true
D/DeviceProfile(16344): * recording.ffc.camera-sensor: 1
D/DeviceProfile(16344): * recording.ffc.video: 320x240 15 low
D/DeviceProfile(16344): * recording.hd.video: 1280x720 24 hd
D/DeviceProfile(16344): * recording.live.audio-aux: EhAAAA==
D/DeviceProfile(16344): * recording.live.video: 176x144 15 low
D/DeviceProfile(16344): * recording.live.video-aux: AUKAHv/hAAhnQoAelaCxMQEABGjOPIA=
D/DeviceProfile(16344): * recording.live.video-aux-rotation-90: AUKAHv/hAAhnQoAelaCRcQEABGjOPIA=
D/DeviceProfile(16344): * recording.liveffc.audio-aux: EhAAAA==
D/DeviceProfile(16344): * recording.liveffc.camera-sensor: 1
D/DeviceProfile(16344): * recording.liveffc.video: 176x144 15 low
D/DeviceProfile(16344): * recording.liveffc.video-aux: AUKAHv/hAAhnQoAelaCxMQEABGjOPIA=
D/DeviceProfile(16344): * recording.liveffc.video-aux-rotation-90: AUKAHv/hAAhnQoAelaCRcQEABGjOPIA=
D/DeviceProfile(16344): * recording.normal.video: 640x480 15 medium
D/DeviceProfile(16344): * user.dir: /
D/DeviceProfile(16344): * user.home:
D/DeviceProfile(16344): * user.language: en
D/DeviceProfile(16344): * user.name:
D/DeviceProfile(16344): * user.region: US
D/DeviceProfile(16344): ******************************************************************
I/ActivityManager( 1111): No longer want com.google.android.gsf.login (pid 15960): hidden #16
I/dalvikvm(16312): Could not find method com.google.android.gcm.GCMRegistrar.checkDevice, referenced from method com.my_provider.gcm.RegisterActivity.RegisterDevice
W/dalvikvm(16312): VFY: unable to resolve static method 382: Lcom/google/android/gcm/GCMRegistrar;.checkDevice (Landroid/content/Context;)V
D/dalvikvm(16312): VFY: replacing opcode 0x71 at 0x0000
D/dalvikvm(16312): VFY: dead code 0x0003-001c in Lcom/my_provider/gcm/RegisterActivity;.RegisterDevice (Landroid/app/Activity;)V
W/Unity (16312): Font size and style overrides are only supported for dynamic fonts.
W/Unity (16312):
W/Unity (16312): (Filename: ./Runtime/GUI/TextMeshGenerator2.cpp Line: 65)
W/Unity (16312):
W/Unity (16312): Font size and style overrides are only supported for dynamic fonts.
W/Unity (16312):
W/Unity (16312): (Filename: ./Runtime/GUI/TextMeshGenerator2.cpp Line: 65)
W/Unity (16312):
W/dalvikvm(16312): threadid=9: thread exiting with uncaught exception (group=0x4001d560)
E/AndroidRuntime(16312): FATAL EXCEPTION: GLThread 10
E/AndroidRuntime(16312): java.lang.NoClassDefFoundError: com.google.android.gcm.GCMRegistrar
E/AndroidRuntime(16312): at com.my_provider.gcm.RegisterActivity.RegisterDevice(RegisterActivity.java:23)
E/AndroidRuntime(16312): at com.unity3d.player.UnityPlayer.nativeRender(Native Method)
E/AndroidRuntime(16312): at com.unity3d.player.UnityPlayer.onDrawFrame(Unknown Source)
E/AndroidRuntime(16312): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1363)
E/AndroidRuntime(16312): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1118)
W/ActivityManager( 1111): Force finishing activity com.my.package.testapp/com.unity3d.player.UnityPlayerNativeActivity

代码很简单,只有两个文件

RegisterActivity.java:

package com.my_provider.gcm;

import android.os.Bundle;
import android.app.Activity;
import com.google.android.gcm.GCMRegistrar;
import com.unity3d.player.UnityPlayer;
import com.unity3d.player.UnityPlayerActivity;

public class RegisterActivity extends UnityPlayerActivity
{
public static String ProjectID;

@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
}

public static void RegisterDevice(final Activity activity)
{
try
{
GCMRegistrar.checkDevice(activity);
GCMRegistrar.checkManifest(activity);

final String regId = GCMRegistrar.getRegistrationId(activity);

if (regId.equals(""))
GCMRegistrar.register(activity, ProjectID);
}
catch(Exception e)
{
UnityPlayer.UnitySendMessage("ErrorHandlerGameObject", "OnError", e.getMessage());
}
}
}

最后是服务 GCMBroadcastReceiver.java:

package com.my_provider.gcm;
import android.content.Context;
import android.content.Intent;

import com.google.android.gcm.GCMBaseIntentService;
import com.unity3d.player.UnityPlayer;

public class GCMBroadcastReceiver extends GCMBaseIntentService {

public GCMBroadcastReceiver()
{
super(RegisterActivity.ProjectID);
}

@Override
protected void onRegistered(Context context, String deviceID)
{
UnityPlayer.UnitySendMessage("DeviceRegisteringGameObject", "OnRegisteredAndroidDevice", deviceID);
}

@Override
protected void onUnregistered(Context context, String deviceID)
{
UnityPlayer.UnitySendMessage("DeviceRegisteringGameObject", "OnUnregisteredAndroidDevice", deviceID);
}

@Override
public void onError(Context context, String errorID)
{
UnityPlayer.UnitySendMessage("DeviceRegisteringGameObject", "OnError", errorID);
}

@Override
protected void onMessage(Context context, Intent intent)
{
UnityPlayer.UnitySendMessage("DeviceRegisteringGameObject", "OnMessageAndroid", intent.getStringExtra("message"));
}
}

最佳答案

I had manually copied gcm.jar and classes.jar to the "libs" folder(I am using ADT 17), then selected to Add To Build Path.

我不知道classes.jar是什么。

对于常规 Android 应用程序来说,只需在 libs/ 文件夹中包含 gcm.jar 就足够了 - 使用“添加到构建路径”手动更改构建路径是一个简单的方法错误。

Unity 插件的流程是否不同,我不能说。

该错误表明您的编译时构建路径中有 gcm.jar (例如,通过“添加到构建路径”),但它不在 APK 中(例如,您没有 gcm.jar 位于 libs/ 中,或者手动将其添加到构建路径会阻止将其添加到您的 APK)。

关于java - Unity 的 GCM 插件,找不到方法 GCMRegistrar.checkDevice,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16548842/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com