我的Android应用程序在启动时崩溃。我正在使用Unity并正在为它制作一个google-play-services插件。
现在我只想要一个简单的登录工作。
这是我的代码:
package com.company.appname;
import android.content.Intent;
import android.os.Bundle;
import com.google.example.games.basegameutils.GameHelper;
import com.google.example.games.basegameutils.GameHelper.GameHelperListener;
import com.unity3d.player.UnityPlayerActivity;
public class Main extends UnityPlayerActivity
{
GameHelper mHelper;
@Override
public void onCreate(Bundle savedInstanceState) {
// create game helper with all APIs (Games, Plus, AppState):
System.out.println("creating gamehelper");
mHelper = new GameHelper(this, GameHelper.CLIENT_GAMES);
GameHelperListener listener = new GameHelper.GameHelperListener() {
@Override
public void onSignInSucceeded() {
// handle sign-in success
System.out.println("signed in!!");
}
@Override
public void onSignInFailed() {
// handle sign-in failure (e.g. show Sign In button)
System.out.println("sign in failed...");
}
};
super.onCreate(savedInstanceState);
System.out.println("setting up gamehelper");
mHelper.setup(listener);
System.out.println("gamehelper set up");
}
@Override
protected void onStart() {
super.onStart();
System.out.println("starting gamehelper");
mHelper.onStart(this);
}
@Override
protected void onStop() {
super.onStop();
System.out.println("stopping gamehelper");
mHelper.onStop();
}
@Override
protected void onActivityResult(int request, int response, Intent data) {
super.onActivityResult(request, response, data);
System.out.println("gamehelper activity result");
mHelper.onActivityResult(request, response, data);
}
static public void Test()
{
System.out.println("test worked!!!");
}
}
这是清单文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.ChocolatePinecone.PrincessRescueRun" android:theme="@android:style/Theme.NoTitleBar" android:versionName="1.0" android:versionCode="1" android:installLocation="preferExternal">
<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="true">
<activity android:name=".Main" android:label="@string/app_name" android:screenOrientation="reverseLandscape" android:launchMode="singleTask" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="unityplayer.UnityActivity" android:value="true" />
<meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="true" />
</activity>
<meta-data android:name="com.google.android.gms.games.APP_ID"
android:value="@string/app_id" />
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version"/>
<meta-data android:name="com.google.android.gms.appstate.APP_ID" android:value="@string/app_id" />
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|uiMode|touchscreen"/>
</application>
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="19" />
<uses-feature android:glEsVersion="0x00020000" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-feature android:name="android.hardware.sensor.accelerometer" />
<uses-feature android:name="android.hardware.touchscreen" />
<uses-feature android:name="android.hardware.touchscreen.multitouch" android:required="false" />
<uses-feature android:name="android.hardware.touchscreen.multitouch.distinct" android:required="false" />
</manifest>
我的插件的构建顺序是:
我得到的错误:
07-21 22:18:21.209: E/AndroidRuntime(12813): FATAL EXCEPTION: main
07-21 22:18:21.209: E/AndroidRuntime(12813): Process: com.company.appname, PID: 12813
07-21 22:18:21.209: E/AndroidRuntime(12813): java.lang.Error: FATAL EXCEPTION [main]
07-21 22:18:21.209: E/AndroidRuntime(12813): Unity version : 4.3.4f1
07-21 22:18:21.209: E/AndroidRuntime(12813): Device model : samsung GT-I9505
07-21 22:18:21.209: E/AndroidRuntime(12813): Device fingerprint: samsung/jfltexx/jflte:4.4.2/KOT49H/I9505XXUGNF1:user/release-keys
07-21 22:18:21.209: E/AndroidRuntime(12813): Caused by: java.lang.NoClassDefFoundError: com.google.example.games.basegameutils.R$string
07-21 22:18:21.209: E/AndroidRuntime(12813): at com.google.example.games.basegameutils.GameHelperUtils.<clinit>(GameHelperUtils.java:33)
07-21 22:18:21.209: E/AndroidRuntime(12813): at com.google.example.games.basegameutils.GameHelper.onConnectionFailed(GameHelper.java:791)
07-21 22:18:21.209: E/AndroidRuntime(12813): at com.google.android.gms.internal.fg.a(Unknown Source)
07-21 22:18:21.209: E/AndroidRuntime(12813): at com.google.android.gms.common.api.b.ei(Unknown Source)
07-21 22:18:21.209: E/AndroidRuntime(12813): at com.google.android.gms.common.api.b.d(Unknown Source)
07-21 22:18:21.209: E/AndroidRuntime(12813): at com.google.android.gms.common.api.b$4.onConnectionFailed(Unknown Source)
07-21 22:18:21.209: E/AndroidRuntime(12813): at com.google.android.gms.internal.fg.a(Unknown Source)
07-21 22:18:21.209: E/AndroidRuntime(12813): at com.google.android.gms.internal.ff$h.b(Unknown Source)
07-21 22:18:21.209: E/AndroidRuntime(12813): at com.google.android.gms.internal.ff$h.a(Unknown Source)
07-21 22:18:21.209: E/AndroidRuntime(12813): at com.google.android.gms.internal.ff$b.eN(Unknown Source)
07-21 22:18:21.209: E/AndroidRuntime(12813): at com.google.android.gms.internal.ff$a.handleMessage(Unknown Source)
07-21 22:18:21.209: E/AndroidRuntime(12813): at android.os.Handler.dispatchMessage(Handler.java:102)
07-21 22:18:21.209: E/AndroidRuntime(12813): at android.os.Looper.loop(Looper.java:157)
07-21 22:18:21.209: E/AndroidRuntime(12813): at android.app.ActivityThread.main(ActivityThread.java:5356)
07-21 22:18:21.209: E/AndroidRuntime(12813): at java.lang.reflect.Method.invokeNative(Native Method)
07-21 22:18:21.209: E/AndroidRuntime(12813): at java.lang.reflect.Method.invoke(Method.java:515)
07-21 22:18:21.209: E/AndroidRuntime(12813): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
07-21 22:18:21.209: E/AndroidRuntime(12813): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
07-21 22:18:21.209: E/AndroidRuntime(12813): at dalvik.system.NativeStart.main(Native Method)
我尝试的事情:
我不知道问题可能是什么......
希望你们能给我一些指示。
答案 0 :(得分:1)
我解决了! 似乎apk文件中没有basegameutils的R.java。
我在eclipse中打开了basegameutils项目,切换了src和gen的构建顺序并构建了项目。