じ☆ve冰风 发表于 3 天前

[1.5.1+] Exporting to Android using Cordova

Due to the process described in MV's help section for exporting to Android no longer being functional (R.I.P Crosswalk), this is a guide that will allow you to export to MV using a new way. I am writing a guide in a way that assumes you do not have a functioning Android development environment setup so we will be going over how to set that up as well. This guide will be written to get MV games to work on Android version 4.4 (KitKat) or higher.

Installing Prerequisites
Links:
Android Studio/Android SDK
Java Development Kit
NodeJS

Installing Java Development Kit (JDK)
Download the latest version of the Java Development Kit (JDK) from the link provided above. If you're running 32bit Windows, download the 32bit version, if you're running 64bit, download the 64bit version. When Installing the JDK take note of where it is being installed too, we will need to know the location to setup something later. It may ask you to install the Java Runtime Environment (JRE) as well, if so do that too.

Now we need to setup a "JAVA_HOME" environment variable. To do this follow the steps below.

1. First press Win+R (Windows Key + R), this should open up the RUN window.
2. In the RUN window type "SystemPropertiesAdvanced" (without quotes) and press enter or click OK. This should open up the "System Properties" window, like the image below.

Spoiler: Figure -1. System Properties
https://i.imgur.com/c417JDu.png
3. Click "Envrionment Variables..." It should open the Environment Variables window like below.
Spoiler: Figure 0. Environment Variables Window
https://i.imgur.com/ABb7f0R.png
4. Under "System variables" click "New.." it should open up a window asking for a "Variable name" and "Variable value".
5. For the variable name put the following (without quotes) "JAVA_HOME".
6. For the variable value put the location/path of your JDK install. Commonly (for 64bit): "C:\Program Files\Java\jdk1.8.0_144" (without quotes).
7. Press OK three times to close all the windows.

Installing Android Studio/Android SDK
Download the latest version of Android Studio, or the standalone Android SDK. This guide will be using the Android Studio to illustrate the process however so I suggest that.

When installing Android Studio, make sure the Android SDK option is checked.

At some point during the installation you will be able to select the location you want to install the Studio IDE and Android SDK to. This page looks like the below by default:
Spoiler: Figure 1. Android Studio Install Config
https://i.imgur.com/YU25EE4.png

You can install it to anywhere you like, but for the sake of the tutorial and for my own reasons I will be installing the Android SDK to the "C:\Android" directory (see below image). I suggest keeping the install location for it easy to reach, and without spaces as sometimes even on Windows spaces can be the cause of issues when doing stuff. Note down or remember the location of the "Android SDK" (In my case, as you will see in the image below, it is C:\Android) we will need it later.

Spoiler: Figure 2. Android Studio Install Config Change
https://i.imgur.com/oLlxTHB.png


Once the Install is complete, start Android Studio. You may see a screen like below.
Spoiler: Figure 3. Android Studio 'Missing SDK'
https://i.imgur.com/lE5XAyu.png
If this is the case, click Next and then make sure everything on the next page is checked like below and then click Next again.

Spoiler: Figure 4. Android Studio SDK Missing SDK Install 2
https://i.imgur.com/Mp5KthP.png

On the next page, click Finish and it will begin to install the missing components. When the missing components are installed, click Finish again. This should open up a window like so:

Spoiler: Figure 5. Android Studio Main Window
https://i.imgur.com/T4LZYTv.png

Click "Configure" at the bottom of this window, and then click SDK Manager. This will bring up a window like so:
Spoiler: Figure 6. Android SDK Manager
https://i.imgur.com/h99Ffue.png
On this window, under the SDK Platforms tab check "Android 4.4 (KitKat)" and then click Apply and then Okay. This will bring up a window asking you to accept the Android SDK/Google License to install this version of the Android API. Click Accept and then Next to install this version of the API. When this is done downloading and extracting the API, click Finish again and then click Apply and Ok again to close the SDK Manager window. You can now close the Android Studio window as well.

Now we need to setup the ANDROID_HOME environment variable in Advanced System Properties. In order to do that follow the steps above that you used to setup the JAVA_HOME environment variable, except for variable name put "ANDROID_HOME" and for variable value put the location of the Android SDK directory that you noted during the install (in my case C:\Android). DO NOT close the "Environment Variables" window like you did previously for JAVA_HOME, instead locate the "Path" system variable by scrolling down the list (if need be). You will need to modify this a bit by following the steps below.

1. Double click the "Path" variable, it should open up a new window to edit the variable. In Windows 10, the window looks like the below image.

Spoiler: Figure 7. Path variable editing
https://i.imgur.com/tEsgwQX.png

If you aren't on Windows 10, it may look like the window from creating a new variable, just the variable value field has a bunch of paths separated by the character ";".

2. If you're on Windows 10, click "New" it will add a new text field at the bottom of the list for you to add a new path too.
3. In the new text field type the path to your Android SDK install and end it with "\tools" (in my case: "C:\Android\tools" without quotes). Please make sure it is the full path to the "tools" directory of your Android SDK install, when installing the Android SDK it may have added an "sdk" sub folder before the "tools" folder if you did not change the directory.
4. Repeat the above process but add "\platform-tools" after (in my case it would be "C:\Android\platform-tools" without quotes).
5. Repeat the above process but just end it with the base directory for the Android SDK (in my case just "C:\Android" without quotes).
6. Press Ok to close all the Environment variable and System Properties windows.

