cocos2d-x Android GREE SDK 연동 세번째. AndroidManifest.xml 설정 및 GREE SDK 초기화

Android GREE SDK Build 및 개발 환경 준비가 마무리 되었다면 이제 cocos2d-x Helloworld에 GREE SDK를 붙있는 작업중 AndroidManifest.xml 설정 및 GREE SDK 초기화
단계로 진행해보겠습니다.

일단 초기화에 필요한 gree_platform_configuration.xml이라는 파일을 만들어야 합니다.

진행중인 프로젝트의 proj.android\res 폴더에 xml 폴더를 만드시고 gree_platform_configuration.xml 파일을 만들어 아래와 같은 내용을 기입합니다.

<?xml version="1.0" encoding="utf-8"?> 

<properties>

         <applicationId>NNNN</applicationId>

         <consumerKey>XXXXXXXXXXXX</consumerKey>
         <consumerSecret>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</consumerSecret>
         <developmentMode>sandbox</developmentMode>          
</properties>

applicationid, consumerKey, consumerSecret 값은 GREE Sendbox에 등록한 App의 Detail정보를 보면 확인할 수 있습니다. 3개의 값은 필수요소인 듯하고 나머지 GREE 개발 가이드에 보면 파라미터가 몇가지 더 있습니다. 자세한것은 개발 가이드 참고하세요.

consumerKey, consumerSecret 두개는 보안을 위해 암호화를 해서 사용할 수도 있다네요. 이건 따로 정리하던가 해야겠습니다.

developmentMode는 말그대로 개발 모드냐 아니냐에 대한 설정인데 sandbox로 하면 Sandbox에서 테스트 하는 모드고 production은 App을 정식으로 Store에 올릴 때 하면 됩니다.

다음으로 Application을 상속하는 클래스를 만들어서 GREE SDK를 초기화 처리하는 부분을 추가해야합니다.

package org.cocos2dx.application;

import net.gree.asdk.api.GreePlatform;
import android.app.Application;

public class GreeApplication extends Application {
 @Override
 public void onCreate(){
  super.onCreate();
  GreePlatform.initialize(getApplicationContext(), R.xml.gree_platform_configuration, null);
 }
}

위 링크를 참고하셔서 만드시고 이름은 GreeApplication이라고 하겠습니다. onCreate를 Override해서 GREE를 초기화 합니다. 2번째 인자는 위에서 만들었던 xml 파일입니다.

초기화 처리의 마지막으로 GREE SDK가 필요로 하는 permission과 activity를 위해 작업중인 프로젝트의 AndroidManifest.xml을 수정해야합니다. 이 포스팅에서는 cocos2d-x Helloworld의 AndroidManifest.xml 이겠죠. 

<application> 태그에는 방금 만들었던 Application 상속 class인  android:name="GreeApplication" 를 추가해줍니다. 다음으로

    <!-- GREE SDK가 필요로 하는 permission -->
    <uses-permission android:name="android.permission.INTERNET"/> 
     <uses-permission android:name="android.permission.READ_CONTACTS"/> 
     <uses-permission android:name="android.permission.WAKE_LOCK"/> 
     <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.WRITE_EXTERNAL_STORAGE"/> 
     <uses-permission android:name="android.permission.GET_TASKS" /> 
     <!-- org.cocos2dx.application를 각 개발 App의 Package 이름으로 변경한다.  --> 
     <uses-permission android:name="org.cocos2dx.application.permission.C2D_MESSAGE"/> 
     <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/> 
     <!-- org.cocos2dx.application를 각 개발 App의 Package 이름으로 변경한다.  --> 
     <permission 
         android:name="org.cocos2dx.application.permission.C2D_MESSAGE" 
         android:protectionLevel="signature"/>

