Android

SDKs and Compilation

Android SDK (Software Development Kit)

Android Studio

NDK (Native Development Kit)

  • It is a set of tools that allows using C and C++ code with Android.

CMake

  • It is an external build tool that works with Gradle to create native libraries.

    • This component is not required if you plan to use only ndk-build.

LLDB

  • It is the debugger used by Android Studio to debug native code. By default, LLDB is installed with Android Studio.

Exporting Godot to Android

  • Instructions are in execution order .

Setup

Prerequisites
In Android Studio
  • Inside the SDK Manager :

    • SDK Tools:

      • .

In Godot
  • Android SDK Path:

    • C:/Users/_user_/AppData/Local/Android/Sdk

  • Java SDK Path (Temurin 17 path):

    • C:/Program Files/Eclipse Adoptium/jdk-17.0.12.7-hotspot

Export

Package name
  • *Troubleshooting:

    • If you get an error saying 'Could not install to device', make sure you do not have an application with the same Android package name already installed on the device (but signed with a different key).

      • If you have an application with the same Android package name but a different signing key already installed on the device, you must remove the application in question from the Android device before exporting to Android again.

Keystore
  • "Debug keystores are now automatically generated by the editor since Godot 4.3".

  • Release:

    • Enter the path to the keystore file you just generated.

  • Release User:

    • Replace with the key alias

  • Release Password:

    • Key password.

    • Note that the keystore password and the key password currently have to be the same.

      • From what I understand, this is a current limitation of Android Studio.

Settings
Gradle
  • It is optional.

  • Requirements :

    • You need to click Project -> Install Android Build Template .

    • I believe Gradle relies more heavily on installations done in Android Studio.

  • From what I perceive, all folders and files inside the res://Android/build  folder should never be changed. Things inside there are useful, but just use Godot's export interface and everything is configurable in a much better way.

  • Troubleshooting :

    • (2024-10-18) I had problems enabling Gradle.

      • I tried to download all correct versions of dependencies but it did not help.

      • "When using the gradle Android build system, assets that are placed within a folder whose name begins with an underscore will not be included in the generated APK. This does not apply to assets whose file name begins with an underscore."

        • "For example, _example/image.png  will not be included as an asset, but _image.png  will."

        • Using it in a project that does not have folders starting with _  solved the problem.

Debugging

One-click Deploy
Adb (Android Debug Bridge)
  • *About:

    • Comes bundled with the standard Android Studio installation.

    • adb logcat .

      • Lets you see all things from the connected device.

    • adb logcat -s godot

      • Lets you see only logs related to Godot.

    • You can use adb logcat > log.txt , which will generate a file with all logs.

  • Add the path C:\Users\_user_\AppData\Local\Android\Sdk\platform-tools\  to Environment Variables.

  • Environment Variables -> System variables/Path -> Edit -> New -> paste the path above .

Wireless: Via 'adb tcpip'
  • I can set my phone's IP to be static to make connecting with adb connect  easier.

  • *Requirements:

    • The phone must have 'USB Debugging' enabled.

    • It is necessary to have 'adb' installed together with (probably) all JDK and Android Studio requirements.

    • Both devices must be on the same Wi-Fi network.

    • The used port must be open (5555); it usually is.

  • *Method:

    • Connect the cable.

    • Type adb tcpip 5555 .

      • "Essentially, it turns the connected device into a 'server' ready to receive connections over Wi-Fi".

      • tcpip :

        • "This adb command argument changes the communication interface of ADB from 'USB' (the default) to 'TCP/IP' mode."

      • 5555 :

        • "This is the network port where ADB will listen for connections. The number 5555 is the default port used by ADB for TCP/IP connections. You can choose another port if you prefer, but 5555 is widely used because it is the default."

    • Disconnect the cable.

    • Type adb connect phone_local_ip_address:5555 .

      • The phone's IP address is found in 'About phone -> Status information -> IP address'.

      • The format is usually "192.168.0.x".

    • Done.

    • To disconnect, you can do adb disconnect phone_local_ip_address:5555 .

      • It only ends the current connection, and the device will still continue to listen on port 5555, which still represents a risk.

    • To return adb to USB configuration, you can do adb usb .

      • This is important for security reasons.

      • Running adb usb  without first doing adb disconnect  will not cause any problem, but it is good practice to disconnect before switching to USB mode. The adb usb  command ensures the device is no longer available for wireless ADB connections, minimizing security risks even if the connection were still active.

  • *Advantages:

    • Smooth debugging with adb logcat -s godot .

    • One-click Deploy can be used to export and automatically open the app on the phone via wireless.

  • *Disadvantages:

    • Does not show Godot debugging when running One-click Deploy.

