Let's build for Android!

Started by eri0o, Mon 08/01/2018 00:35:15

Previous topic - Next topic

eri0o

>> The documentation for releasing for Android is here: README.md <<

Please in case of trouble ask here in this thread! It's possible I screwed up somewhere too, so report any problems!

Note: due to Google Play App size limits, it's important your game not be bigger than 1GB. You can put some files in the app bundle and the rest on the install time asset pack if you need it to be just a bit (100MB) bigger.

---

The information below is outdated, it was relevant for old Android port.
Spoiler


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: cmd

cd YOURGAMENAME\Compiled\
mkdir obb
move YOURGAMENAME.ags obb\
%appdata%\Local\Android\Sdk\tools\bin\jobb -d \obb\ -o main.3.com.YOURSTUDIONAME.YOURGAMENAME.obb -pn com.YOURSTUDIONAME.YOURGAMENAME -pv 3

   
In Linux/OSX
Code: cmd

cd YOURGAMENAME/Compiled/
mkdir obb
mv YOURGAMENAME.ags obb/
~/Android/Sdk/tools/bin/jobb -d ./obb/ -o main.3.com.YOURSTUDIONAME.YOURGAMENAME.obb -pn com.YOURSTUDIONAME.YOURGAMENAME -pv 3


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!
[close]

Mehrdad

Great!!!.Nice job, Thanks so much Erio. I'll try it soon ;-D
My official site: http://www.pershaland.com/

Chicky

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

Quote from: Chicky on Tue 09/01/2018 16:24:32can 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

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

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

Quote from: Joseph DiPerla on Wed 10/01/2018 14:32:07
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

CW, I still couldn't understand: is the current master branch supposed to build for Android or it should fail?

Crimson Wizard

Quote from: eri0o on Wed 10/01/2018 17:56:11
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

#9
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.

.M.M.

Nice! Can I have a question that is slightly off-topic? (hopefully just slightly :) )
Quote from: eri0o on Mon 08/01/2018 00:35:15
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

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

Quote from: Crimson Wizard on Tue 09/01/2018 16:54:18
Quote from: Chicky on Tue 09/01/2018 16:24:32can 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

Quote from: eri0o on Mon 08/01/2018 00:35:15Android\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

#14
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

.gitignore
Code: java

# Built application files
*.apk
*.ap_

# Built application middle files
/*/build/

# Files for the ART/Dalvik VM
*.dex

# Java class files
*.class

# Generated files
bin/
gen/
out/

# Gradle files
.gradle/
build/

# Signing files
.signing/

# Crashlytics configuations
com_crashlytics_export_strings.xml

# Local configuration file (sdk path, etc)
local.properties

# Proguard folder generated by Eclipse
proguard/

# Log Files
*.log

# Android Studio Navigation editor temp files
.navigation/

# Android Studio captures folder
captures/

# IntelliJ
*.iml
.idea/workspace.xml
.idea/tasks.xml
.idea/gradle.xml
.idea/assetWizardSettings.xml
.idea/dictionaries
.idea/libraries
.idea/caches

# Keystore files
# Uncomment the following line if you do not want to check your keystore files in.
*.jks

# External native build folder generated in Android Studio 2.2 and later
.externalNativeBuild

# Google Services (e.g. APIs or Firebase)
google-services.json

# Freeline
freeline.py
freeline/
freeline_project_description.json

# fastlane
fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots
fastlane/test_output
fastlane/readme.md

# OS-specific files
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db


[close]

The creature

#15
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 :) )


eri0o

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

#17
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: ags
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!-- TODO: Update these values for your project -->
    <!-- app name -->
    <string name="app_name">Game</string>
    <!-- game EXE or data file name -->
    <string name="game_file_name">Game.ags</string>
    <!-- expansion file version -->
    <integer name="obbFileVersion">1</integer>
    <!-- expansion file size in bytes (long) -->
    <string name="obbFileSize">43613638</string>
    <!-- expansion file key, @null for none -->
    <string name="obbKey">@null</string>
</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: ags
<?xml version="1.0" encoding="UTF-8"?>
<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">
  <component name="FacetManager">
    <facet type="java-gradle" name="Java-Gradle">
      <configuration>
        <option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" />
        <option name="BUILDABLE" value="false" />
      </configuration>
    </facet>
  </component>
  <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="true">
    <exclude-output />
    <content url="file://$MODULE_DIR$">
      <excludeFolder url="file://$MODULE_DIR$/.gradle" />
    </content>
    <orderEntry type="inheritedJdk" />
    <orderEntry type="sourceFolder" forTests="false" />
  </component>
</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 ???

The creature

#18
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: ags
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.

eri0o


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...

SMF spam blocked by CleanTalk