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

Can't get Android modules with Engine.get_singleton() anymore #22859

Closed
samuelpedrajas opened this issue Oct 8, 2018 · 16 comments
Closed

Can't get Android modules with Engine.get_singleton() anymore #22859

samuelpedrajas opened this issue Oct 8, 2018 · 16 comments

Comments

@samuelpedrajas
Copy link
Contributor

samuelpedrajas commented Oct 8, 2018

Godot version:

3.1 Alpha commit 0063ba9

OS/device including version:

Android 8 and 7 / Xiaomi MI5 and Galaxy Tab A8 (2016)

Issue description:

I used to call Engine.has_singleton("SomeModule") and Engine.get_singleton("SomeModule") to use Android modules in my game, but a few days ago I pulled the master branch and these two functions stopped behaving as before. I always get False when calling Engine.has_singleton("SomeModule") and [Object:null] when calling Engine.get_singleton("SomeModule").

I don't know too much about Godot's internals or Android, but after debugging a bit I found that this two lines were removed from platform/android/java_glue.cpp at the end of the _initialize_java_modules function:

jobject obj = env->CallStaticObjectMethod(singletonClass, initialize, _godot_instance);
jobject gob = env->NewGlobalRef(obj);

For some reason if I get back the first line (env->CallStaticObjectMethod(singletonClass, initialize, _godot_instance);) it gets fixed, but I'm not sure if this is the right solution.

Steps to reproduce:
I used the example of this module https://github.com/Shin-NiL/Godot-Share/ as a minimal reproduction project. After moving the module to the modules folder and compiling the templates, I rewrote the code in _on_share_btn_pressed like this:

func _on_share_btn_pressed():
	print(Engine.has_singleton("GodotShare"))
	print(Engine.get_singleton("GodotShare"))

And I get:

False
[Object:null]

I think this would happen with any Android module.

@TheTrope
Copy link

TheTrope commented Oct 11, 2018

Definitly the same issue as mine #22932
env->CallStaticObjectMethod(..) has been removed in d95212 by akien-mga
d952126#diff-a93edb66949b871e603227d460cf03b1L889
I don't know why this line has been removed
@akien-mga , some hightlight ? Thanks !
Following it !

@wombatwingdings
Copy link

It's not just me then! Thanks all.

@s0ra
Copy link

s0ra commented Oct 15, 2018

I don't know if this error related to this bug.

AndroidRuntime: java.lang.ClassNotFoundException: Didn't find class "org/godotengine/godot/..." on path: DexPathList[[zip file "/system/framework/org.apache.http.legacy.boot.jar", zip file "/data/app/org.godotengine...

version: godot-b05efd98ffe3036b05e501b26ed2ee811161ee11

@dumitru-stama
Copy link
Contributor

dumitru-stama commented Oct 15, 2018

Same for me, added PR #23021 to fix this
Pretty sure the lines were removed by mistake to fix the warning with "gob" variable not being used after initialization.

@akien-mga
Copy link
Member

Fixed by #23021.

@DDru
Copy link

DDru commented Jan 28, 2019

I think it again not working.
In custom build (Latest commit f32c826) i tried to use it https://github.com/FrogSquare/GodotAds (unpacked archive into modules folder and rebuild from sorcecode engine and android exports in empty project.
But engine does not find singletons. Line var Unityads = Globals.get_singleton("GDUnityAds") equals to [Object:null]

@akien-mga
Copy link
Member

Please report this bug to https://github.com/FrogSquare/GodotAds, the issue is in their documentation. You should use ProjectSettings, not Globals, and that's since 3.0.

@DDru
Copy link

DDru commented Jan 30, 2019

@akien-mga what did you mean by ProjectSettings? I tried to use Engine.get_singleton and added classes to the project file, but this did not change anything.

@wombatwingdings
Copy link

I don't use that module myself, but from my experience, you would need to add the following to your project.godot file (or add it in "Project Settings -> Android -> Modules" in the UI). The readme for your module doesn't mention this.

[android]
modules="org/godotengine/godot/GodotAds"

@DDru
Copy link

DDru commented Jan 30, 2019

@wombatwingdings it does not work.

@akien-mga why Godot has no methods for working with advertising? All engines can do it.

@Siler88
Copy link

Siler88 commented Apr 5, 2019

hey guys. i still have the bug. issnt it fixed jet?

@ANeller
Copy link

ANeller commented Apr 14, 2019

Yeah im having the exact same problems and have also tried all the various tips above

@DDru
Copy link

DDru commented Apr 14, 2019

@Siler88 @ANeller
I found out that it works (returns not null) only on Android. Just run the game on your phone and look at the debug result.

@ANeller
Copy link

ANeller commented Apr 14, 2019

@Siler88 @ANeller
I found out that it works (returns not null) only on Android. Just run the game on your phone and look at the debug result.

@DDru
I tried to run on my phone but doesnt load as soon as I add this to my engine config file -

[android]
modules="org/godotengine/godot/GodotAds,org/godotengine/godot/AdMob,org/godotengine/godot/GDAdColony,org/godotengine/godot/GDChartboost,org/godotengine/godot/GDVungle,org/godotengine/godot/GDMopub,org/godotengine/godot/GDUnityAds"

is this correct? - https://screenpresso.com/=010vc

@DDru
Copy link

DDru commented Apr 14, 2019

@ANeller
Look at the manual here: https://github.com/FrogSquare/GodotAds

  • First you need to add files to the source code and specify in config.py which Ad you need
  • Then rebuild engine source code
  • In the modules you specify only selected Ad

@ai-boson
Copy link

On the android device I get this bug report. I am using Godot 3.2.2.
bugreportonphone

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests