Skip to content

Commit

Permalink
add android support
Browse files Browse the repository at this point in the history
  • Loading branch information
3ddelano committed Dec 23, 2023
1 parent 8cac770 commit 26be836
Show file tree
Hide file tree
Showing 10 changed files with 187 additions and 27 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
# Godot logs
logs/

sample/android

.env
vc140.pdb
.sconsign.dblite

*.obj
*.os

**/*.tmp

temp/

epic-online-services-godot-addon.zip
165 changes: 151 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,44 @@ Epic Online Services Godot (WIP)

<img alt="Godot3" src="https://img.shields.io/badge/-Godot 4.2-478CBF?style=for-the-badge&logo=godotengine&logoWidth=20&logoColor=white" />&nbsp;&nbsp;&nbsp;<img alt="Epic Online Services 1.16.1" src="https://img.shields.io/badge/-Epic Online Services 1.16.1-313131?style=for-the-badge&logo=epic-games&logoWidth=20&logoColor=white" />

> Tested on: Windows 10 x64 and Linux x64
> Supports Windows x64, Linux x64 and Android
> Disclaimer: This project is NOT affiliated with Epic Games Inc or Godot Engine. It doesn't endorse Epic Online Services. This project and sample Godot scenes are provided solely for educational purposes and may or may not comply with Epic Games' Design Guidelines, if you plan to release a game make sure you read the [Guidelines](https://dev.epicgames.com/docs/services/en-US/EpicAccountServices/DesignGuidelines/index.html) and any other steps needed to release a public game like asking for user consent, option to delete user data, website with privacy policy and license, etc.

#### The [main](https://github.com/3ddelano/epic-online-services-godot/tree/main) branch is for Godot 4.2
#### The [godot3-mono](https://github.com/3ddelano/epic-online-services-godot/tree/godot3-mono) branch is for Godot 3 Mono (C#) (un maintained)

## [View Current Project Status](#current-project-status)

## [Demo Video (Coming Soon)](#)

## [Documentation (Coming Soon)](#)


## Support Development

#### Making this project took a lot of time and effort, reading the Epic Online Services documentation countless times and testing each method in Godot. I would really appreciate if you could support the project in any way.

<a href="https://www.buymeacoffee.com/3ddelano" target="_blank"><img height="41" width="174" src="https://cdn.buymeacoffee.com/buttons/v2/default-red.png" alt="Buy Me A Coffee" width="150" ></a>
<br>
<a href="https://github.com/sponsors/3ddelano" target="_blank">Github Sponsor</a>
<a href="https://github.com/sponsors/3ddelano" target="_blank"><h4>Github Sponsor</h4></a>

#### Want to support in other ways? Contact me on Discord: `@3ddelano`

Join the Discord server for discussing suggestions or bugs: [3ddelano Cafe](https://discord.gg/FZY9TqW)


How does it work
--------------
## [View Current Project Status](#current-project-status)

## [Demo Video (Coming Soon)](#)

## [Documentation (Coming Soon)](#)

## Screenshots

- Windows
<img src="./_media/windows_auth_success.png">

- Android
<img src="./_media/android_auth_success.jpg">


## How does it work

This project uses GDExtension to wrap the Epic Online Services C SDK so that it can be easily used in Godot using GDScript, C#, etc with similar class hierarchy and static type support. It makes use of signals for sending events like user login, logout, achievement unlock, etc.

Expand All @@ -46,9 +54,9 @@ Installation
This is a regular plugin for `Godot 4.2`. To install the plugin follow the steps below:

1. Goto the Releases section and download the [latest release](https://github.com/3ddelano/epic-online-services-godot/releases/latest)
2. Extract the zip file and copy the `addons/epic-online-services-godot` folder into the `addons/` folder in of your project.
3. Goto `Project->Project Settings->Plugins` and enable the `Epic Online Services Godot 4.2` plugin.
4. You can now use the plugin. Head to the [Documentation](#) for more information on how to use the plugin. Use the below simple script.
2. Extract the zip file and copy the `addons/epic-online-services-godot` folder into the `res://addons/` folder of your project. If the `res://addons` does not exist, create it.
3. In the Godot editor, goto `Project->Project Settings->Plugins` and enable the `Epic Online Services Godot 4.2` plugin.
4. You can now use the plugin. Head to the [Documentation](#) for more information on how to use the plugin. Use the below starter script.
```GDScript
# In main script
extends Node
Expand Down Expand Up @@ -156,7 +164,7 @@ To develop this plugin, follow the below steps:
scons platform=windows target=template_release
```

6. The built GDExtension library will be in the `addons/epic-online-services-godot/bin/` folder.
6. The built GDExtension library will be in the `res://addons/epic-online-services-godot/bin/` folder of the sample project.


### How to run the sample project?
Expand Down Expand Up @@ -191,6 +199,135 @@ Follow the instructions in [Running the service for local development](https://d
Bootstrap the exported game executable (eg. `My Amazing Game.exe`)


## Exporting for Android

### Pre-requisites

- EOS Android SDK (Download from [Epic Developer Portal](https://dev.epicgames.com/portal))

1. Setup the Android Build Template in your Godot project by following the tutorial [Gradle builds for Andriod](https://docs.godotengine.org/en/stable/tutorials/export/android_gradle_build.html). This will create an android project in `res://android/build`.

2. Now with reference to the tutorial [Add the EOS SDK to Your Android Studio Project](https://dev.epicgames.com/docs/epic-online-services/platforms/android#4-add-the-eos-sdk-to-your-android-studio-project), perform the following steps.

3. In the `res://android/build/build.gradle` file, add the following lines after the implementations in the `dependencies` section.

Before
```
dependencies {
implementation libraries.kotlinStdLib
implementation libraries.androidxFragment
... other code
```

After
```
dependencies {
implementation libraries.kotlinStdLib
implementation libraries.androidxFragment
// EOS SDK dependencies
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.security:security-crypto:1.0.0'
implementation 'androidx.browser:browser:1.0.0'
implementation files('../../../thirdparty/eos-sdk/SDK/Bin/Android/static-stdc++/aar/eos-sdk.aar')

...other code
```

4. In the `res://android/build/build.gradle` file, add the following lines after the `defaultConfig` in the `android` section.

Before
```
android {

... other code

defaultConfig {
... other code
// Feel free to modify the application id to your own.
applicationId getExportPackageName()
versionCode getExportVersionCode()
versionName getExportVersionName()
minSdkVersion getExportMinSdkVersion()
targetSdkVersion getExportTargetSdkVersion()

missingDimensionStrategy 'products', 'template'
}

... other code
```

After
```
android {

... other code

defaultConfig {
... other code
// Feel free to modify the application id to your own.
applicationId getExportPackageName()
versionCode getExportVersionCode()
versionName getExportVersionName()
minSdkVersion getExportMinSdkVersion()
targetSdkVersion getExportTargetSdkVersion()

missingDimensionStrategy 'products', 'template'

// This is needed by EOS Android SDK
String ClientId = "PUT YOUR EOS CLIENT ID HERE"
resValue("string", "eos_login_protocol_scheme", "eos." + ClientId.toLowerCase())
}

... other code
```

5. In the `res://android/build/config.gradle` file, update the `minSdk` to `23` to match with the requirements of the `EOS Android SDK`.

Before
```
minSdk : 22,
```
After
```
minSdk : 23,
```

6. In the `res://android/build/src/com/godot/game/GodotGame.java` file, update it as follows.
```java
package com.godot.game;

import com.epicgames.mobile.eossdk.EOSSDK; // added
import org.godotengine.godot.GodotActivity;

import android.os.Bundle;

public class GodotApp extends GodotActivity {
static { // added
System.loadLibrary("EOSSDK"); // added
} // added
@Override
public void onCreate(Bundle savedInstanceState) {
EOSSDK.init(getApplicationContext()); // added

setTheme(R.style.GodotAppMainTheme);
super.onCreate(savedInstanceState);
}
}

```

7. Now open your project in the Godot Editor, and goto `Project -> Export` and create a new Android export profile.

8. In the `Gradle Build` section, enable `Use Gradle Build`. In the `Architectures` section enable `arm64-v8a`. In the `Permissions` section ensure that `ACESSS_NETWORK_STATE`, `ACCESS_WIFI_STATE` and `INTERNET` are enabled. These permissions are needed for the EOS SDK to work. Fill in the other details such as package name, etc as needed.

9. You can now export the Android APK by clicking the Export Project button.


## Current Project Status

- Auth Interface
Expand Down
19 changes: 16 additions & 3 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,21 @@ if env["platform"] == "windows":
env.Append(LINKFLAGS=["/ignore:4099"])

env.Append(LIBS=["EOSSDK-Win64-Shipping"])

elif env["platform"] == "linux":
env.Append(LIBS=["EOSSDK-Linux-Shipping.so"])

elif env["platform"] == "macos":
env.Append(LIBS=["EOSSDK-Mac-Shipping.dylib"])

elif env["platform"] == "android":
eos_android_arch = "arm64-v8a"
if env["arch"] == "x86_64":
eos_android_arch = "x86_64"

env.Append(LIBPATH=[eos_sdk_folder + "Bin/Android/static-stdc++/libs/" + eos_android_arch + "/"])
env.Append(LIBS=["EOSSDK"])


if env["platform"] == "macos":
library = env.SharedLibrary(
Expand All @@ -60,6 +70,9 @@ def on_complete(target, source, env):
# Disable scons cache for source files
NoCache(sources)

complete_command = Command('complete', library, on_complete)
Depends(complete_command, library)
Default(complete_command)
if env["platform"] == "windows":
complete_command = Command('complete', library, on_complete)
Depends(complete_command, library)
Default(complete_command)
else:
Default(library)
Binary file added _media/android_auth_success.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added _media/windows_auth_success.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions sample/Main.gd
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ func test_sessions_interface():
# update_sess = await EOS.get_instance().sessions_interface_update_session_callback
# print("--- Sessions: update_session: ", update_sess)


# Search session
#var create_search_opts = EOS.Sessions.CreateSessionSearchOptions.new()
#var create_session_search = EOS.Sessions.SessionsInterface.create_session_search(create_search_opts)
Expand Down Expand Up @@ -626,7 +626,7 @@ func test_sessions_interface():
# EOS.Sessions.SessionsInterface.join_session(join_sess_opts)
# print("--- Sessions: join_session: ", await EOS.get_instance().sessions_interface_join_session_callback)


# Register players
var reg_players_opts = EOS.Sessions.RegisterPlayersOptions.new()
reg_players_opts.session_name = "TestSession001"
Expand Down
4 changes: 4 additions & 0 deletions sample/addons/epic-online-services-godot/eosg.gdextension
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ windows.x86_64.debug = "bin/windows/libeosg.windows.template_debug.dev.x86_64.dl
windows.x86_64.release = "bin/windows/libeosg.windows.template_release.x86_64.dll"
macos.debug = "bin/macos/libeosg.macos.template_debug.framework"
macos.release = "bin/macos/libeosg.macos.template_release.framework"
android.debug.arm64 = "bin/android/libeosg.android.template_debug.arm64.so"
android.release.arm64 = "bin/android/libeosg.android.template_release.arm64.so"
android.debug.x86_64 = "bin/android/libeosg.android.template_debug.x86_64.so"
android.release.x86_64 = "bin/android/libeosg.android.template_release.x86_64.so"

[dependencies]
windows.debug.x86_64 = ["bin/windows/EOSSDK-Win64-Shipping.dll", "bin/windows/x64/xaudio2_9redist.dll"]
Expand Down
16 changes: 8 additions & 8 deletions sample/components/StyledPopupWindow/StyledPopupWindowTheme.tres

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions sample/project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ common/enable_pause_aware_picking=true
[rendering]

renderer/rendering_method="gl_compatibility"
textures/vram_compression/import_etc2_astc=true
environment/defaults/default_clear_color=Color(0.121569, 0.121569, 0.121569, 1)
environment/defaults/default_environment="res://default_env.tres"
1 change: 1 addition & 0 deletions src/platform_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,7 @@ int IEOS::platform_interface_initialize(Ref<RefCounted> p_options) {
initOptions.ReallocateMemoryFunction = nullptr;
initOptions.ReleaseMemoryFunction = nullptr;
initOptions.Reserved = nullptr;
// TODO: Implement EOS_Android_InitializeOptions for Android
initOptions.SystemInitializeOptions = nullptr;
initOptions.OverrideThreadAffinity = nullptr;

Expand Down

0 comments on commit 26be836

Please sign in to comment.