Android NDK overriding methods - android

I have 2 NDK libraries (.so files ) in my android project and there is a method in the first library that is also called (used) in the first library and I want the second library to override the called (used) method found in the first library. Is it possible to just have the same name and parameters and load the second library after the first like
System.load(first);
System.load(second);
Will this override the first method or do I have to do something else? If so, please specify.
Thanks in advance for your time.

Once a symbol has been resolved (by System.load) it will not be changed. The definition loaded from first will be used.

Related

Xamarin binding .aar with Metadata.xml doesn't seem to work

I'm trying to bind an android SDK for voice chat (zoom sdk).
They have two .aar files (zoomcoomonlib.aar and zoomsdk.aar)
I know I have to create separate binding project for each .aar and then reference them.
While binding zoomsdk.aar I'm getting the below error
The type `Com.Zipow.Videobox.Onedrive.ErrorEventArgs' already contains a definition for `P0' (CS0102) (B14)
In the .aar file I navigated to the package com.zipow.videobox.onedrive; to the interface IODFoldLoaderListener
And below are the contents of it
So it seems parameter String var1 of method onError is causing the issue.
And xamarin studio generated obj/debug/api.xml confirms it (below screenshot) that onError will have first parameter named p0:
So in this scenario I change the metadata.xml to give this parameter a meaningful name.
Like below screenshot:
But even after doing that I am getting same error. That error didn't resolve.
Moreover now if I see the obj/debug/api/.xml file I see the contents for the class IODFoldLoaderListener remains the same.
So changing the metadata.xml has no effect it seems.
Your definition needs to be changed quite a bit. Here is an example that solves the same problem:
<attr path="/api/package[#name='com.emarsys.mobileengage.inbox']/interface[#name='ResetBadgeCountResultListener']/method[#name='onError' and count(parameter)=1 and parameter[1][#type='java.lang.Exception']]" name="argsType">ResetBadgeCountResultListenerOnErrorArgs</attr>
Please note the /interface and argsType items here as your initial definition is incorrect. You would then change the parameters to strings instead of java.lang.Exception from my example.

java.lang.UnsatisfiedLinkError: No implementation found for void package name with method

Not able to call any native method from java file.Getting this error not able to resolve.I already check method name in c file absolute match and .so file also loaded.Getting Log for JNI_OnLoad ENTRY.
Based on your question it is hard to judge.
I suggest to start with something super simple. For example, take a look here:
http://jnicookbook.owsiak.org/recipe-No-001/
This is super simple, Hello World, sample for JNI based codes.
Just take a look at all the pieces required to successfully run the code and try to replicate it in your environment.

Shortcut for Overriding methods in Android Studio

I have recently migrated to Android Studio and I am pretty used to the Source -> Override/Implement feature in Eclipse.
I was wondering where I could find the same feature on Android Studio. I've tried "Alt-Insert"/Generate-Override methods but I don't find the OnPause() method to override in the list. How do I get the methods that I want to override in the list?
These are the only methods that are available to me on my IDE.
Ctrl + O
should work well in Android Studio.
Press Alt(Left one)+insert.
It shows all the dialog with heading "Generate"
Choose override methods.
Shortcut- Ctrl+O
The method you want to override has to be declared in a class you implement or extend. It might be that your class does not extend Activity (for example). And your project might have to be an android project and not a plain java project.
My understanding is that you need to have the class in your code for Android Studio to offer you the override options pertaining to that class. The image you've posted seems to have only one class.
See how many I got:

calling jni method from other jni library

Is it possible to call jni method of 1 library from another method of different jni library ?
for eg: I have 2 libraries lib_1.so and lib_2.so.
I want to call a method get_interface() of lib_1.so from lib_2.so.
Is this possible?
If yes, please share the example of how this can be done.
When calling from one shared library to another, its really no longer jni, its just native code(c->c or c++ -> c++). Include the .h and invoke the function as you would normally, passing whatever parameters the function requires.
I think you can do dlopen("lib2.so") from lib1.so so you have a handle to your lib2.so library and then using that handle you can call the methods.

Eclipse Indigo does not allow #Override for non Activity overwritten methods

I am using Eclipse Indigo for Android development. The problem i face is that it does not allow #Override for non Activity overwritten methods. For example if i implement onErrorListner of MediaPlayer and i set attribute #Override with it then it gives the following compile time error:
The method onError(MediaPlayer, int, int) of type MyActivity must override a superclass method
And to fix this problem, i am suggested the following
Remove "#Override" annotation
Tough removing the #Override fixes the issue but why does it complain about it and also removing it may cause stopping some functionality of its parent etc??
I have downloaded many examples which use this "#Override" attribute with non-activity methods which proves that this is used and i might be missing some obvious thing. But i cannot run these examples in Eclipse Indigo without removing these "#Override" attributes from all the classes.
Why?
Any help is greatly appreciated.
Your project Java compiler level is set to 1.5 instead of 1.6. See here.
It is not good to remove that line. you need to change to JDK version in your eclipse then you will not get such errors. Follow, following steps for it,
Right Click on your Project & select Properties.
Then from the left section Select Java Compiler & select the Version of the JDK you installed. If it is already selected then de-select it & try it.

Categories

Resources