我添加到我的團結項目Facebook團結SDK和onesignal團結SDK。 我配置了facebook和onesignal。OneSignal SDK&Facebook SDK和Unity3D
第一次,在建築,表現出這樣的錯誤:
Build failure
Unable to merge android manifests. See the Console for more details.
在控制檯:
Error: Error while saving blame file, build will continue
Error: The prefix "tools" for attribute "tools:overrideLibrary" associated with an element type "uses-sdk" is not bound.
UnityEditor.HostView:OnGUI()
此錯誤後,我加入到AndroidManifest.xml文件的xmlns:工具=「HTTP: //schemas.android.com/tools「,我創建的APK沒有任何錯誤。但在設備上顯示如錯誤!
09-21 17:36:32.321 25682 25702 V com.facebook.unity.FB: SetUserAgentSuffix(Unity.7.10.0)
09-21 17:36:32.391 25682 25702 E Unity : AndroidJavaException: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/facebook/FacebookActivity;
09-21 17:36:32.391 25682 25702 E Unity : java.lang.NoClassDefFoundError: Failed resolution of: Lcom/facebook/FacebookActivity;
09-21 17:36:32.391 25682 25702 E Unity : at com.facebook.internal.Validate.hasFacebookActivity(Validate.java:216)
09-21 17:36:32.391 25682 25702 E Unity : at com.facebook.FacebookSdk.sdkInitialize(FacebookSdk.java:265)
09-21 17:36:32.391 25682 25702 E Unity : at com.facebook.unity.FB.Init(FB.java:86)
09-21 17:36:32.391 25682 25702 E Unity : at com.unity3d.player.UnityPlayer.nativeRender(Native Method)
09-21 17:36:32.391 25682 25702 E Unity : at com.unity3d.player.UnityPlayer.c(Unknown Source)
09-21 17:36:32.391 25682 25702 E Unity : at com.unity3d.player.UnityPlayer$c$1.handleMessage(Unknown Source)
09-21 17:36:32.391 25682 25702 E Unity : at android.os.Handler.dispatchMessage(Handler.java:98)
09-21 17:36:32.391 25682 25702 E Unity : at android.os.Looper.loop(Looper.java:148)
09-21 17:36:32.391 25682 25702 E Unity : at com.unity3d.player.UnityPlayer$c.run(Unknown Source)
09-21 17:36:32.391 25682 25702 E Unity : Caused by: java.lang.ClassNotFoundException: Didn't find class "com.facebook.FacebookActivity" on path: DexPathList[[zip file "/data/app/.../base.apk"],
如果我刪除OneSingal SDK一切正常!
AndroidManifest.xml中
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="com.unity3d.player" android:installLocation="preferExternal" android:versionCode="1" android:versionName="1.0">
<supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" android:anyDensity="true" />
<application android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:icon="@drawable/app_icon" android:label="@string/app_name" android:debuggable="true">
<activity android:name="com.unity3d.player.UnityPlayerActivity" android:label="@string/app_name">
<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" />
</activity>
<activity android:name="com.facebook.unity.FBUnityLoginActivity" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" />
<activity android:name="com.facebook.unity.FBUnityDialogsActivity" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" />
<activity android:name="com.facebook.unity.FBUnityAppLinkActivity" android:exported="true" />
<activity android:name="com.facebook.unity.FBUnityDeepLinkingActivity" android:exported="true" />
<activity android:name="com.facebook.unity.FBUnityGameRequestActivity" />
<activity android:name="com.facebook.unity.FBUnityCreateGameGroupActivity" />
<activity android:name="com.facebook.unity.FBUnityJoinGameGroupActivity" />
<activity android:name="com.facebook.unity.AppInviteDialogActivity" />
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="fb149293168895610" />
<provider android:name="com.facebook.FacebookContentProvider" android:authorities="com.facebook.app.FacebookContentProvider149293168895610" android:exported="true" />
</application>
</manifest>
OneSignal/AndroidManifest.xml中
<!--
WARNING: Do NOT Modify! Changes will be overwritten by the OneSignal plugin.
Make your changes to Assets/Plugins/Android/AndroidManifest.xml instead.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.onesignal.onesignalsdk"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="9" />
<permission android:name="com.challenges_inc.realmultiplayerracing.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.challenges_inc.realmultiplayerracing.permission.C2D_MESSAGE" />
<application>
<receiver
android:name="com.onesignal.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.challenges_inc.realmultiplayerracing" />
</intent-filter>
</receiver>
</application>
</manifest>
Unity3d腳本:
void Start() {
FacebookInit();
}
private void FacebookInit() {
if (!FB.IsInitialized) {
FB.Init (InitCallback, OnHideUnity);
} else {
InitCallback();
}
}
private void InitCallback() {
if (FB.IsInitialized) {
Debug.Log("Initialized the Facebook SDK");
FB.ActivateApp();
if (FB.IsLoggedIn) {
OneSignalHandler();
} else {
Debug.Log("FB.IsLoggedIn is false");
}
} else {
Debug.Log("Failed to Initialize the Facebook SDK");
}
}
private void OnHideUnity (bool isGameShown) {
//...
}
public void OnClickConnectToFacebook() {
FB.LogInWithReadPermissions(new List<string>(){"public_profile", "email", "user_friends"}, AuthCallback);
}
private void AuthCallback (ILoginResult result) {
if (FB.IsLoggedIn) {
OneSignalHandler();
} else {
Debug.Log("FB.IsLoggedIn is false");
}
}
void OneSignalHandler() {
OneSignal.SetLogLevel(OneSignal.LOG_LEVEL.INFO, OneSignal.LOG_LEVEL.INFO);
string user_id = Facebook.Unity.AccessToken.CurrentAccessToken.UserId;
Debug.Log ("UserID: " + user_id);
OneSignal.StartInit("ONE-SIGNAL-APP-ID")
.EndInit();
OneSignal.SendTag ("user_id", user_id);
OneSignal.inFocusDisplayType = OneSignal.OSInFocusDisplayOption.Notification;
}
Unity3D版本:2017.1.1f1
OS:的MacOS 10.12.6
Facebook的SDK:7.10.0
OneSignal SDK:2.4.0
的Android分鐘SDK:
的Android目標SDK:
我降級到了OneSignal 2.3.3,並且所有工作都正常! – shranet
我試圖重現與所有相同的環境設置期望在windows上建設的問題,而不是能夠。我沒有遇到'uses-sdk'錯誤,這可能來自另一個插件。我沒有試圖初始化facebook插件(只是導入它),但com.facebook.FacebookActivity類出現在APK的classes.dex文件中。 我建議重新導入facebook插件,然後是OneSignal 2.4.0插件。 如果你仍然有這個問題,我建議創建一個新的Unity項目,再現與facebook和OneSignal的問題。 – jkasten
我使用Facebook SDK的PlayServiceResolver後,第一次使用OneSignler SKD的PlayServiceResolver,並且所有工作都正常! – shranet