Cocos2dx - Google Play Service | Leader Board

1:04 AM 0 Comments

Hi every one, today i will show you how to Google Play Service to Cocos2d use SonarCocosHelper by http://www.sonarsystems.co.uk/

All of bellow step is my experience when Looking Cocos2d Google Play Service tutorials of SonarSystems, i attach this video link to you, you can easy follow video then, have any issue, look at my post. Hope you will add this success. 

Setup Cocos Sonar Helper: http://www.sonarsystems.co.uk/cocoshelper.php?platform=android

Add Google Service: http://www.sonarsystems.co.uk/cocoshelper.php?platform=android&plugin=helper-googleplayservices


OK. Let 's begin. First, I use C++ and build to Android, but don't worry, it have 2 type  to add with IOS and JS on Cocos Helper folder below .


A/ Download and prepare useful and require things:

- Cocos Helper : https://github.com/SonarSystems/Cocos-Helper
or https://drive.google.com/file/d/0B_fyorPeUEq5XzlpMW9yMVRWVGM/view?usp=sharing

- Eclipse IDE.

- Android SDK -  Please install intial some package from this SDK:
+ Newest Android API, (v23 this moment)
+ Google Play Service.
+ Android Support Libary


B/ Add Google Service to Cocos Project:


First: Prepare some file to project:


1. Extract Cocos Helper , then open this:


2. Open SonarCocosHelperCPP folder , if you use Java Script, open SonarCocosHelperJS:




3. Copy SonarFrameworks.cpp and SonarFrameworks.h to your CocosProject/Classes folder:





4. Now, open folder External Cocos Helper Android Frameworks:





5. Copy all file in Classes folder to your CocosProject/Classes


6. Copy folder "res" and "src" to your CocosProject/proj.android folder, overwriten this.


7. Open AndroidManifest.xml on SonarCocosHelperCPP folder .


8. Change package name of this to your cocos package name.


9. Save then copy this AndroidManifest.xml to your CocosProject/proj.android, remember overwriten .


10. Open 
"...\External Cocos Helper Android Frameworks\Frameworks"
copy GooglePlayServices folder 
to "CocosProject\proj.android\src\sonar\systems\frameworks"




Second: Let's do some work on Eclipse:

1. Choose Help -- > install new software.





2. Paste this link to Work With: https://dl-ssl.google.com/android/eclipse/


3. Press add then tick to Develop Tools, we need this to build our project with android develop kit.





4. Open your CocosProject\proj.android\jni\Android.mk, edit this like bellow, do this, and you will never need to add any new class to this:


LOCAL_PATH := $(call my-dir)
CLASSES_PATH := $(LOCAL_PATH)/../../Classes

include $(CLEAR_VARS)

LOCAL_MODULE := cocos2dcpp_shared

LOCAL_MODULE_FILENAME := libcocos2dcpp


LOCAL_SRC_FILES := hellocpp/main.cpp \
$(subst $(LOCAL_PATH)/,,$(wildcard $(CLASSES_PATH)/*/*.cpp)) \
$(subst $(LOCAL_PATH)/,,$(wildcard $(CLASSES_PATH)/*.cpp)) \

LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes

# _COCOS_HEADER_ANDROID_BEGIN
# _COCOS_HEADER_ANDROID_END


LOCAL_STATIC_LIBRARIES := cocos2dx_static

# _COCOS_LIB_ANDROID_BEGIN
# _COCOS_LIB_ANDROID_END

include $(BUILD_SHARED_LIBRARY)

$(call import-module,./prebuilt-mk)

# _COCOS_LIB_IMPORT_ANDROID_BEGIN
# _COCOS_LIB_IMPORT_ANDROID_END


5.  Let's add your cocos project to Eclipes by import this, look image bellow to see how to add:






6. You will see some error, that is good, because we don't add Google Service Libary to this. Now , we'll add. First, copy google play service folder to your CocosProject folder, you can look at google play service on this destination:

"C:\Program Files (x86)\Android\android-sdk\extras\google\google_play_services\libproject"

Then copy :
"C:\Program Files (x86)\Android\android-sdk\extras\android\support\v4\android-support-v4.jar"
to YourGoogle_play_servicesFolder\libs


7. Import your Google Play Service libary to Eclipse, do same when import your project:





8. Then, right click on your project in eclipes, choose properties --> Android --> Choose Android 6.0.








9. Then press Add, choose your google play service lib you added before. Press OK.





10. On Eclipes Bar on top choose Project --> Clean, do this to check out/refresh project, if have some error it will show for us. For now, all error gone.





11. Again,  right click on your project in eclipes, choose properties-->Java Build Path-->Libaries Tab--> Add Jar:

- Now Open google-play-service_lib, choose 2 .jar file on Libs folder:
+ android-support-v4.jar
+ google-play-services.jar

- And 1 .jar file on bin folder:
+ google-play-services_lib.jar







12. Change to tab Order and Export:
- Tick to 3 jar file we added above.




13. Copy:
"...\YourGooglePlayServiceLibaryFolder\res\values\version.xml"
to
"...\YourCocosProjectFolder\proj.android\res\values\"


14. Open:
"...\YourCocosProjectFolder\proj.android\AndroidManifest.xml"


15. Uncomment this:


 <!-- Required for Google Play Services  -->
        <meta-data
            android:name="com.google.android.gms.games.APP_ID"
            android:value="@string/google_play_game_app_id" /> 
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
        <!-- End here requirement for Google Play Services -->


16. On Project view, open sonar.systems.framework->SonarFrameworkSettings:
- Set USE_GOOGLE_PLAY_GAME_SERVICES = true;





17. Use your Google Developer Console to to upload your app, then add Google Leader board , and get APP_ID, on this article, you can find many tuts To add your app to Google Play Console.


18. Open :
"...\CocosProject\proj.android\res\values\SonarFrameworkSettings.xml"

- Paste your appid to this.


19. Every things is Done, now try to Export your APP with Eclipes.


20. All API to access Google Play Service you can found here:

http://www.sonarsystems.co.uk/cocoshelper.php?type=reference&plugin=helper-googleplayservices



Remember Include "SonarFrameWorks.h" and use namespace SonarCocosHelper.


Thanks for read this! I write this to share to any one have issue on development, hope you will do like me when learn some thing good, it will help us - developer - on game development way.  ^ ^

0 comments: