RPG Maker [MV] html to android apk with Android Studio [Koala] *Latest* (&qu
Android Studio version used: Android Studio Koala Feature Drop | 2024.1.2 Canary 4Oracle JDK version used: oracle open jdk 20.0.2
this guide is based on the original: https://hackmd.io/@Mirai/RPGMakerMVMZ-Android_eng#■-Extra
preface
this guide does not cover:
- implement ads/in app purchases
- sign the apk
- do any required steps to upload to Play Store
- any part of the "extra" section of the og guide
- the most recent version of android studio
- or guarantee anything will work
this guide does cover:
- what worked for me
- basic troubleshooting tips
- potential solutions for: "error- script error", "webpage not found", "error, failed to load ___", type errors from the built apk using this method.
some parts of the guide dont need much changing and may just be copied and pasted from the original.
*initial note: if your game files use " - " dashes supposedly there will be issues and this will not work, the og tutorial suggests changing all instances of " - " dashes into underscores " _ " like so.
--------------------------------------------------------
Step 1 (downloads)
--------------------------------------------------------
- Go to the following link to download Android Studio.
Click to expand...
> https://developer.android.com/studio - this link will take you to the latest version (right now its ladybug)
> https://developer.android.com/studio/archive - this link will take you to the archives where you can install older versions
- get an appropriate(?) version of oracle jdk (the og tutorial specifies for this, not sure if you can use others)
> https://www.oracle.com/java/technologies/javase/jdk20-archive-downloads.html - this like is an archive of oracle jdk ver 20, which is the highest version depicted in the og tutorial.
- get the og guide maker's all important webview wrapper files below from gitlab.
(those project files include an MV/MZ compatible plugin for those wacky IAP and ads etc you can play around with i have not looked at them yet. the partially English .js file called: NekoGakuen_AndroidPlus_TransMod, the other version is fully in Japanese, or maybe it's Chinese I forgot - its all kanji)
> https://gitlab.com/MiraiSoSad/android-studio-for-rpg-maker-mvmz/-/tree/en_US (webview wrapper files, zipped)
- extract the above files into a shallow folder of your choosing (shallow = not many folders deep) put it on your desktop if youre not sure. there was some warning about directory depth while trying to move the files once, so thats why i suggest this.
--------------------------------------------------------
Step 2 SDK selection
--------------------------------------------------------
After installing and running Android Studio, expand the menu item in the upper right corner and select SDK Manager.
Click to expand...
here you'll select which versions of android os you want to install, usually its a good idea to include a few older versions (like back to android 10 "Q"). be sure to include the version you're going to test/debug on obviously.
--------------------------------------------------------
Step 3 Deploy
--------------------------------------------------------
- go to rpg maker and deploy your game as android/ios (or android/ios/web browsers depending on version)
- exclude unused files, encrypt all files, have fun with the encryption key
*troubleshooting: if something doesnt work the first thing you can try is deploying as the other option. so if you first chose android/ios, deploy again as web browser. im not sure theres really a difference for MZ, but MV has them separate.
--------------------------------------------------------
Step 4 Open the project
--------------------------------------------------------
- launch android studio and open the project files that you downloaded.
the file you want to open is called MyApplication, it should have a little droid character next to it when you select it
- android studio will then sync the files, you can check the status in the bottom right
--------------------------------------------------------
Step 5 select the JDK version
--------------------------------------------------------
Under File → Project Structure…, select SDK Location. Click Gradle Setting and select Download JDK… from the Gradle JDK menu.
Click to expand...
this is not the directory in the version i used, however.
this is what mine looks like -
- then select either DOWNLOAD JDK (if youre ambitious) or ADD JDK and then select the one you downloaded presumably from the archive link above (like i said i chose oracle jdk 20.0.2, so here is where youd select that)
- the original guide specifies to select Oracle OpenJDK under Vendor when using the download method. not sure if this matters, but again i used oracle jdk 20.0.2.
--------------------------------------------------------
Step 6 "Only" method (again we are skipping the IAP section entirely)
--------------------------------------------------------
- go to your deployed RPG Maker MV project files and select the "www" folder, (NOT the folder that contains the www folder!) and COPY it into the assets folder:
MyApplication > Only > src > main > assets
Click to expand...
*troubleshooting: make sure you copy the "www" folder into the Only directory of the files, the src>main>assets directory exists elsewhere in the MyApplication files so double check its correct.
Under Only, mouse right-click res → values → strings.
After selecting Open Translations Editor,
you can change app_name in Default Value to set your APP game name and other string parameters.
Click to expand...
*troubleshooting: this gave me some trouble a few times, so if you dont want to repeat all prior steps if you get the same issue, go copy the entire MyApplication folder you have now, paste it somewhere else, rename it and then try this part. the issue i got was trying to enter the new name in the fields wasnt working, it wouldnt save anything. i had to re do the whole thing from about step 4 with a fresh copy of MyApplication files.
- in the second photo above, you edit the text in the boxes where the red arrow is pointing, not the bottom section.
- then in the most forgettable area ever, click the three horizontal lines in the upper left corner (again for this version of android studio, not sure how it is in other versions)
- you should see a regular looking toolbar at the top now, from FILE in the upper left, hover over to BUILD toward the right and click BUILD APK(s)
- there may or may not be a "test mode" area under the translation options, set it to false if this version is going to be published on the Play Store for example
- it should say Gradle Build Running in the bottom right with a progress bar
- then in the same area a notification should pop up saying it completed like below, expand it or go to the notification bell in the upper right corner to see it
- you can press the blue highlighted LOCATE button to open the file directory where the apk was sent, or check here: MyApplication > Only > build > outputs > apk > debug
After the output is finished, in the folder MyApplication\Only\build\outputs\apk\debug, you can find three apk files, just install Only-universal-debug.apk to your Android phone and play game.
Click to expand...
- the output file should be called something like "Only-debug.apk"
--------------------------------------------------------
changing the app icon - fancy and automatically dynamic!
--------------------------------------------------------
- do this before building the apk if you want the icon to show up, I put it after because it's not "required"
- go to the lefthand side of android studio and look for "mipmap"
- right click "mipmap" and select delete
- then right click "res" and select NEW > Image Asset
- you should see this window below
- click the folder icon by PATH and select your icon image file from the directory (png)
*tip: its hard to navigate this directory selector as its only words, it might be easy to leave/copy your icon in a shallow folder location like your desktop for this part.
- resize the image by dragging the slider by RESIZE around
- optional: go to background layer > source asset > asset type and select COLOR and adjust it however (transparent doesnt seem to be an option here)
- hit finish when done
now the fun part
--------------------------------------------------------
getting it all to work
--------------------------------------------------------
if you did all of this only to be greeted by something like, or exactly like the bottom image -
which says (for searchability purposes)
"Webpage not available
The webpage at https://example.com/assets/www/index.html could not be loaded because: net::ERR_INVALID_RESPONSE"
- youre not alone. i saw this error only one other place, unsolved: https://forums.rpgmakerweb.com/inde...ng-to-android-mv-android-client.84971/page-22
so why does this happen? uh well from what i understand is that calling the "index.html" file this way doesnt work for our purposes. its needs to be loaded a different way. basically the protocol is wrong because the apk game is not a url on a server its local files, but this code doesnt grant access to them. we do not have a url to replace the name with at Code:
.setDomain("example.com") // replace this with your website's domain
so that is how we know its not correct.
> open MainActivity.kt in android studio (hit shift twice and search for its name)
> find the section starting with: @SuppressLint("SetJavaScriptEnabled")
- it should look like this:
Code:
@SuppressLint("SetJavaScriptEnabled")var setWebView = { val webSettings = rpgwebview.settings webSettings.allowFileAccess = true webSettings.allowContentAccess = true webSettings.domStorageEnabled = true webSettings.mediaPlaybackRequiresUserGesture = false webSettings.useWideViewPort = true webSettings.databaseEnabled = true webSettings.loadWithOverviewMode = true webSettings.defaultTextEncodingName = "utf-8" webSettings.javaScriptCanOpenWindowsAutomatically = true webSettings.loadsImagesAutomatically = true webSettings.javaScriptEnabled = true webSettings.cacheMode = WebSettings.LOAD_DEFAULT webSettings.mixedContentMode = WebSettings.MIXED_CONTENT_ALWAYS_ALLOW rpgwebview.setLayerType(View.LAYER_TYPE_HARDWARE, null) val assetLoader = WebViewAssetLoader.Builder() .setDomain("example.com") // replace this with your website's domain .addPathHandler("/assets/", WebViewAssetLoader.AssetsPathHandler(this)) .build() rpgwebview.webViewClient = LocalContentWebViewClient(assetLoader) val inAppHtmlUrl = "https://example.com/assets/index.html" rpgwebview.loadUrl(inAppHtmlUrl) rpgwebview.addJavascriptInterface(AndroidInterface(this), "AndroidInterface")}
> cut from @SuppressLint until the closing bracket " } ", paste the new code below over it
Code:
@SuppressLint("SetJavaScriptEnabled")private fun setWebView() { val webSettings = rpgwebview.settings webSettings.allowFileAccess = true webSettings.allowContentAccess = true webSettings.domStorageEnabled = true webSettings.mediaPlaybackRequiresUserGesture = false webSettings.useWideViewPort = true webSettings.databaseEnabled = true webSettings.loadWithOverviewMode = true webSettings.defaultTextEncodingName = "utf-8" webSettings.javaScriptCanOpenWindowsAutomatically = true webSettings.loadsImagesAutomatically = true webSettings.javaScriptEnabled = true webSettings.cacheMode = WebSettings.LOAD_DEFAULT webSettings.mixedContentMode = WebSettings.MIXED_CONTENT_ALWAYS_ALLOW webSettings.allowFileAccessFromFileURLs = true webSettings.allowUniversalAccessFromFileURLs = true rpgwebview.setLayerType(View.LAYER_TYPE_HARDWARE, null) // Use file:/// protocol to load the local HTML file from assets val inAppHtmlUrl = "file:///android_asset/www/index.html" rpgwebview.loadUrl(inAppHtmlUrl) rpgwebview.addJavascriptInterface(AndroidInterface(this), "AndroidInterface")}
------------------------------------------------------------------------------------
conclusion
------------------------------------------------------------------------------------
- this should also solve "Error - Script Error" and generic errors such as "Game has encountered a bug. Please report it. Error: Failed to load: >insert thing that failed here< at ____" which is what i started getting after i thought i fixed the url issue initially.
I found the idea for this solution here: https://forums.rpgmakerweb.com/index.php?threads/fix-error-failed-to-load-data-actors-json.124240/
which links to this: https://stackoverflow.com/questions...in-requests-are-only-supported-for-http-excep
i still get an, "uncaught TypeError: cannot read properties of null (reading ____)" when i launch the apk for the first time***I fixed this**** so this isnt a total solution or optimization, but a starter for getting html apks to work again instead of using deprecated html>apk wrappers or wrappers that cost money or wrappers that cost money only on a subscription basis!
also that error is seemingly due to a plugin i made***yup it was the plugin I fixed it lol*** so it may not affect other games.
*troubleshooting: when in doubt, re sync the gradle in the upper right area
*troubleshooting: turn plugins on/off when deploying to test what works and what doesnt
*troubleshooting: if you get an error of something failing to load, go to the www deployment folder and look for that file. if its in there, go to your project and check what might make it not load. for me, i had this issue with a plugin i did not make. idk why but it wouldnt load a map associated with that plugin, so i deleted the map, turned the plugin off, and re-deployed.
*troubleshooting: if youre decently savvy with android studio, go ahead and drop your apk into a virtual emulation to test it and run the logcat to see what pops up. read the outputs and see if you get any errors or info that can help you figure out what isn't working and what is.
*troubleshooting: another good place to start with this is to test your deployed game files before testing the APK version. clicking the index.html and running it in browser should show any errors that will be strictly related to your game as it is and has nothing to do with the wrapping process yet. this is good to weed those out before addressing issues for the apk version. if it doesn't show errors then it's probably good, but mine still does and my apk works so, it's still some trial and error.
*troubleshooting: if you see errors and you don't know what's going on, in android studio hit shift twice in a row to open a searchbar, this will let you search anything in all files by default. if you get errors like "failed to load ___" look up the thing that failed to load and see what's going on.
a lot of this is playing detective if you're not an android developer or know code well. i get the base concepts of code language and structure, so I knew where to look to fix issues, but I don't have "high level" knowledge of any of this. with patience and a detective hat, you should similarly be able to fix simple issues like this by poking around a bit.
other common issues such as the black screen issue etc were covered in the original threads for this guide and in an older guide from maybe ~2017ish (I don't have a link just now for that one). I didn't encounter those so I have no tips for them.
eventually I will likely try this again in the most recent version of Android studio and then I'll post results and updates.
hopefully this gets some other projects working that were stuck.
if i forgot something ill edit it in later.
laptop specs (for comparison)
OS: Windows 11 pro
Processor: 12th Gen Intel i9-12900H
RAM: 32.0 GB
GeForce RTX 3070Ti
4tb ssd
本贴来自国际rpgmaker官方论坛作者:fonewearl处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:https://forums.rpgmakerweb.com/threads/rpg-maker-mv-html-to-android-apk-with-android-studio-koala-latest-only-ver.174282/
页:
[1]