Google Play Marketにて100MB以上のアプリをストアにアップロード


iTunes Storeでは問題ないんですが、Google Play Marketにアプリを登録する際にアプリが100MB以上だとファイルを分割しないといけないらしい。
メインのapkファイルと、obbファイル(Opaque Binary Blob)というものに分ける必要がある。
obbファイルというのは暗号化されたディスクイメージみたいなものらしい。
詳しくはこちら
キノコの自省録 | Expansion Filesについて(1) – obb作成編

分割自体はUnityであればビルドセッティングのAndroidのPublishing Settingsから
split_app_binary
この「Split Application Binary」というのをチェックすれば自動で分けてかき出してくれるので便利。

作られたapkとobbをアップロードすればあとは自動でアプリをインストール時にobbファイルも追加で落としてくれて一件落着…なのですがどうもobbファイルのダウンロードに失敗したりディスク容量やネットワークの関係やユーザーのキャンセル操作で落とされないことがあるらしい…
その際の対処処理は自前で書かないといけなく、そのためのライブラリ「Google Play OBB Downloader」もUnityから提供されている。

これを使って実装をすると

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using UnityEngine;
using System;
using System.Collections;
 
/// <summary>
/// Androidのobbファイルがなければ読み込む。
/// 読み込み完了、もしくは他のプラットホームではシーンを移動。
/// </summary>
public class OBBLoader : MonoBehaviour {
    /// <summary>
    /// 遷移するシーンの名前。
    /// </summary>
    public string nextSceneName;
 
    /// <summary>
    /// obbへのパス。
    /// </summary>
    string expansionFilePath;
 
    /// <summary>
    /// 初期化済みかどうか。
    /// </summary>
    bool isInit = false;
 
    /// <summary>
    /// Start.
    /// </summary>
    IEnumerator Start() {
        #if !UNITY_EDITOR && UNITY_ANDROID
        yield return StartCoroutine(this.CheckAndDownLoadOBBCoroutine());
        #else
        this.isInit = true;
        #endif
 
        if (this.isInit)
            Application.LoadLevelAsync(this.nextSceneName);
        else
            Debug.LogError("初期化失敗");
 
        yield return 0;
    }
 
    /// <summary>
    /// OBBファイルをダウンロード済みかどうかをチェックして、なければダウンロードする。
    /// </summary>
    IEnumerator CheckAndDownLoadOBBCoroutine() {
        this.expansionFilePath = GooglePlayDownloader.GetExpansionFilePath();
 
        if (this.expansionFilePath == null) {
            Debug.LogError("External storage is not available!");
            yield break;
        }
 
        string mainPath = GooglePlayDownloader.GetMainOBBPath(this.expansionFilePath);
        string patchPath = GooglePlayDownloader.GetPatchOBBPath(this.expansionFilePath);
 
        // 未ダウンロードであればダウンロードさせる
        if (mainPath == null || patchPath == null) {
            GooglePlayDownloader.FetchOBB();
            yield return StartCoroutine(this.CheckDownloadCoroutine());
        }
        // ダウンロード済み
        else {
            this.isInit = true;
        }
    }
 
    /// <summary>
    /// ダウンロードのチェック。
    /// </summary>
    IEnumerator CheckDownloadCoroutine() {
        string mainPath = null;
 
        do {
            mainPath = GooglePlayDownloader.GetMainOBBPath(this.expansionFilePath);
            yield return new WaitForSeconds(0.5f);
        } while (mainPath == null);
 
        // DL済みファイルの読み取り確認
        WWW www = WWW.LoadFromCacheOrDownload("file://" + mainPath, 0);
 
        yield return www;
 
        if (www.error != null)
            Debug.LogError("WWW error : " + www.error);
        else
            this.isInit = true;
    }
}

こんな感じになった。
(ダウンロードのチェックというのはもしかしたら不必要?)

参考)
mizoguche.info | Unity で APK が 50MB 超えたので OBB Downloader 使う
exoa | Tutorial Unity 4 apk splitting into OBB for google play(下の方にソースのってる)
Github | kankikuchi/LoadManager.cs

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です