Unity Plugin AndroidJavaException NoSuchMethodError on Function with parameters - android

I got a very annoying issue. All of my Android plugins in Unity just work if I dont use parameters in the calling functions. I am working on this issue since 2 days and I am slowly running out of ideas. Even a minimal project doesnt work. I am sure Iam doing it right because my functions are working fine without parameters.
Unity:
void Start (){
AndroidJavaClass pluginClass = new AndroidJavaClass("tnbrtrm.lications.de.myplugin.MyPlugin");
String test = pluginClass.CallStatic<string>("getMessage", new object[] { "alalalalala" });
Debug.Log("callShareAppAARPlugin: " + test);}
Android:
public class MyPlugin extends UnityPlayerActivity {
public static String getMessage(String text)
{ return "Hello World! " + text; }
}
My plugin prints "Hello world" correctly when I delete the parameter "String text", but with parameter I get this annoying error:
AndroidJavaException: java.lang.NoSuchMethodError: no static method "Ltnbrtrm/lications/de/myplugin/MyPlugin;.getMessage(Ljava/lang/String;)Ljava/lang/String;"
I see this error using Plugins as *.jar or *.aar. And I also had a look into this packages and my Classes and Functions are there. Otherwise it wouldnt work without parameters... I tried AndroidJavaClass and AndroidJavaObject.
Can anyone please help me? I tried a lot of things... (older JDK versions, etc.) I seems so easy in all the turorials so I assume it has something to do with my system or unity (5.3.5 pro).
Kind regards,
Tino

Related

