Amazon Mobile App SDK

Hi,

does anyone have experience integrating the Amazon Mobile App SDK into cocos2d-x v3 and the NativeActivity implementation? I would like to use the GameCircle API, but the sample implementation uses Java, and I am a little unsure how to set it up using NativeActivity

https://developer.amazon.com/sdk/gamecircle/documentation/gamecircle-init.html#Section5

Hi,

just have a look at the following files/links:

  1. GameCenter.h https://github.com/michaelcontento/avalon/blob/cocos2dx-v3.0-and-other-stuff/avalon/GameCenter.h
  2. GameCenter.cpp https://github.com/michaelcontento/avalon/blob/cocos2dx-v3.0-and-other-stuff/avalon/platform/android-amazon/gamecenter/GameCenter.cpp
  3. Required java stuff https://github.com/michaelcontento/avalon/tree/cocos2dx-v3.0-and-other-stuff/avalon/platform/android-amazon/gamecenter/java
  4. Follow the official Amazon docs regarding the whole assets/api_key.txt and security profile stuff

Note to the last point: Just copy all files from this directoy into the android project directory (cp -r $AVALON_DIR$/avalon/platform/android-amazon/gamecenter/java/* proj.android/) but don’t forget to clone all submodules before (git clone --recursive ...)!

Final note: Not all features of the Amazon GameCircle API are available but I think it should be a good starting point :slight_smile:

Happy coding!

UPDATE Broken links fixed

Hi,

thanks for the help. I am still a little confused though. The amazon docs say that I should initialize the api during onResume(), https://developer.amazon.com/sdk/gamecircle/documentation/gamecircle-init.html#Section5
and that the api library should be loaded before my game library,
https://developer.amazon.com/sdk/gamecircle/documentation/jni-api.html#Section3

How does that work with NativeActivity since the cocos2dx lib is loaded directly?

Hi,

I am still a little confused though. The amazon docs say that I should initialize the api during onResume(), https://developer.amazon.com/sdk/gamecircle/documentation/gamecircle-init.html#Section5

IMHO this is only used for accurate play time measurement. I’ve got accepted on the Amazon App Store without this but your right, that’s something that should be improved!

But I’m not the best Android developer and it’s not that easy / clear how to integrate the lifecycle events with the NativeActivity. Although I managed to integrate another plugin that depends on event delegation through onActivityResult of the NativeActivity — just have a look at this path and you should get the idea. A similar approach could be used to delegate all other lifecycle events.

and that the api library should be loaded before my game library,
https://developer.amazon.com/sdk/gamecircle/documentation/jni-api.html#Section3
>
How does that work with NativeActivity since the cocos2dx lib is loaded directly?

The GameCenter in Avalon is using the plain Java interface and not the JNI library!

Hi,

does the Amazon integration also require that the Amazon AppStore be installed on the device? Or can I make use of the GameCircle Achievements/Leaderboards APIs on devices that do not have Amazon AppStore installed (for example Ouya or other android based microconsoles)?

Hi,

Michael Contento wrote:

Hi,
>
just have a look at the following files/links:

  1. GameCenter.h https://github.com/michaelcontento/avalon/blob/wip/avalon/GameCenter.h
  2. GameCenter.cpp https://github.com/michaelcontento/avalon/blob/wip/avalon/platform/android-amazon/gamecenter/GameCenter.cpp
  3. Required java stuff https://github.com/michaelcontento/avalon/tree/wip/avalon/platform/android-amazon/gamecenter/java

the links have “404 error”. Are been removed? :slight_smile:
I would like integrate gamecirlcle in my game. Some people have done this?

byz!

  1. Follow the official Amazon docs regarding the whole assets/api_key.txt and security profile stuff
    >
    Note to the last point: Just copy all files from this directoy into the android project directory (cp -r $AVALON_DIR$/avalon/platform/android-amazon/gamecenter/java/* proj.android/) but don’t forget to clone all submodules before (git clone --recursive ...)!
    >
    Final note: Not all features of the Amazon GameCircle API are available but I think it should be a good starting point :slight_smile:
    >
    Happy coding!

I have it by using the official Amazon JNI SDK

I ended up extending NativeActivity simply to initialize Gamecircle, after that you can just use the jni api

This is what my NativeActivity class looks like:

package com.mygame;

import java.util.EnumSet;
import android.os.Bundle;
import android.app.NativeActivity;
import android.util.Log;
import com.amazon.ags.api.*;
import com.amazon.ags.api.achievements.AchievementsClient;
import com.amazon.ags.api.achievements.UpdateProgressResponse;
import com.amazon.ags.api.leaderboards.LeaderboardsClient;
import com.amazon.ags.api.leaderboards.SubmitScoreResponse;
import com.amazon.ags.api.whispersync.GameDataMap;
import com.amazon.ags.api.whispersync.WhispersyncEventListener;
import com.amazon.ags.api.whispersync.model.SyncableNumber;

public class NativeActivityProxy extends android.app.NativeActivity {

    protected AmazonGamesClient agsClient;
    protected AmazonGamesCallback agsCallback;
    protected EnumSet myGameFeatures;
    protected static boolean agsReady = false;

    public static native void onNativeAmazonGamesServiceReady();
    public static native void onNativeAmazonGamesServiceNotReady();
    public static boolean isAmazonGamesServiceReady() {
        return NativeActivityProxy.agsReady;
    }

    protected void onCreate(Bundle savedInstanceState){
        System.loadLibrary("AmazonGamesJni");

        super.onCreate(savedInstanceState); 

        //reference to the agsClient
        agsCallback = new AmazonGamesCallback() {
            @Override
            public void onServiceNotReady(AmazonGamesStatus status) {
                //unable to use service
                NativeActivityProxy.onNativeAmazonGamesServiceNotReady();
            }
            @Override
            public void onServiceReady(AmazonGamesClient amazonGamesClient) {
                agsClient = amazonGamesClient;
                NativeActivityProxy.agsReady = true;
                //ready to use GameCircle
                NativeActivityProxy.onNativeAmazonGamesServiceReady();
            }
        };
        //list of features your game uses (in this example, achievements and leaderboards)
        //myGameFeatures = EnumSet.of(AmazonGamesFeature.Leaderboards, AmazonGamesFeature.Achievements);
        myGameFeatures = EnumSet.of(AmazonGamesFeature.Achievements, AmazonGamesFeature.Leaderboards, AmazonGamesFeature.Whispersync);
        AmazonGamesClient.initialize(this, agsCallback, myGameFeatures);
    }

    @Override
    public void onResume() {
        super.onResume();
    }

    @Override
    public void onPause() {
        super.onPause();
        if (agsClient != null) {
            agsClient.release();
        }
    }

}

Notice I added a couple extra jni calls to be notified when the amazon services are ready, this is implemeted in cpp as:

extern "C" {

    JNIEXPORT void JNICALL Java_com_mygame_NativeActivityProxy_onNativeAmazonGamesServiceReady(JNIEnv* env, jobject thiz) {
        NotificationCenter::getInstance()->postNotification(NOTIFICATION_GAME_AGS_READY, NULL);
    }

    JNIEXPORT void JNICALL Java_com_mygame_NativeActivityProxy_onNativeAmazonGamesServiceNotReady(JNIEnv* env, jobject thiz) {
        NotificationCenter::getInstance()->postNotification(NOTIFICATION_GAME_AGS_NOTREADY, NULL);
    }

}

namespace mygame {


// AmazonGamesService
bool AmazonGamesService::isAmazonGamesServiceReady() {
    cocos2d::JniMethodInfo ccxagsHandler;
    if (!cocos2d::JniHelper::getStaticMethodInfo(ccxagsHandler, "com/mygame/NativeActivityProxy", "isAmazonGamesServiceReady", "()Z")) {
        log("cocos2d::JniHelper::getStaticMethodInfo(ccxagsHandler) FAILED");
    }
    jboolean isReady = ccxagsHandler.env->CallStaticBooleanMethod(ccxagsHandler.classID, ccxagsHandler.methodID);
    return (bool)isReady;
}

Stefano Campodall’Orto wrote:

the links have “404 error”. Are been removed? :slight_smile:
I would like integrate gamecirlcle in my game. Some people have done this?

Oh sorry! I’ve renamed the “wip” branch which caused this problem. Here are the new links:

  1. GameCenter.h https://github.com/michaelcontento/avalon/blob/cocos2dx-v3.0-and-other-stuff/avalon/GameCenter.h
  2. GameCenter.cpp https://github.com/michaelcontento/avalon/blob/cocos2dx-v3.0-and-other-stuff/avalon/platform/android-amazon/gamecenter/GameCenter.cpp
  3. Required java stuff https://github.com/michaelcontento/avalon/tree/cocos2dx-v3.0-and-other-stuff/avalon/platform/android-amazon/gamecenter/java

Michael Contento wrote:

Stefano Campodall’Orto wrote:
> the links have “404 error”. Are been removed? :slight_smile:
> I would like integrate gamecirlcle in my game. Some people have done this?
>
Oh sorry! I’ve renamed the “wip” branch which caused this problem. Here are the new links:
>

  1. GameCenter.h https://github.com/michaelcontento/avalon/blob/cocos2dx-v3.0-and-other-stuff/avalon/GameCenter.h
  2. GameCenter.cpp https://github.com/michaelcontento/avalon/blob/cocos2dx-v3.0-and-other-stuff/avalon/platform/android-amazon/gamecenter/GameCenter.cpp
  3. Required java stuff https://github.com/michaelcontento/avalon/tree/cocos2dx-v3.0-and-other-stuff/avalon/platform/android-amazon/gamecenter/java

Thanks! Is it a great start point!

byz!

links are still 404 :frowning:

the git of this guy is here (google research with tags : ‘amazon contento’) … : https://github.com/hovergames/avalon