0

I'm trying to integrate the Branch SDK in eclipse cocos2d-x v2 game,

  1. Added Branch-2.4.5.jar in libs, target set to lollipop

  2. Followed integration guide https://dev.branch.io/getting-started/sdk-integration-guide/guide/android/

  3. Crashed on Branch.getAutoInstance(this), so tried option 1 from here-Android: Branch.io tutorial: Branch.getAutoInstance(this);

    Caused by: java.lang.ClassCastException: com.casualgames.Game.Game cannot be cast to 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): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1194) E/AndroidRuntime(22756): at android.app.Activity.performStart(Activity.java:5258) E/AndroidRuntime(22756): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2171)

Still the error persists of all the long hours of trying various methods.

Below is the Manifest

    <?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>

Below is my class file

 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);
        }
    }
Community
  • 1
  • 1
Shrinidhi Rao
  • 263
  • 4
  • 15
  • Alex from Branch here: I'm not aware of any specific issues with Branch on Eclipse. Are you getting any specific error messages in the console? Also try turning on the [debug mode](https://dev.branch.io/getting-started/integration-testing/guide/ios/#use-debug-mode-to-simulate-fresh-installs), since this will trigger some additional logging that might be useful. – Alex Bauer Oct 09 '16 at 20:41
  • Hi @AlexBauer , Thanks for the reply. I have edited the question to include include the crash log. It happens either in OnCreate for Branch.getAutoInstance or OnStart removing Branch.getAutoInstance in OnCreate – Shrinidhi Rao Oct 10 '16 at 05:02

1 Answers1

0

Alex from Branch.io here:

You are setting <uses-sdk android:minSdkVersion="9" /> in this app. Unfortunately the current versions (2+) of the Branch SDK don't support anything earlier than minSdkVersion 15.

You'll either need to update to a more recent Android SDK version, or pin your Branch SDK to v1.14.5 and implement some custom session management into all of your Activities. That being said, the SDK version 9 is now almost six years old so I can't actually verify if these steps will work even with an older version of the Branch SDK. Proceed at your own risk — using a more recent version of the core Android API is definitely the recommended solution here :)

Alex Bauer
  • 13,147
  • 1
  • 27
  • 44