Wireless: Other options
  • WebSockets

    • WebSockets allow bidirectional real-time communication between the client (in this case your Godot app) and a server (can be local or cloud).

    • Flexibility for real-time communication.

    • Works on any network as long as the device and server are reachable.

  • HTTP/REST API

    • Create an HTTP server that can be accessed via RESTful calls. The Godot app can send and receive data via HTTP requests.

    • You can use frameworks like Flask (Python), Express (Node.js) or any other server that supports HTTP.

    • Easy to implement and test.

    • Good for applications that do not require real-time communication.

  • Multiplayer using NAT Punchthrough

    • A technique that allows devices on different networks (with NAT) to communicate directly without a relay server.

    • Enables direct device-to-device communication, reducing latency.

  • Bluetooth

    • For applications that need short-range communication, Bluetooth is a viable option.

    • You can use the Android API to manage Bluetooth connections from Godot, although this may require more work for permissions and device management.

    • Useful for nearby devices not on the same Wi-Fi network.

  • TCP/UDP Sockets

    • You can use sockets to establish communication between the Godot app and a server or between devices.

    • Godot has support for sockets, allowing you to create both TCP/UDP servers and clients.

    • Flexibility to create a variety of communication solutions.

  • Godot Steam Networking (for games)

    • If your project is a game and you plan to release on Steam, you can use Steam's networking system, which supports matchmaking and other features.

    • You can use Steamworks APIs with Godot to manage multiplayer connections and communication.

    • Easy integration with the Steam platform and support for NAT Punchthrough.

Permissions

File System
  • "On mobile platforms, this path is unique to the project and is not accessible by other applications for security reasons."

    • You can READ and WRITE files there, but you cannot view them from the computer or phone. The game can access these files without issues.

      • No permissions are required for this to be done on the user://  path.

    • Supposedly, by rooting the phone it is possible to access these files.

  • user://  path:

    • /data/data/my.app.name/files  or /SD card/Android/my.app.name/files .

  • *Verification:

    • Using adb , it is possible to verify that files are being saved.

      • .

    • If I ask the game itself to print the content of the accessed file, it is also possible to verify that the content is being saved.

  • *Weirdness with the pathing:

    • In the case of the Galaxy A31 it was odd.

      • Using file.get_absolute_path()  I obtained /data/data/com.caioraphael.sistemaesqueletico/files/resultados.json , but this path does not exist in the file system.

      • The file system on that phone was inside Android/data/com.caioraphael.sistemaesqueletico/ , but there was nothing inside that folder.

        • In this case, no folder inside Android/data/  contained any app information.

  • *Alternatives:

    • "Firebase".

      • "Cloud Firestore is a NoSQL database that is part of the Firebase platform".

    • "REST API".

Tools

Accelerometer
  • <excalidraw_not_loaded> .

Android Plugins

Exporting to the Google Play Store

App signing

Keystore and Keys
  • Keystore :

    • The secure place (or service) where keys are stored and managed, protecting them against theft or misuse.

  • Key :

    • The cryptographic key itself, which can be used for operations like encryption and signing.