How do I send messages from Android to Unity (with VR)? (UnityPlayer.UnitySendMessage doesn't work)

-> Summary:
I want to send messages from AndroidStudio - Code to Unity - Normal way doesn't seem to be working.
-> What I tried:
I have two projects in Unity3D. They are exactly the same, except that one of them is set up for the Oculus Gear Vr...
Then I export (Android) both of these Projects and open them as AndroidStudio Projects.
When i run these now both work exactly as expected !
But when i try to use the UnityPlayer.UnitySendMessage - method, the method seems not to be executed in the app with the setup vor VR...
The app doesnt crash, it doesnt show any errors in LogCat and i tried to catch any Throwable but that didnt work either...
(On the App with no VR setup the exact same lines of codes works ...)
-> Android - Code:
public class UnityPlayerActivity extends Activity {
[...]
onCreate(Bundle savedInstanceState){
[...] //code generated by Unity
try{
Log.d("mDEBUG", "Test Android1");
UnityPlayer.UnitySendMessage("AndroidCommunication", "AndroidStudioInit", "false");
Log.d("mDEBUG", "Test Android2");
}catch(Throwable e){
e.printStackTrace();
}
}
//Function used by Unity - Code
public void unityLog(String msg){
Log.d("mDEBUG", "Unity: " + msg);
}
[...]
}
-> Unity - Code:
public void AndroidStudioInit(string flag)
{
bool sendCurCameraRotation = bool.Parse(flag);
AndroidJavaClass unityPlayerClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject unityPlayerActivity = unityPlayerClass.GetStatic<AndroidJavaObject>("currentActivity");
unityPlayerActivity.Call("unityLog", "AndroidStudio - Unity - Init");
}
-> Expected Outputs:
For both apps it should print in Logcat:
"[...] D/mDEBUG: Test Android1"
"[...] D/mDEBUG: Unity: AndroidStudio - Unity - Init"
"[...] D/mDEBUG: Test Android2"
-> Actual Results:
For app without setup for VR:
"[...] D/mDEBUG: Test Android1"
"[...] D/mDEBUG: Unity: AndroidStudio - Unity - Init"
"[...] D/mDEBUG: Test Android2"
For app with VR:
"[...] D/mDEBUG: Test Android1"
"[...] D/mDEBUG: Test Android2"
There are also no errors and the Unity App doesnt crash... it just "seems to ignore" the function call...
Ok it seems I know what the problem is and I think it can't really be helped...
I was sending a message to Unity like this:
mUnityPlayer = new UnityPlayer(this);
setContentView(mUnityPlayer);
mUnityPlayer.requestFocus();
UnityPlayer.UnitySendMessage("AndroidCommunication", "AndroidStudioInit", "false");
And normally Unity will store the message in a queue to execute it after Unity has started properly.
That works for the App without Vr enabled just fine.
But with Vr mode enabled a screen will first show up on your device (something like "Put your device into the Gear Vr ...").
And I think it somehow messes up with the message sending...
So Unity will only execute messages after proper starting (After window "Made by Unity" went by).
To remember: Don't send Messages until unity has completely started if you use Vr... If you still want to execute code on start you can try to build a method in Unity that will notify the android code that Unity has finished !
Cheers !

Xamarin Wizard Project Can't Debug

So some background information. I am tasked with exploring writing cross platform native applications using Xamarin. Seems pretty basic so far and I'm liking what I'm reading. I have my Visual Studio 2015 Enterprise all set up and my remote mac configured on the network. I created a cross platform native app through the project creation wizard in Visual Studio. When I launch a debug session for the iOS app, it does start the target app in the simulator on the remote Mac. However, it never actually thinks it is running fully. It will hang at this output:
Launching 'PersonalProject.iOS' on 'iPhone 6 iOS 10.2'...
Loaded assembly: /Users/plm/Library/Developer/CoreSimulator/Devices/B5A038B6-056F-4E6C-A59C-29ABD8C04CD0/data/Containers/Bundle/Application/2A1B11FF-6C59-4A9B-9CE3-7B8446B1AD48/PersonalProject.iOS.app/Xamarin.iOS.dll
Loaded assembly: /Users/plm/Library/Developer/CoreSimulator/Devices/B5A038B6-056F-4E6C-A59C-29ABD8C04CD0/data/Containers/Bundle/Application/2A1B11FF-6C59-4A9B-9CE3-7B8446B1AD48/PersonalProject.iOS.app/System.dll
Thread started: #2
Loaded assembly: /Users/plm/Library/Developer/CoreSimulator/Devices/B5A038B6-056F-4E6C-A59C-29ABD8C04CD0/data/Containers/Bundle/Application/2A1B11FF-6C59-4A9B-9CE3-7B8446B1AD48/PersonalProject.iOS.app/PersonalProject.iOS.exe
Loaded assembly: /Users/plm/Library/Developer/CoreSimulator/Devices/B5A038B6-056F-4E6C-A59C-29ABD8C04CD0/data/Containers/Bundle/Application/2A1B11FF-6C59-4A9B-9CE3-7B8446B1AD48/PersonalProject.iOS.app/System.Xml.dll
Eventually, it will fail with something along these lines:
The app has been terminated.
Launch failed. The app 'PersonalProject.iOS' could not be launched on 'iPhone 6 iOS 10.2'. Error: An error occurred while executing MTouch. Please check the logs for more details.
I've checked the log file in question and it contains nothing more than the same exact phrase.
If I try and put a simple line of Console writing on the action of pressing the button:
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
// Perform any additional setup after loading the view, typically from a nib.
Button.AccessibilityIdentifier = "myButton";
Button.TouchUpInside += delegate {
var title = string.Format ("{0} clicks!", count++);
Button.SetTitle (title, UIControlState.Normal);
Console.WriteLine(string.Format("{0} clicks!"));
};
}
the debug session actually errors on this line 17 (UIApplication.Main) in the Main.cs file:
using System;
using System.Collections.Generic;
using System.Linq;
using Foundation;
using UIKit;
namespace PersonalProject.iOS
{
public class Application
{
// This is the main entry point of the application.
static void Main (string[] args)
{
// if you want to use a different Application Delegate class from "AppDelegate"
// you can specify it here.
UIApplication.Main (args, null, "AppDelegate");
}
}
}
With Unhandled exception error:
Unhandled Exception:
System.FormatException: Index (zero based) must be greater than or equal to zero and less than the size of the argument list.
Error while resolving expression: One or more errors occurred.
If I don't have the console log it will launch the app, but still hanges at those Loaded assembly lines. At this point, I can't hit any breakpoints in my code. I tried adding a breakpoint in the shared code for the button click but it would never hit it, even though the action was being carried out by the simulator.
I'm completely at a loss for how to proceed. I haven't touched anything out of the box of the wizard creation. I was hoping I could at least see the starter project working.
Any help is appreciated.
You are using
Console.WriteLine(string.Format("{0} clicks!"));
The {0} is a placeholder for a value to output, but you never specify that value, that's why you are getting an error.
Use something like this instead:
Console.WriteLine(string.Format("{0} clicks!", count));
or in C#6 syntax:
Console.WriteLine($"{count} clicks!");

C++ Builder WSDL client for Android

