Problem with Java extension not working with new GMS 1.4 version

RizbIT

Member
Having updated GMS 1.4 to version 1.4.1772

I have just recompiled an app that uses the GMSWebview extension.

I noticed that the webview will ont be shown and in the debug console the following messages are shown:
I/yoyo (15971): Exception thrown trying to call method WebView_Init on WebViewEmbed
I/yoyo (15971): Exception thrown trying to call method WebView_SetHome on WebViewEmbed
I/yoyo (15971): android.software.leanback = 0
I/yoyo (15971): MANUFACTURER = Sony
I/yoyo (15971): Exception thrown trying to call method WebView_SetScrollBars on WebViewEmbed
I/yoyo (15971): Exception thrown trying to call method WebView_SetScrolling on WebViewEmbed
I/yoyo (15971): Exception thrown trying to call method WebView_Create on WebViewEmbed
id like to ask why and how to fix this. I have made no changes to the java extension code.

In GMS Android settings all is upto date. Used SDK Manager to update all components to latest aswell.

Need help
 
W

Wraithious

Guest
Sounds like it's a change in the gradle build version, check that the build tools version number of your project is the same as the one in the extension, it should be in the gradle dependencies box in the main extension window's android tab (double click the extension on the file tree) and compare it to the GMS 1x build tools version you're using. (which is located in game settings at the bottom of the file tree, android tab)
 

RizbIT

Member
here is some more data from the console when compiling debug version:
cmd /c "subst Z: "C:\Users\Master\Documents\GameMaker\Cache\GMSWebView\Android\Default" && Z: && cd \uk.rizbit.gmswebview && "C:\Users\Master\AppData\Roaming\GameMaker-Studio\Android\runner\gradle\gradlew" assembleRelease "

Starting a Gradle Daemon, 1 incompatible and 1 stopped Daemons could not be reused, use --status for details
Incremental java compilation is an incubating feature.
The TaskInputs.source(Object) method has been deprecated and is scheduled to be removed in Gradle 4.0. Please use TaskInputs.file(Object).skipWhenEmpty() instead.
:uk.rizbit.gmswebview:preBuild UP-TO-DATE
:uk.rizbit.gmswebview:preReleaseBuild UP-TO-DATE
:uk.rizbit.gmswebview:checkReleaseManifest
:uk.rizbit.gmswebview:preDebugAndroidTestBuild UP-TO-DATE
:uk.rizbit.gmswebview:preDebugBuild UP-TO-DATE
:uk.rizbit.gmswebview:prepareComAndroidSupportMultidex101Library
:uk.rizbit.gmswebview:prepareComAndroidSupportSupportV42321Library
:uk.rizbit.gmswebview:prepareReleaseDependencies
:uk.rizbit.gmswebview:compileReleaseAidl
:uk.rizbit.gmswebview:compileReleaseRenderscript
:uk.rizbit.gmswebview:generateReleaseBuildConfig
:uk.rizbit.gmswebview:generateReleaseResValues
:uk.rizbit.gmswebview:generateReleaseResources
:uk.rizbit.gmswebview:mergeReleaseResources
:uk.rizbit.gmswebview:processReleaseManifest
Z:\uk.rizbit.gmswebview\src\main\AndroidManifest.xml:15:1-76 Warning:
Element uses-permission#android.permission.WRITE_EXTERNAL_STORAGE at AndroidManifest.xml:15:1-76 duplicated with element declared at AndroidManifest.xml:11:1-77
Z:\uk.rizbit.gmswebview\src\main\AndroidManifest.xml:30:3-81:17 Warning:
application@android:label was tagged at AndroidManifest.xml:30 to replace other declarations but no other declaration present
 
W

Wraithious

Guest
hmm, just a question in case you may have overlooked it, in the global game settings > android tab > permissions, did you check the internet check box?
Another thing you can try is put a test method in your java file:
Code:
public String testMe()
{
String myString = "Access to test method succeeded";
Log.i("yoyo", myString);
return myString;
}
then make a function called testMe and then in a mouse click or something call it like
Code:
var getMsg = testMe();
and then look at the runner output and see if it accessed the extension, if it didn't I still think it's a build tools miss match, if it does work something else is going on there.
 

RizbIT

Member
thanks i tried that and got same error:
I/yoyo (17023): Setting vis flags to 5894
I/yoyo (17023): Exception thrown trying to call method testMe on WebViewEmbed
I/yoyo (17023): ShowMessageAsync("undefined",1)
I/yoyo (17023): Setting vis flags to 5894
I/yoyo (17023): onWindowFocusChanged(false|true)
 