Types of Keys
  • Key

    • Upload Key

      • The upload key is used only to sign the APK before uploading it to Google Play. After upload, Google replaces that signature with the official signature managed by Google's signing service using the real signing key .

      • Therefore, the upload key is an intermediate key to ensure the security of the upload process and maintain the integrity of the app.

      • If the upload key is compromised or lost, the developer can request a new upload key from Google without losing access to the app or the ability to update it.

    • Signing Key

      • Usually generated by Google.

      • The signing key is the cryptographic key used to sign the final APK (Android application package) that will be installed on users' devices.

      • The digital signature with the signing key ensures that the app code has not been modified since it was signed. It confirms the developer's identity, as each signing key is unique.

      • This key is essential and must be kept secure, since any update to the app will also need to be signed with the same key.

      • If the signing key is lost, you will no longer be able to update the app published on the Play Store.

  • Debug Key

    • The debug key is automatically generated by Android Studio (or the build tools) when you build an app in debug mode.

    • It is stored in a default keystore location, usually:

      • For Windows: C:\Users\<username>\.android\debug.keystore

      • For macOS/Linux: /home/<username>/.android/debug.keystore

    • The debug key has a fixed alias ( androiddebugkey ) and a default password ( android  for both the keystore and the key).

      • This always  happens.

    • Its validity is short (usually 365 days).

    • It is used only during development and testing and cannot be used to distribute apps on the Google Play Store.

    • An APK signed with the debug key cannot be published on the Play Store.

    • "Can I manually generate a debug key?"

      • If you want to manually generate a debug key, you can create a key with the same characteristics as a debug key, such as alias, password and validity, using the keytool  command. However, it is important to remember that even if you generate a key with those characteristics, it will not be considered an "official debug key" used automatically by Android Studio to build debug-mode apps.

      • It is possible to identify whether a key is an official debug key or a manually generated key with the same characteristics. This can be done by analyzing some information of the key, such as alias, location, passwords and issuer.

      • Even if the key is not an official debug key, it will not be accepted by the Play Store due to its set of characteristics similar to an official Debug Key.

Generating a Keystore
  • keytool -v -genkey -keystore mygame.jks -alias mygame -keyalg RSA -validity 10000

  • This generates a Key that can be either an Upload Key  or a Signing Key .

  •   - This is a screenshot from a video, btw.
Signing extensions
  • .

.apk.idsig
  • The .apk.idsig  file contains digital signing information required to validate and verify the APK's integrity on the Android system.

  • It is generated automatically by Godot and is part of the APK export and signing process.

  • You do not need to manipulate it directly. The Android system uses it internally when installing the APK to ensure that the signature is valid.

  • The .apk.idsig  file is not generated when exporting an .aab  (Android App Bundle). The .idsig  is specifically associated with the APK  format, which is the directly installable package on Android devices. The .aab , on the other hand, follows a different signing and packaging process.

  • Renaming the file and removing the .apk  prefix from the .apk.idsig  would likely cause problems** during the APK signature verification on the Android system. This happens because the installation and verification process for APKs in Android depends on a specific file structure and naming conventions that tie the digital signature to its corresponding APK.

Fingerprints
  • The certificate fingerprint  is a short and unique representation of a certificate that is often requested by API providers alongside the package name to register an app to use their service. The MD5, SHA-1 and SHA-256 fingerprints of the upload and app signing certificates can be found on the app signing page of the Play Console. Other fingerprints can also be computed by downloading the original certificate ( .der ) from the same page.

Considerations
  • App upgrade:

    • When the system is installing an update to an app, it compares the certificate(s) in the new version with those in the existing version. The system allows the update if the certificates match. If you sign the new version with a different certificate, you must assign a different package name to the app—in this case, the user installs the new version as a completely new app.

  • Code/data sharing through permissions:

    • Android provides signature-based permissions enforcement, so that an app can expose functionality to another app that is signed with a specified certificate. By signing multiple APKs with the same certificate and using signature-based permissions checks, your apps can share code and data in a secure manner.

    • I have no idea about this.

Google Play Store

Developer Account
  • A one-time fee of 25 USD is charged.

  • (2024-10-18) I paid the 25 USD fee (?? BRL) and submitted my ID and proof of address for verification.

Fees
  • If your app is paid or if you have in-app purchases, Google takes a percentage of each sale.

  • The standard commission is:

    • 15% for the first US$1 million in annual revenue per developer.

    • 30% for annual revenue above US$1 million.

  • This applies to paid apps and to purchases made within free apps (such as subscriptions or virtual items).

.aab vs .apk
  • .

Google Play Services

Firebase

In-app purchases