Setup AndroidStudio (version 1.7.0 or later)

This page is not available in English.
Please select another language.

このページでは、Mobage Native SDK (Android 版) のセットアップ方法について解説します。

Mobage Native SDK ライブラリをインポートする(Android Studio 版)

Android Studio のメニューバーから [File] -> [Project Structures...] を選択します。

Project Structure ダイアログが開きますので、左上の「+」ボタンをクリックします。

Create New Module ダイアログが開きますので、画面下部にある More Modules の「Import Gradle Project」を選択し、[Next] ボタンをクリックします。

Source directory を選択します。右側の [...] ボタンをクリックします。

クリックすると、Source directory 選択画面が表示されますので、[MobageNativeAndroid] プロジェクトを選択し、[OK] ボタンをクリックします。(Mobage Native SDK の Android ライブラリプロジェクトのディレクトリです)

Mobage Native SDK のディレクトリが Source directory ボックスに入りますので、そのまま [Finish] ボタンをクリックします。

以下のような画面が表示されますが、そのまま [Finish] ボタンをクリックします。

完了してもそれだけではプロジェクトが表示されません。 setting.gradle へ include ':MobageNativeAndroid' を追加します。

settings.gradle へ追加後、右上に表示される「Sync Now」をクリックします。

左側のペインに MobageNativeAndroid プロジェクトが表示されているのを確認してください。

再度 Project Structure ダイアログを開き、① 既存プロジェクトの Module 名(この場合 app)を選択し、②上部の [Dependencies] タブをクリック、③ 左下の [+] ボタンをクリックします。

以下のような選択メニューが表示されますので、[3 Module dependency] をクリックします。

[Choose Module] ダイアログが表示されますので、[:MobageNativeAndroid] を選択し、[OK] ボタンをクリックします。


以上で Mobage Native SDK のインポートが完了しました。

 

Sync 時に以下のエラーが出ることがありますが、無視して問題ありません。

  • Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.


AndroidManifest.xml を設定する

