Author Topic: Let's build for Android!  (Read 3072 times)

eri0o

  • Posts: 392
    • eri0o worked on a game that was nominated for an AGS Award!
Let's build for Android!
« on: 08 Jan 2018, 00:35 »
I will try to explain what I did here, questions will arise, hopefully everything can be answered here and this will allow me to generate a guide.

So first two things are important:
 - Android port of the engine currently doesn't report correctly mouse.isButtonDown, so your game CAN'T BE USING THIS, use if(System.OperatingSystem == eOSAndroid) in your code to work for this.
 - I am using the latest prebuilt APK as libs, those were for the previous stable version, so your game must be built with that AGS.

1. You need to install the latest Android Studio, just download and install. https://developer.android.com/studio/index.html .

2. You will also need JDK, NDK and Android SDK.

3. After installing Android Studio, download the repository I made here: https://github.com/ericoporto/mythsuntold_dungeonhands . This is my modded version of Monkey's Android Studio Project.

4. Open the folder in Android Studio.

5. Building should generate my game .apk!

6. Ok, let's make YOUR game .apk. In the folder Android Studio placed the Sdk, there is a magical tool called jobb. I use Ubuntu, and the tool is in the folder ~/Android/Sdk/tools/bin/ in my computer. If you use Windows, then it's probably in %appdata%\Local\Android\Sdk . (if someone can confirm this information, it would be awesome!). This is just so you can understand what will happen next.

7. In your game Compiled folder, there is a YOURGAMENAME.ags file. Open a cmd.exe (windows) or bash terminal (Linux/OSX). Change Directory to the folder YOURGAMENAME.ags is.

In Windows (untested!)
Code: Text
  1. cd YOURGAMENAME\Compiled\
  2. mkdir obb
  3. move YOURGAMENAME.ags obb\
  4. %appdata%\Local\Android\Sdk\tools\bin\jobb -d \obb\ -o main.3.com.YOURSTUDIONAME.YOURGAMENAME.obb -pn com.YOURSTUDIONAME.YOURGAMENAME -pv 3
  5.  
   
In Linux/OSX
Code: Text
  1. cd YOURGAMENAME/Compiled/
  2. mkdir obb
  3. mv YOURGAMENAME.ags obb/
  4. ~/Android/Sdk/tools/bin/jobb -d ./obb/ -o main.3.com.YOURSTUDIONAME.YOURGAMENAME.obb -pn com.YOURSTUDIONAME.YOURGAMENAME -pv 3
  5.  

In the code above, 3 is simply the OBB version number. Every time you change the content of the OBB linked to your APK and release, you have to increase that number - and update in your Android Studio Project accordingly. Also make sure that YOURGAMENAME and YOURSTUDIONAME are correctly updated in your android studio project.

8. In the README there is a line called Setting up the project for your game. I will copy below:

-Update package name:

Open the project in Android Studio, then in the project tree navigate to app/java/com.mythsuntold.osd.scourge.
Right-click on this folder and select "Refactor -> Move...". When prompted, select "Move package 'com.mythsuntold.dungeonhands' to another package" (the default). You may receive a warning that multiple directories will be moved, select Yes. Type the parent name of your package, not the final package name (e.g., com.bigbluecup not com.bigbluecup.game), select "Refactor" and then click "Do Refactor".
Right-click on the new project folder in the project tree (e.g., com.bigbluecup.scourge) and select "Refactor -> Rename". Type the package name for your game (e.g., game), then select "Refactor" and click "Do Refactor".

Finally, delete the com.mythsuntold.dungeonhands folder.

- Update project.properties. This file contains gradle settings related to your project. The application ID, version code, and version name need to be set to match your project settings (application ID is your package name).

- Update project.xml. This file contains resources for your project. The values there are described in that file.

- Update local.static.properties. This file contains local data that should NOT be added to version control (.gitignore will ignore your changes to this file). You need to add your keystore path, alias, and passwords, and optionally the path to your copy of the AGS source (if you are rebuilding the engine native libraries). See the Java docs on keytool or use the Android Studio signing wizard to generate a keystore.

- Update private.xml. This file contains definitions for your RSA public key and an integer-array with bytes for your salt which is used by the ExpansionDownloaderService. These values are necessary if distributing your app via the Google Play Store. The RSA public key is provided in the Google Play Developer Console, and the salt bytes may be any number of values in the range [-128, 127]. You may need to upload an APK without the RSA public key first before the key is provided. That APK should not be public unless the OBB file is embedded.

