我试图在eclipse cocos2d-x v2游戏中集成Branch SDK,
在libs中添加了Branch-2.4.5.jar,目标设置为lollipop
关注的整合指南https://dev.branch.io/getting-started/sdk-integration-guide/guide/android/
在Branch.getAutoInstance(this)上崩溃,所以从这里尝试了选项1 - Android: Branch.io tutorial: Branch.getAutoInstance(this);
引起:java.lang.ClassCastException:com.casualgames.Game.Game无法强制转换为android.app.Application E / AndroidRuntime(22756):at io.branch.referral.Branch.getAutoInstance(Branch.java:565) E / AndroidRuntime(22756):at com.casualgames.Game.Game.onStart(Game.java:493) E / AndroidRuntime(22756):在android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1194) E / AndroidRuntime(22756):在android.app.Activity.performStart(Activity.java:5258) E / AndroidRuntime(22756):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2171)
在尝试各种方法的所有长时间内仍然存在错误。
以下是清单
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.casualgames.Game"
android:installLocation="auto"
android:versionCode="82"
android:versionName="6.3.12" >
<uses-sdk android:minSdkVersion="9" />
<uses-feature android:glEsVersion="0x00020000" />
<application
android:icon="@drawable/icon"
android:label="@string/app_name"
android:name="io.branch.referral.BranchApp">
<meta-data
android:name="io.branch.sdk.TestMode"
android:value="true" />
<meta-data
android:name="io.branch.sdk.BranchKey"
android:value="key_live_kmxxxxxxxx_my_key_value" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.gms.games.APP_ID"
android:value="@string/games_app_id" />
<activity
android:name=".Game"
android:configChanges="orientation"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<data android:scheme="schemename" android:host="open" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
<receiver
android:name="io.branch.referral.InstallListener"
android:exported="true" >
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
</application>
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:xlargeScreens="true" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="com.android.vending.BILLING" />
<uses-permission android:name="android.permission.VIBRATE" />
</manifest>
以下是我的班级文件
package com.casualgames.Game;
import io.branch.referral.Branch;
import io.branch.referral.BranchError;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import android.content.Intent;
import org.cocos2dx.lib.Cocos2dxActivity;
import org.cocos2dx.lib.Cocos2dxGLSurfaceView;
import org.json.JSONObject;
import android.annotation.SuppressLint;
import android.app.AlarmManager;
import android.app.AlertDialog;
import android.app.PendingIntent;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Bundle;
import android.util.Base64;
import android.util.Log;
import android.widget.RelativeLayout;
import com.nidogames.Game.basegameutils.BaseGameActivity;
import android.provider.Settings;
import android.provider.Settings.Secure;
public class Game extends BaseGameActivity{
private static Context mContext;
private static final String TAG = “Game”;
private RelativeLayout mAdsLayout;
public static native void resumeGame();
public static native void quitGame();
private Cocos2dxGLSurfaceView glSurfaceView;
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
mContext = this;
String versionName = pinfo.versionName;
Branch.getAutoInstance(this.getApplication());
Log.i(TAG, "Finished oncreate");
}
public Cocos2dxGLSurfaceView onCreateView() {
glSurfaceView = new Cocos2dxGLSurfaceView(this);
glSurfaceView.setEGLConfigChooser(5, 6, 5, 0, 16, 8);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB)
{
this.hideSystemUI();
}
return glSurfaceView;
}
@Override
protected void onPause() {
super.onPause();
}
@Override
protected void onResume(){
super.onResume();
}
@Override
protected void onStart() {
super.onStart();
Branch branch = Branch.getAutoInstance(this);
branch.initSession(new Branch.BranchReferralInitListener(){
@Override
public void onInitFinished(JSONObject referringParams, BranchError error) {
if (error == null) {
} else {
Log.i("MyApp", error.getMessage());
}
}
}, this.getIntent().getData(), this);
}
@Override
protected void onStop() {
super.onStop();
}
@Override
protected void onDestroy() {
super.onDestroy();
}
@Override
public void onNewIntent(Intent intent) {
this.setIntent(intent);
}
}
答案 0 :(得分:0)
您在此应用中设置了<uses-sdk android:minSdkVersion="9" />
。不幸的是,Branch SDK的当前版本(2+)不支持minSdkVersion
15之前的任何内容。
您需要更新到更新的Android SDK版本,或者将您的Branch SDK固定到v1.14.5和implement some custom session management into all of your Activities。 话虽如此,SDK版本9现在差不多已有六年了,所以即使使用较旧版本的Branch SDK,我也无法验证这些步骤是否有效。请自行承担风险 - 使用更新版本的核心Android API绝对是推荐的解决方案:)