Mobage Native SDK を用いた開発では、Android 端末が元から持っている様々なネイティブ機能を利用、あるいは制限するために、AndroidManifest.xml の中に下記のような設定のための記述を含める必要があります。

  • manifest タグの要素に xmlns:tools="http://schemas.android.com/tools" を追加します。
  • 以下のパーミッションが必要です。
    • android.permission.INTERNET
      android.permission.ACCESS_WIFI_STATE
      android.permission.WRITE_EXTERNAL_STORAGE
      android.permission.ACCESS_NETWORK_STATE
      com.android.vending.BILLING
  • 画面の向き変更に対応していないため、Activity に対して画面の向きを固定します。
  • Main の Activity については standard モードおよび singleTop モードで起動するように設定します。
  • シングルサインオン用に SDK の内部に Activity を保持しているため、この Activity を外部から呼び出せるように設定します。
  • 以下の Activity の設定が必要です。
    • ダッシュボード Activity (MobageDashBoardActivity) の設定が必要です。 
    • MobageProxyActivity の設定が必要です。
  • application タグの android:icon="@drawable/icon" については自由に設定が可能です。 (参考: https://developer.dena.jp/mbga/admin/news/2001/entry
  • com.mobage.android.TrackingReceiver の設定が必要です。
上記と他の必要な設定を全て記述すると、AndroidManifest.xml は下記のようになります。
MobageDashboardActivity の screenOrientation に landscape を指定することができます。landscape に設定することで Mobage の UI が横画面で開くようになりますので、横画面のアプリでは指定されることを推奨します。

下記の箇所は、お使いの環境に合わせて書き換えてください。
${YourActivityName}:
  Activity 名 (FQCN: パッケージ名をつけたクラス名) に書き換えてください。

${YourApplicationId}:
  Mobage のアプリケーションID に書き換えてください。

Mobage Native SDK 1.4.7 より com.mobage.android.TrackingReceiver を必ず追加しなければならなくなりました。
もし Install Referrer を他の Receiver に転送したい場合は、以下のように記載して下さい。

  • meta-data の android:name は forward. で始まるユニークな名前を設定して下さい。
  • android:value は受け取る Receiver 名を FQCN で記載して下さい。
    TrackingReceiver が他の Receiver から Intent を転送してもらうこともできます。たとえば AppBrain と Google の CampaignTrackingReceiver とを併用する場合は、以下のように記述することができます。

 

F.O.X for Mobage について

Mobage Native SDK 1.4.7.4 以降、以下のように F.O.X for Mobage の利用を選択できるようになりました。

  • F.O.X for Mobage を利用する場合は、何もせずに通常のインポート手順で問題ありません。
  • F.O.X for Mobage を利用しない場合や、アプリケーションで独自に F.O.X を組み込む場合には、MobageNativeAndroid の代わりに MobageNativeAndroidWithoutFOX をインポートしてください。ライブラリの指定も同様です。

Android Market In-app Billing の設定をする

In-App Billing (以下、IAB) は、アプリ内でデジタルコンテンツを販売することを可能にする Google Play(旧Android Market) のサービスです。
IAB 対応のため Proguard を内部で使用します。それに伴い、既存の非公開 API が削除されております。また、アプリケーションを一般公開する際に多マーケットに対応するため、デベロッパーサイトへアップロードされたアプリケーションからパッケージ名を変更致します。

IAB 機能を利用する為には、下記のステップを踏んで下さい。

[1. FQCN でのクラス名の指定]

下記のクラスの参照の際は FQCN (完全修飾名、パッケージ名をつけたクラス名) で記述してください。

  • AndroidManifest.xml に記述するクラス
  • R クラス (R クラスを参照する全てのプログラムコード中)

[2. リソースファイル名の制限]

下記のアイコンファイル名は SDK が予約しています。予約された名前からファイル名を変更しないでください。

  • /res/drawable/icon.png
  • /res/drawable-hdpi/icon.png
  • /res/drawable-ldpi/icon.png
  • /res/drawable-mdpi/icon.png

[3. マーケット情報設定ファイル名の予約]

下記のマーケット情報設定ファイルは、SDK が予約しています。予約されたファイル名と同じ名前のファイルを作成しないでください。

  • /assets/billing_config.xml

[4. Intent 起動について]

広告サービス等で、Intent 起動が必要な場合に、com.mobage.android.activity.MobageProxyActivity に設定された Intent Filter は使用しないでください。

About the usage of Advertising ID (Important)

From Aug 1, 2014 all uploaded applications on Play Store will need to use Advertising ID for advertising purpose due to the policy changes on Google Play.

The usage of Android’s AdvertisingID (AdID) is required for Ad tracking purpose when using Cross Promotion or our Smartphone R/S plan.
To use the AdID you will need to implement Google Play Services.

 

How to Import Google Play service SDK

Your application will need to reference the Google Play service SDK to implement the AdID.  
See below on how to import Advertising ID into your project.

  1. Run Android SDK Manager from eclipse
  2. Check on「Extras」 > 「Google Play service」 and install the package
  3. Select「Import」 -> 「Android」 -> 「Existing Android Code Into Workspace」 and import "${ANDROID_SDK_PATH}/extras/google/google_play_services/libproject/google-play-services_lib"

    Do not reference the actual path but select "Copy projects into workspace" so it will copy the library to your workspace


  4. Go to「Project の Properties」 > 「Android」 > 「Library」 and add "google-play-service_lib" as a Library Project
     
  5. Add the following to the <application> tag in the AndroidManifest.xml

Make sure you have confirmed that Google Play Game Services is linked to your App by following Confirming Google Play Game Services.

Using Proguard with Google Play Game Services implemented

You will need to configure proguard.cfg or proguard-android.txt as below, when using proguard with Google Play Game Services.


Confirming Google Play Game Services

Make sure to confirm that AdvertisingIdClient class on Google Play Game Services library is present by following the instructions below.

  • Open apk file with apktool and confirm that "/smali/com/google/android/gms/ads/identifier/AdvertisingIdClient.smali" exists.
  • Startup the application with SDK installed and confirm on logcat ($adb logcat) that you don't see the following errors.

If you find any issues by confirming above, you can solve these by following the next steps.

  • Remove "google-play-services_lib" library link from your project and add "libs/google-play-services.jar from" from  "google-play-services_lib" to your project.
  • If you are using old versions of Android SDK Tools or Android SDK Build-Tools, you can try lower the "google-play-services_lib" to version 4.
  • For Invalid ApplicationInfo or MetaData error , please check that you have added "meta-data" tag for goole play game services.
  • For IllegalStateException make sure you have correct value on meta-data.

If you see Invalid ApplicationInfo or MetaData error on logcat make sure you have meta-data and google play game services version writing on your AndroidManifest. 

Using ProGuard with Mobage SDK implemented

Make sure to add the following to your proguard-project.txt when using ProGuard.

 

Using ProGuard with F.O.X for Mobage implemented

Add the following ProGuard settings when implementing F.O.X for Mobage.


更新履歴

  • 2018/11/14
    • Mobage Native SDK 1.7.0 リリースに伴い、大幅に修正
  • 2014/08/20
    • Mobage Native SDK 1.4.7 リリースに伴い、新規作成

PREVIOUS

Setup AndroidStudio (version 1.4.7 or later)

NEXT

How to develop in Eclipse