I'm having a confusing problem. I'm trying to make a Web cleint that uses WSDL.
I'm using C++ RAD Studio 10 Seattle, but the same problem occured in RAD Studio XE8(older version).
1.I create a Multi-Device Application, add one Edit component and one Button.
2.I create a WSDL Importer by changing the location of the WSDL file to : "http://www.w3schools.com/webservices/tempconvert.asmx?WSDL" and leave all other setting to default.
3.On ButtonClick event of the button I write two lines of code :
_di_TempConvertSoap Converter = GetTempConvertSoap(true,
"http://www.w3schools.com/webservices/tempconvert.asmx?WSDL");
Edit1->Text = Converter->CelsiusToFahrenheit("32");
So after these three steps I have one unit, which is the main Unit with the Form and with the button event. And one file "tempconvert.cpp" that the WSDL Importer has generated. It quite actually just translates the WSDL code to a C++ one and defines the method to communicate with the server. In my case I have two methods : FahrenheitToCelsius() and CelsiusToFahrenheit(), in the example I use CelsiusToFahrenheit().
I compile it to 32-bit Windows platform, run it and when I click the button, the result "89.6" appears in the text of the Edit component. So this is working as expected.
But when I change the target platform to "Android" and use my mobile phone "Samsung GT-I8262" with Android 4.1.2 and run the project, it just stops and exits. I debugged the problem and it stops at the first command in "tempconvert.cpp" in RegTypes() method.
// ************************************************************************
//
// This routine registers the interfaces and types exposed by the WebService.
// ************************************************************************ //
static void RegTypes()
{
/* TempConvertSoap */
InvRegistry()->RegisterInterface(__delphirtti(TempConvertSoap), L"http://www.w3schools.com/webservices/", L"utf-8");
InvRegistry()->RegisterDefaultSOAPAction(__delphirtti(TempConvertSoap), L"http://www.w3schools.com/webservices/%operationName%");
InvRegistry()->RegisterInvokeOptions(__delphirtti(TempConvertSoap), ioDocument);
/* TempConvertSoap.FahrenheitToCelsius */
InvRegistry()->RegisterMethodInfo(__delphirtti(TempConvertSoap), "FahrenheitToCelsius", "",
"[ReturnName='FahrenheitToCelsiusResult']", IS_OPTN);
/* TempConvertSoap.CelsiusToFahrenheit */
InvRegistry()->RegisterMethodInfo(__delphirtti(TempConvertSoap), "CelsiusToFahrenheit", "",
"[ReturnName='CelsiusToFahrenheitResult']", IS_OPTN);
/* TempConvertHttpPost */
InvRegistry()->RegisterInterface(__delphirtti(TempConvertHttpPost), L"http://www.w3schools.com/webservices/", L"utf-8");
InvRegistry()->RegisterDefaultSOAPAction(__delphirtti(TempConvertHttpPost), L"");
}
#pragma startup RegTypes 32
Does someone have any idea why this might be happening? I tried on two other Samsung phones and it didn't work. The error that shuts the program down is "Segmentation fault(11)", and more precisely it stops at the following line of code in "System.pas" file :
u_strFromUTF8(PUChar(Dest), MaxDestChars, DestLen, MarshaledAString(Source), SourceBytes, ErrorConv);
Here is some info that I've found about the function:
u_strFromUTF8 - function that converts a UTF-8 string to UTF-16.
UCHAR is a Byte(in Delphi), so PUCHAR is a pointer to Byte.
I cannot se what could possibly go wrong with this function which apparently only converts a string.
So my question is why does the project work on Windows 32 bit version, but on Android it throws Segmentation fault(11)?
I hope I could find a solution for this problem. I will keep looking.
Thank you,
Zdravko Donev :)
UPDATE:
I disassembled the line:
InvRegistry()->RegisterInterface(__delphirtti(TempConvertSoap), L"http://www.w3schools.com/webservices/", L"utf-16");
to get :
TInvokableClassRegistry *Class = InvRegistry();
TTypeInfo *Info = __delphirtti(TempConvertSoap);
UnicodeString Namespace = "http://www.w3schools.com/webservices/";
UnicodeString WSDLEncoding = "utf-8";
Class->RegisterInterface(Info, Namespace, WSDLEncoding);
And I saw that the problem occurs when calling InvRegistry() function, but I still haven't found the problem as I cannot reach the source code of the function.
I found a solution.
I deleted the line
#pragma startup RegTypes 32
and called the method RegTypes() on my own when I create the form and it worked.

Working AdMob ANE for AIR 4.0 or 13