RizbIT

Member
i dont understand about the build tools mismatch, the only place i know of that you set build tools version is under Global Game Settings->Android
 
W

Wraithious

Guest
Hmmm it's strange that that basic test method doesn't work, in the global game settings android tab what are your target sdk and min sdk and compile sdk set to? were they different in the earlier version of gms? if so try setting them to the old settings, or set them to target - 23, min - 13, compile - 23, other than that something is preventing any access to the extension, in the extension in the file tree is the place holder there? like if you click the + on your extension there should be another file with the same name, then if you click that + the functions show.
And altho alot of extensions have practically nothing in the android tab (when you double click the extension) you may need to reference your java file in the application level box, same thing if you use any type of themes too plus if you use a theme you need to compile it in the gradle dependencies box
Clipboard02.png
 

RizbIT

Member
hey wraith tbh im new to java although i did write most of my extension myself, using reference.

im not show about themes and whether i need to add the text in the gradle dependencies box. The thing is when the extension WAS working i had nothing in the gradle box and it still worked

target sdk min and max is 23, 9 and 23

only thing i have updated is GMS

my build tolld in sdk manager are upto date and i tried recompile using new build tool version in settings still didnt work
 

RizbIT

Member
Sounds like it's a change in the gradle build version, check that the build tools version number of your project is the same as the one in the extension, it should be in the gradle dependencies box in the main extension window's android tab (double click the extension on the file tree) and compare it to the GMS 1x build tools version you're using. (which is located in game settings at the bottom of the file tree, android tab)
I created a new project and a new java file and created a new extension from scratch in that project

heres the java code for the extension:



Code:
package ${YYAndroidPackageName};
import ${YYAndroidPackageName}.RunnerActivity;
import ${YYAndroidPackageName}.R;

import com.yoyogames.runner.RunnerJNILib;
import android.app.Application;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;

public class WebViewEmbed// extends Activity
{
public String testMe()
 {
 return "Access to test method succeeded";
 }
}
Again i get the same error
 

RizbIT

Member
ok i think this is kinda sorted.

I had to reorganise the structure of the extension

before I had used a reference to a java file but now i added placeholder for a generic file and the java file went in
extensions\GMSWebView\AndroidSource\Java

when i export the extension into a new project it works fine npw

BUT when i try to use the same extension in the original GMSWebview project it doesnt work.
 

RizbIT

Member
ok it now works for some reason i had to remove this aswell from the android settings


Code:
<activity android:name=".WebViewEmbed"
                  android:theme="@android:style/Theme.Translucent"
 />
 
W

Wraithious

Guest
ok i think this is kinda sorted.

I had to reorganise the structure of the extension

before I had used a reference to a java file but now i added placeholder for a generic file and the java file went in
extensions\GMSWebView\AndroidSource\Java

when i export the extension into a new project it works fine npw

BUT when i try to use the same extension in the original GMSWebview project it doesnt work.
ahh so it was a placeholder file issue! good that you got it fixed, strange tho that it won't work in that 1 project, did you press the brush icon to clean the project? I've found that any mods done to the java file require you to clean the project every time before testing, if that's not the case try redoing the project and importing your extension, if it doesn't work it's something with the project code that isn't compatible any more for whatever reason.
 
W

Wraithious

Guest
ok it now works for some reason i had to remove this aswell from the android settings


Code:
<activity android:name=".WebViewEmbed"
                  android:theme="@android:style/Theme.Translucent"
 />
that would seem to coincide with what i said about the gradle build box code, if you want to use that theme you must put in the correct appCompat compile code, to match gamemaker's build tools version.
 
L

Lintydude

Guest
Hey would either of you be able to help me? I've spent almost 24 hours trying to get rid of these "Exception thrown" messages (which appear when I call any function in my code, even simple 1-line test functions). I have tried just about every solution I could find on the web, but haven't found one that works.
I'll post some data if it helps:
Global Game Settings
Target SDK: 23
Min SDK: 9
Compile SDK: 23
Build Tools: 23.0.1
Support Lib: 23.1.1

Preferences
NDK: r12b
JDK: 1.8 "8u102"

Extension
Manifest level and all other boxes are empty.

Version
1.4.1772
 
W

Wraithious

Guest
Hey would either of you be able to help me? I've spent almost 24 hours trying to get rid of these "Exception thrown" messages (which appear when I call any function in my code, even simple 1-line test functions). I have tried just about every solution I could find on the web, but haven't found one that works.
I'll post some data if it helps:
Global Game Settings
Target SDK: 23
Min SDK: 9
Compile SDK: 23
Build Tools: 23.0.1
Support Lib: 23.1.1

Preferences
NDK: r12b
JDK: 1.8 "8u102"

Extension
Manifest level and all other boxes are empty.

Version
1.4.1772
What exactly does the error message say? Especially the end part, does it say : null or does it say the name of your java class file?
If it says : null then theres a problem inside your java class code (missing calls to link the jni runner with a java call most likely) or theres no placeholder file to link your extension, but if there is a class name at the end of the error then make sure that name matches the class name inside your java file and that the name of the java file matches the java class name.
 
L

Lintydude

Guest
What exactly does the error message say? Especially the end part, does it say : null or does it say the name of your java class file?
If it says : null then theres a problem inside your java class code (missing calls to link the jni runner with a java call most likely) or theres no placeholder file to link your extension, but if there is a class name at the end of the error then make sure that name matches the class name inside your java file and that the name of the java file matches the java class name.
The error I'm getting is "Exception thrown trying to call method AddTwoNumbers on GenericTest" but it shows up for every function I try to call :( and yes, my class does match the name of the java file
 
W

Wraithious

Guest
hmm, if you're following that tutorial make sure in your function edit window that the name of each of your functions are the same as the method names in the java class, this:
example8.png

should = this in the java class:
Code:
//package name and imports
public class GenericTest {

public double AddTwoNumbers(double inputNumber) {
//....code to add random number to input number
}

}
And in gms you'd call it with something like:
Code:
global.randomPick = AddTwoNumbers(round(random(100)));
 
L

Lintydude

Guest
yeah man, all of my functions match the method names

update #1:
I exported the two faulty extensions into a new project and ran the functions. It seems that the GenericTest functions now work as intended, however I am still getting the same errors when I attempt to run the extension I made... here is some code of it so you can check it.
Code:
public class StepCounter extends Activity implements SensorEventListener {
    private SensorManager sensorManager;
    private Sensor detectorSensor;
    private boolean stepWasTaken = false;
 
    private static final int EVENT_OTHER_SOCIAL = 70;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
     
        sensorManager = (SensorManager) this.getSystemService(Context.SENSOR_SERVICE);
        if(sensorManager.getDefaultSensor(Sensor.TYPE_STEP_DETECTOR) != null)
        {
            detectorSensor = sensorManager.getDefaultSensor(Sensor.TYPE_STEP_DETECTOR);
            Log.i("yoyo","onCreate Step")
        }
    }


    @Override
    public void onSensorChanged(SensorEvent event) {
        Log.i("yoyo","Sensor changed")
    }
}
I tried to make it so that there was a function that was called every step event, where it would basically check if the user had taken a step. But I think I know what the problem is now, I'm not giving the functions any arguments. Would you know how I could make this work? I'm rather knew to Java and extensions.

update #2:
Managed to get the GenericTest extension working in my original project by copying the settings from the new project I imported it into :D now I just need to fix my extension
 
Last edited by a moderator:
W

Wraithious

Guest
here is some code of it so you can check it.
Code:
public class StepCounter extends Activity implements SensorEventListener {
private SensorManager sensorManager;
private Sensor detectorSensor;
private boolean stepWasTaken = false;

private static final int EVENT_OTHER_SOCIAL = 70;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

sensorManager = (SensorManager) this.getSystemService(Context.SENSOR_SERVICE);
if(sensorManager.getDefaultSensor(Sensor.TYPE_STEP_DETECTOR) != null)
{
detectorSensor = sensorManager.getDefaultSensor(Sensor.TYPE_STEP_DETECTOR);
Log.i("yoyo","onCreate Step")
}
}


