You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 9, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Nov 9, 2026. It is now read-only.
'DownloadDrawablesAsync' does not implement inherited abstract member 'AsyncTask.DoInBackground(params Object[])' #647
When I try compile a binding to google mediation mopub adapter I get the error 'DownloadDrawablesAsync' does not implement inherited abstract member 'AsyncTask.DoInBackground(params Object[])'
1>C:\Users\fernando\source\repos\Google.Ads.Mediation.Mopub\Google.Ads.Mediation.Mopub\obj\Debug\generated\src\Com.Mopub.Mobileads.Dfp.Adapters.DownloadDrawablesAsync.cs(10,23,10,45): error CS0534: 'DownloadDrawablesAsync' does not implement inherited abstract member 'AsyncTask.DoInBackground(params Object[])'
Version Information
Microsoft Visual Studio Enterprise 2019
Version 16.5.5
VisualStudio.16.Release/16.5.5+30104.148
Microsoft .NET Framework
Version 4.8.03752
Installed Version: Enterprise
Xamarin 16.5.000.533 (d16-5@9152e1b)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.
Xamarin Designer 16.5.0.470 (remotes/origin/d16-5@681de3fd6)
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.
Xamarin Templates 16.5.49 (0904f41)
Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.
@fernandovm
If bindings project would be that easy... We are trying to make bindings projects easy, but it will work only in ideal case.
In your case you are inheriting a type and binding generator generates code w/o compiling (or even better semantically analysing the code), so the only way is to tweak class inheritance (metadata) with metadata transforms in metadata.xml:
remove base class - NO-NO
check if the method is generated and why c# has issues with it
Because Mopub version returns System.Collections.Generic.IDictionary<string, global::Android.Graphics.Drawables.Drawable>, while AsyncTask returns Java.Lang.Object
<attr
path="/api/package[@name='com.mopub.mobileads.dfp.adapters']/class[@name='DownloadDrawablesAsync']/method[@name='doInBackground' and count(parameter)=1 and parameter[1][@type='java.lang.Object...']]"
name="managedReturn"
>
Java.Lang.Object
</attr>
It should have the same signature as method in the base class, but the error persists.
I'm not sure why managedReturn isn't good enough. Switching it to return will build:
<attr
path="/api/package[@name='com.mopub.mobileads.dfp.adapters']/class[@name='DownloadDrawablesAsync']/method[@name='doInBackground' and count(parameter)=1 and parameter[1][@type='java.lang.Object...']]"
name="return">
Java.Lang.Object
</attr>
That's generally frowned upon as it messes with the type that gets sent to Java, so you will need to test it before you ship it. (This is effectively what @moljac's <remove-node>/<add-node> is doing.)
It's not good enough because managedReturnonly changes the declared return type, and nothing in the body. The problem is that JavaDictionary<T>.FromJniHandle() returns an IDictionary<TKey, TValue>, which is not implicitly convertible to Java.Lang.Object, hence the compilation error.
The problem with the "just change the return type" approach, suggested by @jpobst and @moljac, is that it will break subclassing and overriding, because the return type is used to tell the Java Callable Wrapper generator what Java return type to use. By altering it to be java.lang.Object, the JCW return type will likewise be java.lang.Object, which is not the original java.util.HashMap or a subclass thereof.
The result will be Java Callable Wrapper generator errors from javac.
What we need is a (not fully specified or thought-out) generator "solution" which allows the Java & managed return types to "diverge" in more significant ways than what managedReturn currently allows.
For example, if there was an implicit conversion fromIDictionary & other collection types toJava.Lang.Object, managedReturn would likely work as-is:
While this "works," is this something we want to support? (Though Java.Lang.Objectalready has a ton of implicit conversion operators, so perhaps this is "fine"…)
Alternatively, could we allow generator to detect that the types aren't implicitly convertible, e.g. that IDictionary isn't implicitly convertible to Java.Lang.Object, and in such instances insert an appropriate .JavaCast<T>?
@moljac The thing is your metadata doesn't "fail". If it couldn't match anything it would have given you an error like: <attr path=\"{0}\"/> matched no nodes..
All metadata does is modify the api.xml using XPath, it doesn't understand what that actually is, and it is successfully adding the managedReturn attribute.
It just happens to be a successful change that doesn't fix the issue. 😄
If you run Rebuild, what messages are you seeing in the log? There's generally pretty good warnings telling you exactly why it is skipping over each type/method it doesn't bind.
Hi @jpobst, yes, generally, but unfortunately seems is not be this case. In normal output msbuild verbosity is generated just one: warning CS0109: The member 'BuildConfig.class_ref' does not hide an accessible member. The new keyword is not required.
These are the output as the process moves through in order (parsing the jar, resolving the java types, applying metadata), so if we can find where the types disappear it should tell us what step is failing.
If they aren't in any of the files, you can use a Java decompiler to see if they exist in the .jar: obj\Debug\library_project_jars\classes.jar.
Hi guys, excuse me by delay in reply. So @jpobst, indeed, I don't know why (maybe it is just some kind of gradle wrapper), but the mopub android sdk .aar file downloaded from bintray does not has the need classes inside the classes.jar file.
Well, I built the mopub android sdk from github sources and create a binding library from the .jar generated file. Several adjustments were needed in metadata file to build with succesfull, but okay, it worked.
However, when I add a reference to this binding library in my android app project I have new compilation errors, such as:
obj\Off\90\android\src\mono\com\mopub\mobileads\VideoDownloader_VideoDownloaderListenerImplementor.java:8: error: VideoDownloaderListener is not public in VideoDownloader; cannot be accessed from outside package com.mopub.mobileads.VideoDownloader.VideoDownloaderListener
So, the main problem is that in generated file from obj\Debug\generated\src the interface already appears as public:
// Metadata.xml XPath class reference: path="/api/package[@name='com.mopub.mobileads']/class[@name='VideoDownloader']"[global::Android.Runtime.Register("com/mopub/mobileads/VideoDownloader",DoNotGenerateAcw=true)]publicpartialclassVideoDownloader:global::Java.Lang.Object{// Metadata.xml XPath interface reference: path="/api/package[@name='com.mopub.mobileads']/interface[@name='VideoDownloader.VideoDownloaderListener']"[Register("com/mopub/mobileads/VideoDownloader$VideoDownloaderListener","","Com.Mopub.Mobileads.VideoDownloader/IVideoDownloaderListenerInvoker")]publicpartialinterfaceIVideoDownloaderListener:IJavaObject,IJavaPeerable{// Metadata.xml XPath method reference: path="/api/package[@name='com.mopub.mobileads']/interface[@name='VideoDownloader.VideoDownloaderListener']/method[@name='onComplete' and count(parameter)=1 and parameter[1][@type='boolean']]"[Register("onComplete","(Z)V","GetOnComplete_ZHandler:Com.Mopub.Mobileads.VideoDownloader/IVideoDownloaderListenerInvoker, Higgx.Library.AdSource.Mopub.Sdk.Android")]voidOnComplete(boolp0);}//removed code..}
Would appreciate if you point to me what's the problem that I can't see. :((
That error is coming from Java, not C#. So you'll need to look at the .jar that it is trying to compile against and see if the interface is public there.
Since you do this to change the C# version I suspect it is not public in Java:
Hi @jpobst, this change in C# was just a test (one of them), but yes, it is not public in Java (see here), it is visible only inside its package.
The problem seems me is that in binding library it is generated as public, but, even I changing that using metatada (to force the internal visibility) I get erros when compiling my app that reference this binding library.
Ok, sorry, let's go.. The interface VideoDownloaderListener is not public in the java code, but I get the error described above, even without to do any visibility change in the metadata.
Then, I have made several tests changing the visibility of this interface using metadata, just attempts to try understand how the generator would can interpret the case, but, I was not successful.
When I compile the sample project using VS2019 16.6.0 I get:
error: MraidBridge_MraidBridgeListenerImplementor is not abstract and does not override abstract method onSetOrientationProperties(boolean,MraidOrientation) in MraidBridgeListener
\mono\com\mopub\mraid\MraidBridge_MraidBridgeListenerImplementor.java
This is because onSetOrientationProperties in the interface MraidBridgeListener requires a parameter of type MraidOrientation, which is not a public type in Java.
However this does not seem to be the error you are getting. Is this an error you have gotten previously and have a workaround for?
When I compile it I also get this error, in really, I get seven errors:
I didn't mentioned before because I wanted solve the other six problems, they seems me the same thing.
About MraidBridgeListener, I haven't tested, but as it requires the type MraidOrientation which is not a public, I think that there isn't to do, unless remove it using metadata. This will compile, but after will see if works in runtime.
Activity
moljac commentedon May 19, 2020
@fernandovm
If bindings project would be that easy... We are trying to make bindings projects easy, but it will work only in ideal case.
In your case you are inheriting a type and binding generator generates code w/o compiling (or even better semantically analysing the code), so the only way is to tweak class inheritance (metadata) with metadata transforms in metadata.xml:
So that method was generated:
So why does it not build?
Because Mopub version returns
System.Collections.Generic.IDictionary<string, global::Android.Graphics.Drawables.Drawable>, while AsyncTask returnsJava.Lang.Objectsee: https://docs.microsoft.com/en-us/dotnet/api/android.os.asynctask.doinbackground?view=xamarin-android-sdk-9#Android_OS_AsyncTask_DoInBackground_Java_Lang_Object___
So if add this to your
metadata.xml:It should have the same signature as method in the base class, but the error persists.
@jpobst @jonpryor
This will make your code build (at least it did in my code):
I will create repro sample in the repo and post it here.
moljac commentedon May 19, 2020
I managed to bind v.5.4.1 without any metadata.
There is something in v.5.12.0
OK mvnrepository does not have the latest version, but bintray:
https://bintray.com/mopub/mopub-android-sdk/mopub-android-sdk/_latestVersion
5.12.0 builds w/o issues and metadata too
https://github.com/HolisticWare/HolisticWareComponents/tree/master/XPlat/Mopub
Seems that new and old style projects (and tooling) do make the difference:
https://github.com/HolisticWare/HolisticWareComponents/blob/master/XPlat/Mopub/source/Mopub.XamarinAndroid/Mopub.XamarinAndroid.csproj
jpobst commentedon May 19, 2020
I'm not sure why
managedReturnisn't good enough. Switching it toreturnwill build:That's generally frowned upon as it messes with the type that gets sent to Java, so you will need to test it before you ship it. (This is effectively what @moljac's
<remove-node>/<add-node>is doing.)jpobst commentedon May 19, 2020
For internal investigation:
There's 2 issues with what gets generated for
managedReturn:virtualrather thanoverride. (https://github.com/xamarin/java.interop/issues/586)JavaDictionary<string, Drawable>instead ofJLO.jonpryor commentedon May 19, 2020
@jpobst asked:
It's not good enough because
managedReturnonly changes the declared return type, and nothing in the body. The problem is thatJavaDictionary<T>.FromJniHandle()returns anIDictionary<TKey, TValue>, which is not implicitly convertible toJava.Lang.Object, hence the compilation error.jonpryor commentedon May 19, 2020
The problem with the "just change the
returntype" approach, suggested by @jpobst and @moljac, is that it will break subclassing and overriding, because thereturntype is used to tell the Java Callable Wrapper generator what Java return type to use. By altering it to bejava.lang.Object, the JCW return type will likewise bejava.lang.Object, which is not the originaljava.util.HashMapor a subclass thereof.The result will be Java Callable Wrapper generator errors from
javac.moljac commentedon May 19, 2020
@jonpryor @jpobst
If such metadata fails (like my attempt to change
managedReturn) would it be possible to emit warning or error in such case?jonpryor commentedon May 19, 2020
What we need is a (not fully specified or thought-out)
generator"solution" which allows the Java & managed return types to "diverge" in more significant ways than whatmanagedReturncurrently allows.For example, if there was an implicit conversion from
IDictionary& other collection types toJava.Lang.Object,managedReturnwould likely work as-is:While this "works," is this something we want to support? (Though
Java.Lang.Objectalready has a ton of implicit conversion operators, so perhaps this is "fine"…)Alternatively, could we allow
generatorto detect that the types aren't implicitly convertible, e.g. thatIDictionaryisn't implicitly convertible toJava.Lang.Object, and in such instances insert an appropriate.JavaCast<T>?Though as-is, this would also require some additional "glue code" to add a new
.JavaCast<T>()extension method that operates onIDictionary/etc.jpobst commentedon May 19, 2020
@moljac The thing is your
metadatadoesn't "fail". If it couldn't match anything it would have given you an error like:<attr path=\"{0}\"/> matched no nodes..All
metadatadoes is modify theapi.xmlusing XPath, it doesn't understand what that actually is, and it is successfully adding themanagedReturnattribute.It just happens to be a successful change that doesn't fix the issue. 😄
3 remaining items
jpobst commentedon May 20, 2020
If you run Rebuild, what messages are you seeing in the log? There's generally pretty good warnings telling you exactly why it is skipping over each type/method it doesn't bind.
fernandovm commentedon May 20, 2020
Hi @jpobst, yes, generally, but unfortunately seems is not be this case. In normal output msbuild verbosity is generated just one: warning CS0109: The member 'BuildConfig.class_ref' does not hide an accessible member. The new keyword is not required.
The diagnostico verbosity output log: build-output.txt
jpobst commentedon May 20, 2020
Are the types listed in:
These are the output as the process moves through in order (parsing the jar, resolving the java types, applying metadata), so if we can find where the types disappear it should tell us what step is failing.
If they aren't in any of the files, you can use a Java decompiler to see if they exist in the .jar:
obj\Debug\library_project_jars\classes.jar.fernandovm commentedon May 30, 2020
Hi guys, excuse me by delay in reply. So @jpobst, indeed, I don't know why (maybe it is just some kind of gradle wrapper), but the mopub android sdk .aar file downloaded from bintray does not has the need classes inside the classes.jar file.
Well, I built the mopub android sdk from github sources and create a binding library from the .jar generated file. Several adjustments were needed in metadata file to build with succesfull, but okay, it worked.
However, when I add a reference to this binding library in my android app project I have new compilation errors, such as:
obj\Off\90\android\src\mono\com\mopub\mobileads\VideoDownloader_VideoDownloaderListenerImplementor.java:8: error: VideoDownloaderListener is not public in VideoDownloader; cannot be accessed from outside package com.mopub.mobileads.VideoDownloader.VideoDownloaderListenerSo, the main problem is that in generated file from obj\Debug\generated\src the interface already appears as public:
Would appreciate if you point to me what's the problem that I can't see. :((
Thank you!
jpobst commentedon Jun 1, 2020
That error is coming from Java, not C#. So you'll need to look at the
.jarthat it is trying to compile against and see if the interface is public there.Since you do this to change the C# version I suspect it is not public in Java:
I'm not sure how you're intended to implement that interface, even if you were consuming this directly from Java, if it's not public.
fernandovm commentedon Jun 4, 2020
Hi @jpobst, this change in C# was just a test (one of them), but yes, it is not public in Java (see here), it is visible only inside its package.
The problem seems me is that in binding library it is generated as public, but, even I changing that using metatada (to force the internal visibility) I get erros when compiling my app that reference this binding library.
jpobst commentedon Jun 4, 2020
I'm afraid I don't understand what you are saying, it is explicitly being marked
publicin C# by this metadata:What error do you get when you remove that?
fernandovm commentedon Jun 4, 2020
Ok, sorry, let's go.. The interface VideoDownloaderListener is not public in the java code, but I get the error described above, even without to do any visibility change in the metadata.
Then, I have made several tests changing the visibility of this interface using metadata, just attempts to try understand how the generator would can interpret the case, but, I was not successful.
You can see this problem in the updated sample project Google.Ads.Mediation.Mopub.zip.
jpobst commentedon Jun 5, 2020
When I compile the sample project using VS2019 16.6.0 I get:
This is because
onSetOrientationPropertiesin the interfaceMraidBridgeListenerrequires a parameter of typeMraidOrientation, which is not a public type in Java.However this does not seem to be the error you are getting. Is this an error you have gotten previously and have a workaround for?
fernandovm commentedon Jun 5, 2020
When I compile it I also get this error, in really, I get seven errors:
I didn't mentioned before because I wanted solve the other six problems, they seems me the same thing.
About
MraidBridgeListener, I haven't tested, but as it requires the type MraidOrientation which is not a public, I think that there isn't to do, unless remove it using metadata. This will compile, but after will see if works in runtime.jpobst commentedon Jun 5, 2020
I think those 6 will go away if you update to 16.6+, due to this change: #572.
Granted, the fix is that the listeners are going to go away, but they are package-private in Java, and shouldn't be bound.
That only leaves the error I mentioned.
fernandovm commentedon Jun 5, 2020
Indeed, great!
I will remove the MraidBridge class using metadata and to test at runtime.
<remove-node path="/api/package[@name='com.mopub.mraid']/class[@name='MraidBridge']" />jpobst commentedon Jul 1, 2020
Hopefully this fixed your issue! If not, please comment with updated details and we can re-open.