- Update graphics resources (app/src/main/res). You can use the Android Asset Studio to easily generate graphics for your app, or use your preferred method. Everything in the drawable and various mipmap-* folders should be replaced with your resources.

I made this post with the intent to help Mehrdad, so please try this!

Mehrdad

  • Posts: 422
    • I can help with animation
    • I can help with characters
    • I can help with story design
    • I can help with web design
Re: Let's build for Android!
« Reply #1 on: 08 Jan 2018, 06:47 »
Great!!!.Nice job, Thanks so much Erio. I'll try it soon ;-D

Chicky

  • Posts: 3,358
    • Chicky worked on a game that was nominated for an AGS Award!
Re: Let's build for Android!
« Reply #2 on: 09 Jan 2018, 16:24 »
Awesome! I've been looking for a little more hand-holding on this process after having some trouble running through Monkey's guide. Before I get stuck in, can you confirm if this works with games that were built with the latest editor build (3.4.1 December)?

Exciting stuff!

Crimson Wizard

  • Local Moderator
  • Posts: 8,735
    • Best Innovation Award Winner 2013, for spearheading the AGS 3.3.0 project
    • Lifetime Achievement Award Winner
    • Crimson Wizard worked on a game that was nominated for an AGS Award!
      Crimson Wizard worked on a game that won an AGS Award!
Re: Let's build for Android!
« Reply #3 on: 09 Jan 2018, 16:54 »
can you confirm if this works with games that were built with the latest editor build (3.4.1 December)?
You cannot build 3.4.1 for Android, until I (or someone else) fix OpenGL code compilation for mobile ports. :/ (Which I hope to address very soon).

Chicky

  • Posts: 3,358
    • Chicky worked on a game that was nominated for an AGS Award!
Re: Let's build for Android!
« Reply #4 on: 09 Jan 2018, 17:03 »
Ah, drat. Can't win 'em all. Looking forward to that CW, your efforts with the OpenGL side of things have been very much appreciated.

Joseph DiPerla

  • Posts: 1,235
  • Joseph DiPerla, Adventure Game Creator Wannabe!
    • I can help with backgrounds
    • I can help with characters
    • I can help with play testing
    • I can help with story design
    • I can help with translating
    • I can help with voice acting
    • I can help with web design
Re: Let's build for Android!
« Reply #5 on: 10 Jan 2018, 14:32 »
I know nothing about OpenGL or coding, but it seems you may need to use opengl es to compile for at least android: https://developer.android.com/training/graphics/opengl/index.html

Seems like a rough task. But then again, what do I know?
Joseph DiPerla--- http://www.adventurestockpile.com
Play my Star Wars MMORPG: http://sw-bfs.com
See my Fiverr page for translation and other services: https://www.fiverr.com/josephdiperla
Google Plus Adventure Community: https://plus.google.com/communities/116504865864458899575

Crimson Wizard

  • Local Moderator
  • Posts: 8,735
    • Best Innovation Award Winner 2013, for spearheading the AGS 3.3.0 project
    • Lifetime Achievement Award Winner
    • Crimson Wizard worked on a game that was nominated for an AGS Award!
      Crimson Wizard worked on a game that won an AGS Award!
Re: Let's build for Android!
« Reply #6 on: 10 Jan 2018, 15:16 »
I know nothing about OpenGL or coding, but it seems you may need to use opengl es to compile for at least android: https://developer.android.com/training/graphics/opengl/index.html

Seems like a rough task. But then again, what do I know?

We already have OpenGL coded for Android port (otherwise it would not work at all). But I added some changes for 3.4.1 to make Tinting work (because JJS forgot to add support for that), using shaders, and now I need to find out how to make shaders work with GL ES.
Assuming that may simply be a matter of finding out correct headers and function names, so may take only couple of hours, but I need to study this first.

I keep saying "I need", although all this time I had a secret wish someone else do that, considering there were people already building Android port on their own. ;)

eri0o

  • Posts: 392
    • eri0o worked on a game that was nominated for an AGS Award!
Re: Let's build for Android!
« Reply #7 on: 10 Jan 2018, 17:56 »
CW, I still couldn't understand: is the current master branch supposed to build for Android or it should fail?

Crimson Wizard

  • Local Moderator
  • Posts: 8,735
    • Best Innovation Award Winner 2013, for spearheading the AGS 3.3.0 project
    • Lifetime Achievement Award Winner
    • Crimson Wizard worked on a game that was nominated for an AGS Award!
      Crimson Wizard worked on a game that won an AGS Award!
