Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/android support #101

Merged
merged 20 commits into from
Mar 13, 2021
Merged

Feature/android support #101

merged 20 commits into from
Mar 13, 2021

Conversation

piiertho
Copy link
Member

@piiertho piiertho commented Mar 10, 2021

This adds android platform support.
This enable to export game. Only thing to do is the same as classic godot build.
Kotlin project Dex jars will be created if user enable android build in gradle project.
This modifies CI to add Android build for debug and release exports. Also build steps names have changed, explaining the expected but not run CI jobs.

@piiertho piiertho marked this pull request as ready for review March 10, 2021 12:27
@@ -32,13 +32,16 @@ jobs:
build-editor-debug:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
name: [ Linux, OSX, Windows ]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the change?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because on exports I had to rename it to not have confusions between x11 and android. So to keep it coherent, I renamed for all cpp jobs.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this should contain Android as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no editor build for android.

@@ -5,13 +5,16 @@ jobs:
build-editor-release:
strategy:
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]
name: [ Linux, OSX, Windows ]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here - I don't think this is necessary.

godot {
isAndroidExportEnabled.set(true)
dxToolPath.set("${System.getenv("HOME")}/Android/Sdk/build-tools/30.0.3/dx")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use standard android env variables?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean ANDROID_HOME?

Copy link
Contributor

@chippmann chippmann Mar 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm according to https://developer.android.com/studio/command-line/variables ANDROID_HOME is deprecated and replaced by ANDROID_SDK_ROOT. Will update the places in the docs and the commented line in build.gradle.kts of tests

@@ -35,7 +40,33 @@ jni::JObject to_java_url(jni::Env& env, const String& bootstrapJar) {
return url;
}

jni::JObject create_android_class_loader(jni::Env& env, const String& full_jar_path,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we just inline this in create_class_loader? create_android_class_loader wont be called elsewhere right?

Copy link
Member Author

@piiertho piiertho Mar 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create_android_class_loader is also called in GDKotlin::init, while initializing bootstrap.

src/jni/env.cpp Outdated
@@ -62,7 +59,7 @@ namespace jni {
if (exception_check()) {
exception_describe();
exception_clear();
throw JniError("An exception has occurred!");
JVM_CRASH_COND_MSG(true, "An exception has occurred!")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A jvm exception shouldn't cause the engine to crash. If we can't use exceptions here - I suggest that we start implementing what C# did. Make the behaviour when an exception happens in jvm configurable. So either crash completely, or just log the message (maybe using ERR_FAIL_COND_MSG?). When in tool mode, we shouldn't crash to stop misbehaving plugins from crashing the engine.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. But as we need to change this in more places in general, I suggest doing this in a separate PR.

Copy link
Member Author

@piiertho piiertho Mar 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not agree when I read code.
I'm not for checking exception every time we make a jvm call (which is the case for now).
I agree in debug we should make this check, tool should not crash. But in release mode I think we should think a bit more. Even if it is only a bool check, it is a bool check for every jvm method call.
Thing is our module is here to enable user to bring game logic. We should take the less cpu time possible, so that user have much for its game logic.
I think we should run flamegraph to see check_exception impact.

Copy link
Member Author

@piiertho piiertho Mar 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now I made it crash only in debug when not in TOOL, otherwise it prints error. But we'll have to think a bit more to exception handling.

) != OK) {
LOG_ERROR("Cannot copy jre folder to export folder, please make sure you created a jre in project "
"root folder using jlink.")
if (!p_path.ends_with(".apk")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will not hold up anymore with 3.2.4!
As 3.2.4 will add bundle support. Not sure if just checking for aar as well is enough but most probably it is

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -35,8 +40,25 @@ jni::JObject to_java_url(jni::Env& env, const String& bootstrapJar) {
return url;
}

jni::JObject create_class_loader(jni::Env& env, const String& bootstrapJar) {
jni::JObject url = to_java_url(env, bootstrapJar);
jni::JObject create_class_loader(jni::Env& env, const String& full_jar_path, const jni::JObject& p_parent_loader) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parent_class_loader is not being used in the non android path. As I've mentioned before URLClassLoader's constructor accepts a class loader as the second parameter :)

String bootstrap_jar{"res://build/libs/godot-bootstrap.jar"};
String main_jar;
String bootstrap_jar;
if (p_path.ends_with(".apk")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here aar is missing as well

@piiertho piiertho merged commit 7bbf2b0 into master Mar 13, 2021
@piiertho piiertho deleted the feature/android-support branch March 13, 2021 10:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants