Try   HackMD

讓 RPG Maker MV/MZ 也能在 Android 手機上遊玩的教學

本教學文章我將不再繼續更新維護了,並且完全開源給所有人任意修改使用和二次發佈等,但是也不要再問我關於本教學文章的任何問題,我一直以來都免費提供教學資源給你們,卻沒有任何人想要贊助支持我。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

本篇教學文章是將原本已經被我上鎖的舊版教學文章「使用 APK Expansion Files(OBB) 來解決輸出 APK 大容量的限制」進行全面升級,主要除了也是因為舊版教學文章的程式碼太過老舊且不太能支援現在的Android 環境,而且今年 8 月 Google 官方也宣布將統一改用「AAB」的格式來替代原本一直以來使用的「APK」以及「OBB」格式。

總之,這次教學除了有改善原本舊版文章的 IAP 內購Admob 廣告之外,也新增其他幾項功能,
當然,這次教學也將教你輸出成 AAB 格式來讓你上架到 Play 商店。

  • 2022/02/28 更新
    更新插件使用條款,以及新增關於「支援平台」資訊和最佳化一些程式碼。
  • 2021/08/10 更新
    修正部分 Android 裝置無法正常執行的問題,並且新增「額外補充」的教學內容。

◆ 第一步

到以下網址下載 Android Studio

https://developer.android.com/studio

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

打勾同意之後,按「Download Android Studio」開始下載並安裝 Android Studio。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

安裝完後執行 Android Studio 並展開右上角的選單項目,選擇「SDK Manager」。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

在「SDK Platforms」勾選安裝最新版的 Android 版本,
這裡我是勾選「Android 11.0®」,當然你要按照我圖中的設定打勾我也沒意見。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

切換到「SDK Tools」將紅色勾勾標註的必要工具都打勾,
當然你要按照我圖中的設定打勾我也沒意見,
按下「OK」之後會執行下載並安裝勾選的所需套件。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

◆ 第二步

開啟你的 RPG Maker MV 的專案,並按「檔案」→「部署…」,
選擇「Android / iOS」之後按下「OK」來輸出。

[RPG Maker MV]

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

而 RPG Maker MZ 的專案為「檔案」→「部署…」,選擇「網頁瀏覽器 / Android / iOS」之後按 OK
來輸出。

[RPG Maker MZ]

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

素材檔名絕對不要有包含中文或亂碼,當然也包含任何的空格都不能有。

◆ 第三步

到以下的 GitLab 網址下載需要的 Android Studio 專案(MyApplication.7z),
以及 IAP 用的範例專案(「ProjectIAP_MV」或「ProjectIAP_MZ」),
也包含範例專案內的 NekoGakuen_AndroidPlus.js 插件在內。

https://gitlab.com/MiraiSoSad/android-studio-for-rpg-maker-mvmz/-/tree/zh_TW

回到 Android Studio 並按下上方的「Open」,
選擇解壓縮剛剛下載的Android Studio 專案資料夾(MyApplication)後按下「OK」,
接著開啟專案之後等待右下角的進度條跑完專案的同步即可。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

◆ 第四步

在「File」→「Project Structure…」那邊的「SDK Location」之中,
點擊「Gradle Setting」後在「Gradle JDK」選項中選擇「Download JDK」。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

接著,在「Version」選擇最新的版本號之後,
在「Vendor」選擇「Oracle OpenJDK」後按下「Download」。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

◆ 第五步

如果要進行 Play 商店上架的話,請選擇「IAP」的部分,
反之,如果只是要輸出並放在手機上玩的話,請選擇「Only」的部分。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

■ Only

首先,來解說下「Only」的使用方法,將你剛剛輸出好的 RPG Maker MV/MZ 專案,
放在「MyApplication\Only\src\main\assets\www」的資料夾中。

在「Only」之下的「res」→「values」→「strings」按滑鼠右鍵,
選擇「Open Translations Editor」後即可在「Default Value」
修改「app_name」來設定你的 APP 遊戲名稱等字串參數。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

接著選擇「Build」→「Build Bundie(s) / APK(s)」→「Build APK(s)」輸出。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