Re: Let's build for Android!
« Reply #8 on: 10 Jan 2018, 18:02 »
CW, I still couldn't understand: is the current master branch supposed to build for Android or it should fail?
It will fail, here is the issue ticket: https://github.com/adventuregamestudio/ags/issues/420

Basically, what we need to do is to find how shader functions (list is given in the ticket) are called in GLES, include proper headers for mobile ports and make proper "#define"s for these functions.
Well, and test that everything is working, ofc.

eri0o

  • Posts: 392
    • eri0o worked on a game that was nominated for an AGS Award!
Re: Let's build for Android!
« Reply #9 on: 10 Jan 2018, 18:46 »
In Android docs I found:

https://developer.android.com/reference/android/opengl/GLES20.html

Doing ctrl+f on each thing from the issue, things look available. I don't know where are iOS docs.

Edit: android moved docs from 'development' to 'developer' and I had a mini heart attack here.
« Last Edit: 14 Feb 2018, 02:39 by eri0o »

.M.M.

  • Posts: 234
Re: Let's build for Android!
« Reply #10 on: 08 Mar 2018, 12:15 »
Nice! Can I have a question that is slightly off-topic? (hopefully just slightly :) )
Android port of the engine currently doesn't report correctly mouse.isButtonDown, so your game CAN'T BE USING THIS, use if(System.OperatingSystem == eOSAndroid) in your code to work for this.
What exactly does it mean, that it's not reported correctly? I'm currently using the function in both my Android projects without a problem, have I missed something?

eri0o

  • Posts: 392
    • eri0o worked on a game that was nominated for an AGS Award!
Re: Let's build for Android!
« Reply #11 on: 06 May 2018, 23:52 »
I don't know how I didn't see this question.

My experience with the Android port was that isButtonDown only reports correctly once the finger is placed in the touchscreen, but then, even if the finger stays in the screen, it doesn't return true anymore - like it would when you do a mouse left click and hold. I saw that iOS Wadjet port does has this behavior - which gets rid of the mouse left click being thrown on finger hold.

This is because the Android port is designed for being able to play existing ags games, and not for making Android games.

Crimson Wizard

  • Local Moderator
  • Posts: 8,735
    • Best Innovation Award Winner 2013, for spearheading the AGS 3.3.0 project
    • Lifetime Achievement Award Winner
    • Crimson Wizard worked on a game that was nominated for an AGS Award!
      Crimson Wizard worked on a game that won an AGS Award!
Re: Let's build for Android!
« Reply #12 on: 10 May 2018, 10:35 »
can you confirm if this works with games that were built with the latest editor build (3.4.1 December)?
You cannot build 3.4.1 for Android, until I (or someone else) fix OpenGL code compilation for mobile ports. :/ (Which I hope to address very soon).


UPD: You now can.

monkey0506

  • Posts: 7,031
  • SEND PIZZA.
    • Best Innovation Award Winner 2017, for his work to help AGS games reach the widest possible audience - through popular distribution platforms (Steam, Galaxy) as well as other operating systems (Android, Linux)
Re: Let's build for Android!
« Reply #13 on: 06 Jun 2018, 08:07 »
Android\Sdk\tools\bin\jobb ...

The jobb tool distributed with the Android SDK (including latest versions) is not suitable for games over 511 MB. This won't affect most games, but it is something that should be pointed out explicitly.

Additionally, you've committed a lot of binary files into your git repo, and don't even have a .gitignore file. I appreciate the fact that you made an effort to maintain this project (or the steps described therein), but you have missed important steps that obfuscate what you did actually fix from the original git repo. FWIW, I have time and an interest in getting the original repo working, but I can't promise anything definitive as I also have other projects to revisit.

eri0o

  • Posts: 392
    • eri0o worked on a game that was nominated for an AGS Award!
Re: Let's build for Android!
« Reply #14 on: 14 Jun 2018, 12:44 »
Thanks Monkey0506 . I was just trying to make something fast that could work on Windows, but I wasn't very eager to install Android Studio on it... I just used it as an alternative to your plugin for myself, on Android Studio on Linux. :/

here is a gitignore for Android Studio projects if someone ever needs one
Spoiler: ShowHide