위와 같은 permission을 추가합니다. 이때 주석처럼 org.cocos2dx.application 부분은 각 개발하시는 App의 Package 이름으로 변경하시기 바랍니다. 다음으로 GREE SDK Activity를 추가해야합니다.

         <!-- 여기서 부터 GREE SDK Activity -->
        <activity
            android:name="net.gree.asdk.core.dashboard.DashboardActivity"
            android:configChanges="orientation" >
        </activity>
        <activity
            android:name="net.gree.asdk.core.notifications.ui.NotificationBoardActivity"
            android:configChanges="orientation"
            android:theme="@android:style/Theme.Translucent.NoTitleBar" >
        </activity>
        <activity
            android:name="net.gree.asdk.core.dashboard.ModalActivity"
            android:configChanges="orientation" >
        </activity>
        <activity
            android:name="net.gree.asdk.core.auth.SetupActivity"
            android:configChanges="orientation|keyboardHidden"
            android:launchMode="singleTask"
            android:theme="@android:style/Theme.Translucent" >
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <!-- XXXX를 어플리케이션  ID 로 교체  --> 
                <data
                    android:host="reopen"
                    android:scheme="greeappXXXX" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <!-- XXXX를 어플리케이션  ID 로 교체  --> 
                <data
                    android:host="get-accesstoken"
                    android:scheme="greeappXXXX" />
            </intent-filter>
        </activity>
        <activity
            android:name="net.gree.asdk.core.notifications.RelayActivity"
            android:configChanges="orientation"
            android:excludeFromRecents="true"
            android:launchMode="singleInstance"
            android:noHistory="true"
            android:taskAffinity="" >
        </activity>
        <activity
            android:name="net.gree.asdk.core.ui.SSOAuthReceiverActivity"
            android:configChanges="keyboardHidden|orientation"
            android:launchMode="singleInstance"
            android:theme="@android:style/Theme.Translucent.NoTitleBar" >
            <intent-filter>
                <action android:name="android.intent.action.SEND" />

                <category android:name="android.intent.category.DEFAULT" />

                <data android:mimeType="GREEApp/SSOAuthResponse" />
            </intent-filter>
        </activity>
        <activity
            android:name="net.gree.asdk.core.ui.ServiceResultreceiverActivity"
            android:configChanges="orientation|keyboardHidden"
            android:launchMode="singleTask"
            android:theme="@android:style/Theme.Translucent" >
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <!-- XXXX를 어플리케이션  ID 로 교체  --> 
                <data
                    android:host="serviceresponse"
                    android:scheme="greeappXXXX" />
            </intent-filter>
        </activity>
        <activity
            android:name="net.gree.asdk.core.dashboard.PostingActivity"
            android:configChanges="orientation" />
        <activity
            android:name="net.gree.asdk.core.dashboard.SubBrowserActivity"
            android:configChanges="orientation" />
        <activity
            android:name="net.gree.asdk.core.dashboard.PostingMultipleActivity"
            android:configChanges="orientation" />
        <activity
            android:name="net.gree.asdk.core.dashboard.ImageViewActivity"
            android:configChanges="orientation">
        </activity>

        <service android:name=".C2DMReceiver" />

        <receiver
            android:name="com.google.android.c2dm.C2DMBroadcastReceiver"
            android:permission="com.google.android.c2dm.permission.SEND" >
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <!-- org.cocos2dx.application를 각 개발 App의 Package 이름으로 변경한다.  --> 
                 <category android:name="org.cocos2dx.application" />
            </intent-filter>
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
             <!-- org.cocos2dx.application를 각 개발 App의 Package 이름으로 변경한다.  --> 
                 <category android:name="org.cocos2dx.application" />
            </intent-filter>
        </receiver>

        <service android:name="com.google.android.c2dm.intent.REGISTER" />

        <receiver
            android:name="net.gree.asdk.api.ConnectionChangeReceiver"
            android:label="NetworkConnection" >
            <intent-filter>
                <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
            </intent-filter>
        </receiver>

역시나 주석부분의 org.cocos2dx.application를 각 App의 Package이름에 맞게 변경해주시기 바랍니다. 각 Activity에 대한 설명은 GREE SDK 개발 가이드를 참고하세요. 마지막으로 기존에 있던 .ApplicationDemo Activity를 수정해야합니다.          

            <intent-filter>
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
            <!-- XXXX를 어플리케이션  ID 로 교체  -->
                <data
                    android:host="start"
                    android:scheme="greeappXXXX" />
                <data
                    android:host="start"
                    android:scheme="greeappopenXXXX" />
            </intent-filter>

위와 같이 intent-filter를 추가해줍니다. XXXX부분은 각 App의 ApplicationId로 변경합니다. 초기화 처리가 마무리 되었습니다. 추가된 permission이나 activity가 많은데 일단 GREE SDK 개발 가이드에 있는 것 그대로 가져와서 그렇고, 나중에는 필요한 것만 추가해서 사용하면 될 듯싶네요.

자 이제 빌드를 한번 해봅니다. 만약,

빌드시 R.java가 생성되지 않는다면 역시나 따로 정리를 했으니 링크를 확인하시기 바랍니다.

빌드를 완료하셨다면, Ctrl + F11을 눌러 실행을 해보시기 바랍니다.

Unable to resolve superclass of Lnet/gree/asdk/core/auth/SetupActivity; (116)
Link of class 'Lnet/gree/asdk/core/auth/SetupActivity;' failed
Could not find method net.gree.asdk.core.auth.SetupActivity.setup, referenced from method net.gree.asdk.core.auth.AuthorizerCore.logout
VFY: unable to resolve static method 3814: Lnet/gree/asdk/core/auth/SetupActivity;.setup (Landroid/content/Context;Ljava/lang/String;Lnet/gree/asdk/core/auth/SetupActivity$SetupListener;)V
Unable to resolve superclass of Lnet/gree/asdk/core/auth/SetupActivity; (116)
Link of class 'Lnet/gree/asdk/core/auth/SetupActivity;' failed
Could not find method net.gree.asdk.core.auth.SetupActivity.setupNewTask, referenced from method net.gree.asdk.core.auth.AuthorizerCore.reauthorize
VFY: unable to resolve static method 3816: Lnet/gree/asdk/core/auth/SetupActivity;.setupNewTask (Landroid/content/Context;Ljava/lang/String;Lnet/gree/asdk/core/auth/SetupActivity$SetupListener;)V

만약 런타임에 위와같은 에러 로그가 남는다면 GREE SDK Build시 추가했던 android-support-v4.jar 파일을 Build Path의 Order and Export에서 체크하지 않아서 발생한 것입니다.

스샷과 같이 GreeSdk 프로젝트에 추가한 android-support-v4.jar를 꼭 체크하시기 바랍니다.

이것으로 GREE SDK 초기화 적용이 끝났습니다. 다음에는 Casual Game API( Leaderboards, Achievements )전 단계인 GREE Login/Logout까지를 정리해보겠습니다.

댓글

이 블로그의 인기 게시물

'xxx.exe' 프로그램을 시작할 수 없습니다. 지정된 파일을 찾을 수 없습니다.

goorm IDE에서 node.js 프로젝트로 Hello World Simple Server 만들어 띄워보기

애드센스 수익을 웨스턴 유니온으로 수표대신 현금으로 지급 받아보자.