@Override
public void onSensorChanged(SensorEvent event) {
Log.i("yoyo","Sensor changed")
}
}
I tried to make it so that there was a function that was called every step event, where it would basically check if the user had taken a step. But I think I know what the problem is now, I'm not giving the functions any arguments. Would you know how I could make this work? I'm rather knew to Java and extensions.
It's hard to find THOROUGH tutorials on how to make extensions for android, the gms default tutorial on it only scratches the absolute surface, and even blurrs out important text in example pictures such as this one:
example10.png
Now that blurred out part, that they don't explain, is a vital part of making some custom extensions work.
Next, if you want the extension to be triggered by something and alert your app, we have the JNIRunnerLib that needs to be connected between your extension and GMS. this needs to happen anywhere you see the word "this" in code, such that your example on line 13 should be changed to this:
Code:
        sensorManager = (SensorManager) RunnerActivity.CurrentActivity.getSystemService(Context.SENSOR_SERVICE);
making sure at the top of the java file that you import these 3 GMS imports:
Code:
package ${YYAndroidPackageName};
import ${YYAndroidPackageName}.R;
import com.yoyogames.runner.RunnerJNILib;
Anywhere you see startActivity or anything activity related you'd have to attach the runner
Also an alternative to always attaching the runner you can do it once with hooking it to an intent to run the extension "as is" example: //with or without arguments, example shows 2 arguments
Code:
public void ShRes(String needed, String reasoning) {
        strOk = "Ok";
        strCancel = "Cancel";
        perms = needed;
        reason = reasoning;
        Intent intent = new Intent(RunnerActivity.CurrentActivity, AudioSave.class); //This runs my javascript in android java, allready attatched to the runner
        RunnerActivity.CurrentActivity.startActivity(intent);
    }
To answer about arguments, you only need to use them if you want to give a number and/or a string to the extension. They can be added in the bottom section of the function editor window with the + - buttons. In your case I'd say you don't need any arguments, you can choose weather to return a string or a double (which you catch in a gms async event) and also you would only need to call the extension once to init it, it will automatically send the results by async, and a final shutdown method. You should only need those 3 methods.

Instead of using onCreate you need to change that to an onInit method, preferably give it a unique name so other extensions won't interfere if used together, and get rid of the call to the layout activity_main. Also there is an option box (double click the icon that holds your functions) to choose that that function is the init function.
example9.png

Also there's permissions to worry about, you need to inject the BODY_SENSORS permission into the manifest and if using android 6.0+ devices you have to ask for permissions at run time or you will get those "Exception thrown trying to call method AddTwoNumbers on GenericTest" all day.
 
Last edited by a moderator:
L

Lintydude

Guest
WOW, that's a lot to wrap my head around but I'll try... ok, so I've had a long hard think about all this and I think I have a good idea of how I should do this. Basically I need the step detector to run in the background... so... I think I'll have a java file called "Hooker.java" which will act as the Intent hooker, which will pass the Intent to a file called "StepDetector.java", which should register a listener everytime it starts... right? I may need to contact you on Skype if you aren't busy.
 
W

Wraithious

Guest
Basically I need the step detector to run in the background.
Sorry if my reply was confusing, I was trying to give you all the info I know about converting an android java class to a GMS extension, or it might be the terminology I used, so I'll define some things here.
when I say Method it is the same thing as a function, or a script that may or may not have arguments, example:
Code:
public double AddTwoNumbers(double inputNumber) {
//....code to add random number to input number
}
an Intent in java starts a method or a java class, or a service. The example part I wrote about starting an intent to run your java class actually calls itself so that it can go through it's onInit method, but can be used for other things too, and most of the time isn't used.

It would be fairly easy to set up with just 1 java class file, all you need is:
the imports at the top,
followed by the class name extends...
and then your defined variables (declared as static in most cases that you'd want to be permanently changed vs temporary variables),
an on init method, or onStart method which will turn on the step listener,
and a final method to shut off the listener by changing the detectorSensor variable back to null.
Also a returnAsync method that will call gms on it's own if you set up the @override method that catches the steps to call it.

For an added bonus in functionality you can also have a method to check weather the listener is active, make a function called isMonitoringSteps( ) ; then in your java class make a method:
Code:
public void isMonitoringSteps(){
int check=0;
if (detectorSensor != null){
check=1;
}
return check;
}
then in gms you just need to tick the relitive box for init and final function (function same as method), or call the init method once on game start and the final method in the game end event and
a social async event that the extension fires the results to.

and the added bonus to check weather initted or not can be checked by calling:
Code:
global.isInitted = isMonitoringSteps();
if (global.isInitted = 1) {
//your code here
}
else if (global.isInitted = 0) {
// call your init method and / or do some other code
}
Oh sorry but I don't have skype, I visit here at least a few times a day, but I think our time difference appears to be 12 hours lol
 
Last edited by a moderator:
Top