等待輸出完成之後,在「MyApplication\Only\build\outputs\apk\debug」的資料夾,
可以找到三個apk檔案後只要把「Only-universal-debug.apk」安裝到手機上即可遊玩。

■ IAP

接著來解說下「IAP」的使用方法,將你剛剛輸出好的 RPG Maker MV/MZ 專案,
放在「MyApplication\RPGAssets\src\main\assets」的資料夾中。

在「File」→「Project Structure…」在「Modules」把「Default Config」的三個參數值修改一下,
分別是「Application ID」、「Version Code」、「Version Name」。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

■ 變更 APP 圖示

將「mipmap」按滑鼠右鍵選擇「Delete…」以便進行更換 APP 的圖示。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

接著在「res」按滑鼠右鍵選擇「New」→「Image Asset」。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

在「Foreground Layer」的「Source Asset」和「Scaling」進行 APP 圖示的設定。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

在「Background Layer」的「Source Asset」進行 APP 圖示背景色彩的設定。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

在 IAP 之下的「Strings」按滑鼠右鍵選擇「Open Translations Editor」來設定一些進階參數。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

「app_name」設定你的 APP 遊戲名稱。
「license_key」設定你的應用程式簽署金鑰,

而這個部分可以在「Play管理中心」左側最下方的「營利設定」中找到。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

「test_mode」設定是否為測試模式,但是當你在 Play 商店上架時,記得將此項設為「false」。
剩下的五項則為「AdMob」廣告單元的部分,目前預設所填入的是測試用的廣告單元,
如果你有使用到 AdMob 廣告單元,記得換成你自己帳號的 AdMob 廣告單元,
而 AdMob 廣告的操作使用,這邊就先不特別說明了。

最後,在「Build」→「Generate Signed Bundle / APK…」那邊,
選擇「Android App Bundle」並按「Next」,然後建立或使用你的簽署金鑰,
完成後將輸出好的 AAB 檔案上傳至 Play 商店即可,
當然簽署金鑰和上架到 Play 商店這兩個部分我就不特別說明了。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

■ 額外補充

● 如何讓 RPG Maker MV 也能支援觸控 UI?

補充說明,雖然MV本身並無內建內建手機觸控的按鈕UI功能,但可以使用官方提供的「TouchUI.js」插件來解決手機操作遊玩的問題。

而TouchUI.js插件平常放在D:\Steam\steamapps\common\RPG Maker MV\dlc\KadokawaPlugins_New\js\plugins的資料夾中。

● 如何變更Splash圖像?

在「MyApplication\IAP\src\main\res\drawable」將「logo.png」換成你自己 APP 啟動畫面的圖檔。

如果是 Only 的話路徑為「MyApplication\Only\src\main\res\drawable」。

● 如何將手機畫面的顯示方向變更為直向顯示?

這邊的話將教你如何在 Android Studio 專案中修改手機顯示方向,而 RPG Maker MV/MZ 的解析度設定應該就不用我特別教你才對。
首先分別在「manifests/AndroidManifest.xml」和「res/layout/activity_main.xml」這兩個檔案進行修改,
在「AndroidManifest.xml」檔案中的第 21 行程式碼,將"sensorLandscape"改為"sensorPortrait",
在「activity_main.xml」檔案中,切換為「Design」後在「main」將「orientation」的參數改為「vertical」。

● 為什麼我使用 RPG Maker MZ 遊戲在 Android 裝置上遊玩會一直停在黑畫面?

您可以試著修改在專案資料夾內的 js/rmmz_managers.js 中第 2109 行左右的語法。

SceneManager.isGameActive = function() {
    // [Note] We use "window.top" to support an iframe.
    try {
        return window.top.document.hasFocus();
    } catch (e) {
        // SecurityError
        return true;
    }
};

修改為

 SceneManager.isGameActive = function () { return true; };

《Mirai》Patreon創作:
https://www.patreon.com/MiraiDiary

《Mirai》個人推特(X):
https://twitter.com/Mirai_so_Sad

《Mirai》itch.io頁面:
https://miraisosad.itch.io

《Mirai》個人Instagram
https://www.instagram.com/miraisosad/

tags: 貓咪學園 NekoGakuen RPG Maker RPG Maker MV RPG Maker MZ Android Studio