.gitignore
Code: Java
  1. # Built application files
  2. *.apk
  3. *.ap_
  4.  
  5. # Built application middle files
  6. /*/build/
  7.  
  8. # Files for the ART/Dalvik VM
  9. *.dex
  10.  
  11. # Java class files
  12. *.class
  13.  
  14. # Generated files
  15. bin/
  16. gen/
  17. out/
  18.  
  19. # Gradle files
  20. .gradle/
  21. build/
  22.  
  23. # Signing files
  24. .signing/
  25.  
  26. # Crashlytics configuations
  27. com_crashlytics_export_strings.xml
  28.  
  29. # Local configuration file (sdk path, etc)
  30. local.properties
  31.  
  32. # Proguard folder generated by Eclipse
  33. proguard/
  34.  
  35. # Log Files
  36. *.log
  37.  
  38. # Android Studio Navigation editor temp files
  39. .navigation/
  40.  
  41. # Android Studio captures folder
  42. captures/
  43.  
  44. # IntelliJ
  45. *.iml
  46. .idea/workspace.xml
  47. .idea/tasks.xml
  48. .idea/gradle.xml
  49. .idea/assetWizardSettings.xml
  50. .idea/dictionaries
  51. .idea/libraries
  52. .idea/caches
  53.  
  54. # Keystore files
  55. # Uncomment the following line if you do not want to check your keystore files in.
  56. *.jks
  57.  
  58. # External native build folder generated in Android Studio 2.2 and later
  59. .externalNativeBuild
  60.  
  61. # Google Services (e.g. APIs or Firebase)
  62. google-services.json
  63.  
  64. # Freeline
  65. freeline.py
  66. freeline/
  67. freeline_project_description.json
  68.  
  69. # fastlane
  70. fastlane/report.xml
  71. fastlane/Preview.html
  72. fastlane/screenshots
  73. fastlane/test_output
  74. fastlane/readme.md
  75.  
  76. # OS-specific files
  77. .DS_Store
  78. .DS_Store?
  79. ._*
  80. .Spotlight-V100
  81. .Trashes
  82. ehthumbs.db
  83. Thumbs.db
  84.  

« Last Edit: 07 Aug 2018, 01:34 by eri0o »

The creature

  • Posts: 38
Re: Let's build for Android!
« Reply #15 on: 22 Oct 2018, 12:37 »
I've been following these instructions to the best that I can, looking at getting my little project working on the Phone. I dont have any compile errors or warnings and the phone is connected via USB developer. It all builds fine and generates the APK file fine. But I have one problem. The game flashes black and then returns to the phone home screen (so the APK is duff). The app also has it's original name Dungeon Ha....

I was curious of a few things - Firstly how to change the app name - I'm guessing I've done something grossly wrong. Secondly. I couldn't use the Jobb tool as there is an error when I run it so I used Winrar? I searched that by zipping up files and in a stored compression and giving it the file extension of .obb works (though I'm not sure now). My Obb file is named: main.1.com.Game.GameGame.obb (keeping the name convention the same as the original obb file).

The files I zipped were: \Compiled\game.ags & audio.vox
Is this all that is required?

********
I managed to atleast get the app name right now changing the  android:label="" in the AndroidManifest.xml but the app sadly still doesnt load. I forgot to mention that the game is compiled using AGS 3.4.1 if that could be an issue.

Any help would be great as I feel like I'm pretty close getting it all working (Thanks to eri0o of course :) )

« Last Edit: 22 Oct 2018, 14:39 by The creature »

eri0o

  • Posts: 392
    • eri0o worked on a game that was nominated for an AGS Award!
Re: Let's build for Android!
« Reply #16 on: 22 Oct 2018, 23:35 »
Could you try using this tool instead to build th obb?

https://bitbucket.org/monkey0506/jobbifier/downloads/

In Android Studio, you can filter to read the messages only from the specified app, if you do that, you will be able to read the errors in the Android Studio console (it uses ADB). You just connect an USB cable between your PC and your Android phone and enables developer mode on the phone.

You can get latest AGS android build here:

http://www.adventuregamestudio.co.uk/forums/index.php?topic=56452.0

The creature

  • Posts: 38
Re: Let's build for Android!
« Reply #17 on: 23 Oct 2018, 10:56 »
That's great, I do have my phone linked up in developer mode via USB and it was installing the APK fine, so that's all working at least.

I also updated the AGS library with the 3.4.1 build. I was using the Steam plugin, but I made an Android version of the project and removed all the STEAM strings from the project in case that was causing issues.

The app still fails to open though, and I get an error: Session 'app': Error Launching activity. It launches now, just the screen is a solid black although it asks at the start for various permissions to access photos and things - so it's trying to work.

My obb file is: main.1.com.CompanyName.Game

I updated the project.xml
Code: Adventure Game Studio
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <resources>
  3.     <!-- TODO: Update these values for your project -->
  4.     <!-- app name -->
  5.     <string name="app_name">Game</string>
  6.     <!-- game EXE or data file name -->
  7.     <string name="game_file_name">Game.ags</string>
  8.     <!-- expansion file version -->
  9.     <integer name="obbFileVersion">1</integer>
  10.     <!-- expansion file size in bytes (long) -->
  11.     <string name="obbFileSize">43613638</string>
  12.     <!-- expansion file key, @null for none -->
  13.     <string name="obbKey">@null</string>
  14. </resources>

I never still haven't used the Jobb/jobbifier tool as I'm not sure how to use it, looking into that I know you use the command console but other than that I'm at a loss. Using ES File Explorer I can see the my obb file is on my phone in the apk.

I also noticed in the master dir - mythsuntold_dungeonhands-master/ I have a file gamecompany.game.iml with this code in it it:
Code: Adventure Game Studio
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <module external.linked.project.id="mythsuntold_dungeonhands" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" type="JAVA_MODULE" version="4">
  3.   <component name="FacetManager">
  4.     <facet type="java-gradle" name="Java-Gradle">
  5.       <configuration>
  6.         <option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" />
  7.         <option name="BUILDABLE" value="false" />
  8.       </configuration>
  9.     </facet>
  10.   </component>
  11.   <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="true">
  12.     <exclude-output />
  13.     <content url="file://$MODULE_DIR$">
  14.       <excludeFolder url="file://$MODULE_DIR$/.gradle" />
  15.     </content>
  16.     <orderEntry type="inheritedJdk" />
  17.     <orderEntry type="sourceFolder" forTests="false" />
  18.   </component>
  19. </module>

does this seem correct too? The 'external.linked.project.id="mythsuntold_dungeonhands" external.' seems odd, is that fine?

I feel pretty close, just at a quandary now ???
« Last Edit: 23 Oct 2018, 11:15 by The creature »

The creature

  • Posts: 38
Re: Let's build for Android!
« Reply #18 on: 23 Oct 2018, 16:51 »
I had noticed I didn't have the NDK installed from the Android SDK Manager. So I switched than on thinking this could be the issue but it throws this warning when I try to build?

Code: Adventure Game Studio
  1. No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android
When I uninstall the NDK all the errors vanish as you can imagine. But, as you have stated in the original post, it is a requirement.

I'm very sorry for being a such pest and cluttering this thread up. It's frustrating because I feel close to getting the app working and with the awesome work that's been done here, it's been a huge help. If I get this working I will also show my process in getting it all working. I know very little about Java and android development, it's well out of my comfort zone.

Any ideas? :( one step forward, two steps back lol

FIXED

Seems that if you install the NDK via the SDK Manager it misses a number of Toolchains folders. I manually downloaded an older zip (16b) in my case and copied the missing files into my: \AppData\Local\Android\Sdk\ndk-bundle\toolchains and that fixed the errors in the project.

Sadly the app still loads to a black screen. I tried using AGS files instead of an obb and the issue still persists so I'm now wondering if the problem lies with the project now. Maybe in the Project Structure settings? I dont know. I'm at a bit of a loss.
« Last Edit: 24 Oct 2018, 10:25 by The creature »

eri0o

  • Posts: 392
    • eri0o worked on a game that was nominated for an AGS Award!
Re: Let's build for Android!
« Reply #19 on: 24 Oct 2018, 12:50 »

With your device connected in Android Studio, selected from the list, click play to run the debugger and have your game process selected in debugable process. This will give you better messages in the logcat.



The jobbifier tool has this GUI:



On input folder write your game build path (XXXX/XXXX/GAMENAME/Compiled/Windows/) and the output under /XXX/YOUR_ANDROID_STUDIO_PROJECT/app/src/main/assets/ . Don't use password, leave as main, don't forget to write your identifier and please give the same version written in your game project in android studio.

Once you can get it running like this, a reminder that you can ship the obb and apk separately in the Google Play Console, because you can't have bigger than 100MB apks.

I don't think you have to modify that xml by hand...

I am  traveling away from home, so can't give more info now...