If you aren't on windows 10, just do the above steps but instead of clicking "New", just end the path with a ";" (without quotes) before typing a new path.

To test if you did it right, press Win+R and then type CMD and press enter. It will open the command prompt, type "android" without quotes and press enter. Ifyou did it right you should see something similar to the below image.

Spoiler: Figure 8. Testing Android SDK In command prompt
https://i.imgur.com/SmzFeMJ.png

Close the command prompt, if that was what you saw, you can move on. If it wasn't try modifying the variables again.

Installing NodeJS
Download and install the Windows LTS installer from the download link provided above for NodeJS. When installing NodeJS make sure the "Add To Path" option will be installed, so you can access NodeJS from the command prompt without having to add it to the Path environment variable yourself. Also make sure "npm package manager" will be installed as well.

Once it is installed, you should be able to open the command prompt (Win+R + typing CMD and pressing enter) and if it was installed correctly (meaning it also set the Path variable in the environment variables)you should be able to type "npm" without quotes and press enter and get similar to the following image.
Spoiler: Figure 9. Testing npm
https://i.imgur.com/xm6ICId.png

Building an APK​

Getting Cordova Setup
Congrats! If you made it this far, your Android environment should be setup correctly and now its time to get Cordova.

Step 1. If command prompt isn't open from testing npm, open it again.
Step 2. Type the following and press enter: npm install -g cordova
Step 3. If it installs correctly you should see something similar to this image below:
Spoiler: Figure 10. Cordova install
https://i.imgur.com/ZrhHEkW.png
Step 4. Test the installation of Cordova by typing the following in command prompt and pressing enter: cordova
Step 5. If installed correctly, you will see a Synopsis on how to use the cordova command (the help).

Creating a Cordova Project
With Cordova installed its time to create a project. In RPG Maker MV, deploy your project for Android/iOS as you would normally to get the exported "www" folder. Then follow the below steps to create a Cordova project to use for the exported "www" content.

Step 1. In command prompt type the following and press enter (see below though before pressing enter): cordova create myMVProjectCordovaDirectory com.my.mvproject myMVProject

Where "myMVProjectCordovaDirectory" is the directory you want the Cordova project to be
Where "com.my.mvproject" is the "address" of your android app (usually safe to just do like com.yourComapnyOrName.TheGameName) without spaces.
Where "myMVProject" (the last one) is the name of the cordova project, usually safe to just use your game name with no spaces.

Example: cordova create C:\AwesomeGameCordova com.liquid.awesomegame AwesomeGame

Step 2. If done correctly you should get a simple "Creating a new cordova project." output.
Step 3. CD into the directory of the cordova project using the "cd" command. For the above example: cd C:\AwesomeGameCordova
Step 4. Once in the directory with command prompt type the following and press enter: cordova platform add android
Step 5. If the above is done correctly, you should see something similar to this image:
Spoiler: Figure 11. Cordova add platform
https://i.imgur.com/m95JPRH.png
Step 6. Type the following and press enter: cordova requirements
Step 7. The above command will check to make sure you can build the project for android, if so you should see similar output tot he below image.
Spoiler: Figure 12. Cordova requirements check
https://i.imgur.com/pSwXkT4.png
Step 8. Open up the exported "www" from your game project and copy the contents of the "www" folder.
Step 9. Go to the location of the Cordova project in Windows Explorer and enter the cordova projects "www" folder, deleting everything in it.
Step 10. Paste the contents of your games "www" into the cordova projects "www". Your cordova projects www folder should look like the below image now.
Spoiler: Figure 13. Cordova www project folder merge
https://i.imgur.com/Tw7dIjJ.png
Step 11. In command prompt type the following and press enter: cordova build android --release
Step 12. After awhile if all goes well, a lot of text should fly by that are basically the build steps executing themselves, and you should end up with a built project.
Step 13. Copy the built apk, found in <PathToYourCordovaProject>/platforms/android/build/outputs/apk/android-release-unsigned.apk to your phone and install the apk! Additionally if you have your phone connected and ADB enabled, you can do "cordova run android" to automatically do this and launch the game on your phone.

Troubleshooting​

1. When building the apk with "cordova build android --release" i get the "ERROR: cmd: Command failed with exit code 1" error Why?
Try doing the following commands:
cordova platform rm android
cordova platform add android@~6
cordova build android --release

If the above doesn't fix the problem, you may have messed up in setting up your environment.

F.A.Q​

NOTE: This guide still needs refinement, and I will go through it later today and do so. You should be able to follow it though and if you understand it build for android, if you have any questions feel free to ask.

Happy RM'ing!
- Liquid


本贴来自国际rpgmaker官方论坛作者:Kaliya处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:https://forums.rpgmakerweb.com/threads/1-5-1-exporting-to-android-using-cordova.84949/
页: [1]
查看完整版本: [1.5.1+] Exporting to Android using Cordova