I am trying to add an AdMob ANE to an empty Flex Mobile Project but I can see nothing inside the view. Also I am checking the load events and no error occurs. :(
My setup:
Adobe FlashBuilder 4.7 (64 bit) Windows
Apache Flex 4.10 ( AIR 4.0 )
Valid AdMob GUID
Updated -app.xml file to allow AdMob
Tested with the samples from following open source ANEs
https://code.google.com/p/flash-air-admob-ane-for-ios-and-android/
https://github.com/pozirk/ANEAdMob
And so far no luck...
Can someone suggest better anes or comment if the listed ones work for their apps ?
Thanks!
Update
I have reupdated my sdk and updated AIR on my device to latest version from
/sdk/runtimes/air/android/device/
Now with the ANE from 1st URL i receive the following message in console:
admob ane log:status code:onBannerFailedReceivelevel:3
My code for this ANE looks like this (just same as in the sample from github )
package com.redcodelabs.view
{
import flash.geom.Rectangle;
import mx.core.UIComponent;
import so.cuo.platform.admob.Admob;
import so.cuo.platform.admob.AdmobEvent;
import so.cuo.platform.admob.AdmobPosition;
public class AdMobView extends UIComponent
{
public var admob:Admob=Admob.getInstance();//create a instance
public function AdMobView()
{
super();
admob.addEventListener(AdmobEvent.onBannerReceive, onAdReceived);
//set admob banner ID
admob.setKeys("ca-app-pub-246436233824XXXX/361665XXXX");
//show banner with relation position
admob.showBanner(Admob.BANNER,AdmobPosition.BOTTOM_CENTER);
}
protected function onAdReceived(event:AdmobEvent):void
{
trace(event.type);
if(event.type==AdmobEvent.onBannerReceive)
{
trace(" -- "+event.data.width,event.data.height);
}
}
}
}
With Milkmangames Admob ANE, you now have to add another ANE : Google Services.
It's a new update, and ads won't show if you don't add this ANE (even if it works an no error messages is shown).
I don't know if it's only for MilkmanGames ANEs, but maybe you have to look if a new version if available.
By the way i'm trying Adbuddiz which is a free ANE and seems to give more money than admob.
I have worked with Flash Mobile apps and the first Adobe ANE link mentioned by you where the ads show up fine. Not sure if it would be different for Flex Mobile.
Are you working with the updated Admob interface or the new one. Maybe you want to recheck your Ad id.
Also which platform are you compiling your app to? Can you share a bit of your code?
Alternately, there are many ANEs more for Admob -
MilkMan Games - http://www.milkmangames.com/blog/2012/09/27/admob-air-native-extension-now-for-ios-and-android/
This ANE is a paid one
You can also add the Admob network to MoPub and use the MoPub ANE.
https://github.com/StickSports/MoPub-ANE
onBannerFailedReceivelevel:3
error code 3 mean not enough ad for show.not your code error
package so.cuo.platform.admob
{
public class AdmobError
{
public static const ERROR_CODE_ERNAL_ERROR :int= 0;
public static const ERROR_CODE_INVALID_REQUEST :int= 1;
public static const ERROR_CODE_NETWORK_ERROR :int= 2;
public static const ERROR_CODE_NO_FILL :int= 3;
}
}
ref
https://github.com/lilili87222/admob-for-flash/blob/master/admob_ane_ios_android/doc/AdmobError.as
you are using an old ane version,admob need new version sdk after update to admob 2.0
and the error admob ane log:status code:onBannerFailedReceivelevel:3 mean that no ad for show.
check out the new version(the old link is brike project has moved to http://code.google.com/p/flash-air-admob-ane-for-ios-and-android/ ),you will get more error detail about the error code 3.

Descrease debug output level at Xamarin.Android + Visual Studio

Sorry for lame and easy question but I failed to find an answer to it.
Every time I print something to the System.Diagnostics.Debug.WriteLine I have my message tripled:
System.Diagnostics.Debug.WriteLine("test");
Output:
[0:]
test
[0:] test
10-22 19:57:13.981 I/mono-stdout( 1026): test
I'm stick to System.Diagnostic.Debug because I write messages from both UI part (monodroid) and business logic (PCL)
Is there any way to descrease level of debug noise of Xamarin.Android?
Thank you for any suggestions.
Make your own little abstraction. We have the same issue in our project, this little Interface helps:
public interface ILogger
{
void Write(LogLevel level, String tag, String message);
}
Then you have your Loggers for each platform, for example:
public class AndroidLogger: ILogger
{
public void Write(LogLevel level, string tag, string message)
{
Android.Util.Log.WriteLine(ConvertLogLevel(level), tag, message);
}
}
You inject the logger in the iOS/Android project and you can even create fancy logger like e.g. a nice file-logger for iOS:
#if DEBUG
LOG.AddLogger(new TouchFileLogger());
LOG.AddLogger(new ConsoleLogger());
#endif
The LOG-class is static and needs not to know about the implementations, thats why it can be easily used in your shared PCL library.
Hope that helps, despite your problem might be solved by now ;-)
You can use Android.Util.Log instead, this greatly decreases it. It also has different levels of logging which you can filter in logcat.
Info: Log.Info()
Debug: Log.Debug()
Warning: Log.Warn()
Error: Log.Error()
Verbose: Log.Verbose()
and additionally a WriteLine, which does all of the above:
Log.WriteLine()

Categories

Resources