Iam trying to bind a jar(zubhium sdk jar) file to my mono droid project. I have followed their guide on xamarins website and created a new binding project which I reference I my mono droid project.
I am having some issues with package names. I get the following error:
Error 3 package com.zubhium.interfaces does not exist
com.zubhium.interfaces.ZubhiumListener
C:\Users\jbp\Desktop\ny\CmsApp.Droid\obj\Debug\android\src\mono\com\zubhium\interfaces\ZubhiumListenerImplementor.java 8 25 CmsApp.Droid
from the genrated source:
package mono.com.zubhium.interfaces;
public class ZubhiumListenerImplementor
extends java.lang.Object
implements
mono.android.IGCUserPeer,
com.zubhium.interfaces.ZubhiumListener
And that is because when the project is wrapped it automaticly adds mono(.com.zubhium....) to the package name. I cant find how to remove this mono or if i can set a rule to add this part.
I tried to put <attr path="/api/package[#name='com.zubhium.interfaces']" name="managedName">mono.com.zubhium.interfaces</attr>
in the xmldata.xml file but that did not work.
Do you guys have any sugestions?
Regards
package com.zubhium.interfaces does not exist
When you bind a .jar library and reference the binding project from another project, you need to also add the .jar to your Application project and set its Build action to AndroidJavaLibrary.
Failure to do so means that the .jar won't be added to the javac $CLASSPATH, resulting in javac compilation errors when compiling the Android Callable Wrapper (as you saw), and that the .jar won't included into your final .apk. Both of these are Badâ„¢.
And that is because when the project is wrapped it automaticly adds mono(.com.zubhium....) to the package name.
That's for an "Implementor" type; you can ignore it. It's used as part of the implementation of events. If you look at the generated C# code, there should be:
[global::Android.Runtime.Register ("mono/com/zubhium/interfaces/ZubhiumListenerImplementor")]
internal sealed class ZubhiumListenerImplementor : Java.Lang.Object, IZubhiumListener {
// ...
}
The mono.com.zubhium.interfaces.ZubhiumListenerImplementor is the ACW for the internal ZubhiumListenerImplementor type.
You can't rename this type; it's an internal construct that isn't controlled via metadata.
Related
I have an .aar third party library that I want to use in Xamarin Android. So I created a new Android Bindings Library, added the aar-library and changed the Build action of the aar file to LibraryProjectZip like described here: https://learn.microsoft.com/en-us/xamarin/android/platform/binding-java-library/binding-an-aar
Nothing else was changed and I would expect the project to compile and generate a dll file.
Instead I get a lot of errors saying Error CS0542 'xy': member names cannot be the same as their enclosing type.
When I jump to the origin of the error, I find the errors in generated code by Visual Studio with the classes looking something like:
public abstract class Albumin : Java.Lang.Object {
internal Albumin ()
{
}
// (removed for readability)
[Register ("ALBUMIN")]
public const string Albumin = (string) "albumin";
I cannot modify the source code of the library.
What can I do in order to build the Binding Library successfully?
Thank you very much #Leo Zhu for the answer in the comments:
The solution is Renaming Members.
So in my case the Metadata.xml in die Binings Library would look like the following:
<attr path="/api/package[#name='com.company.android.sdk.dataclass']/interface[#name='DataClass.Albumin']/field[#name='ALBUMIN']" name="name">ALBUMIN_Binding</attr>
While upgrading a Xamarin app that leverages Splat's bitmap functionality we are getting errors around the use of the methods mentioned in the title:
'IBitmap' does not contain a definition for 'ToNative' and no accessible extension method 'ToNative' accepting a first argument of type 'IBitmap' could be found (are you missing a using directive or an assembly reference?)
In an effort to troubleshoot the problem we have created a new sample Android-only Xamarin app and referenced Splat and Splat.Drawing via NuGet. We then added calls to these methods and have reproduced the error:
public void Bar(IBitmap source)
{
Bitmap native = source.ToNative();
IBitmap bitmap = native.FromNative();
}
It seems as though the Andriod app may not be referencing the proper build of the Splat libraries. When I monitor paths containing %USERPROFILE%\.nuget\packages\splat in ProcMon I don't see any attempt by Visual Studio to open/read anything other than files in the .\netstandard2.0 directories during the build process.
When I open the netstandard2.0 libraries in DotPeek I can see that the class BitmapMixins is not included, but it is included in the monoandroid90 builds.
How do I get the reference to Splat in the Android project to pull in the proper build of Splat?
Example project can be found here: https://github.com/jctlp/SplatBitmap
The error caused by that you did not have the extension methods to assist with dealing with Bitmaps of ToNative and FromNative.
Please do not add reference by installing the Splat from NuGet directly. Add reference to the whole project of Splat would be okay.
Download the whole Splat project from the link below.
https://github.com/reactiveui/splat.git
I create a Xamarin.forms app named App1. And create a class Class2.cs in App1.Android. When I add reference to Splat from the project. It works well with ToNative and FromNative extension method.
Please note: Do not use the Bitmap, use Android.Graphics.Drawables.Drawable or var instead.
public void Bar(IBitmap source)
{
Android.Graphics.Drawables.Drawable native = source.ToNative();//var
IBitmap bitmap = native.FromNative();
}
I am writing Android application using DataBinding by referencing https://developer.android.com/topic/libraries/data-binding/index.html.
But while building my project, It is showing an error in generated class as
> '/databinding/DataBinderMapper.java:10: error: constant expression
> required.'
This error is happening in switch statement inside generated class DataBinderMapper.java (This file is an auto generated file for databinding)
Any one knows the reason for this java switch case error happening in Auto generated buld file?
Edits:
I found the reason for this issue is, layout reference created in R.java file is not final for this case.
For example, in my case layout reference in R.java is
public static int activity_main=0x7f04001c;
Actually it should be
public static final int activity_main=0x7f04001b;
But I don't know the reason for this happened and how to change it to final.
Probably your model that you are binding against has final modifiers in its variables.
This error happens when your project has dependency with library or external plugin apart from application.
The reason for this issue is, the ids generated might clash when you have dependency with multiple library/ plugins.
I would like to use the Scala (2.11) reflection package's runtime mirror in a Scala application compiled for android which is being build using Scala on android.
I was able to fiddle with ProGuard options in order to make it include the required Scala classes. However when I try to get a mirror instance:
universe.runtimeMirror(this.getClass.getClassLoader)
(Indeed it fails during the lazy computation of universe)
The application crashes in run time:
java.lang.NoClassDefFoundError: Failed resolution of: Ljava/rmi/Remote;
at scala.reflect.internal.Definitions$DefinitionsClass.RemoteInterfaceClass$lzycompute(Definitions.scala:370)
at scala.reflect.internal.Definitions$DefinitionsClass.RemoteInterfaceClass(D efinitions.scala:370)
at scala.reflect.runtime.JavaUniverseForce$class.force(JavaUniverseForce.scal a:255)
at scala.reflect.runtime.JavaUniverse.force(JavaUniverse.scala:16)
at scala.reflect.runtime.JavaUniverse.init(JavaUniverse.scala:147)
at scala.reflect.runtime.JavaUniverse.<init>(JavaUniverse.scala:78)
at scala.reflect.runtime.package$.universe$lzycompute(package.scala:17)
at scala.reflect.runtime.package$.universe(package.scala:17)
This crash is for me as expected as it isn't:
It is expected as java.rmi is not part of the Android API and I should expect any code trying to load its classes to crash.
It is unexpected as I didn't know that Scala's reflect package used java.rmi
I have traced the code to were rmi is required, that is to JavaUniverse (a trait mixed in JavaUniverse class) force method:
...
definitions.RemoteInterfaceClass
...
Which leads to DefinitionsClass:
lazy val RemoteInterfaceClass = requiredClass[java.rmi.Remote]
Am I wrong to think that this is a no-go for Scala reflection in Android?
If I am, what could be a workaround to this problem?
To summarize your solution and a related solution, it is sufficient to add two files, and modify build.sbt to include:
dexAdditionalParams in Android += "--core-library"
Add java/rmi/Remote.java to your project with the content:
package java.rmi;
public interface Remote {}
Add java/rmi/RemoteException.java to your project with the content:
package java.rmi;
public interface RemoteException {}
i am working on one of C++ Application, where i need to interface with Android Source Code, i got this Source Code from below URL
https://github.com/android
Now When i am Compiling my application which uses Camera module, then it has many dependencies like utils,binder,gui,system. by this way i am including every header files which camera module of Android depends depends on.
but i am stuck with following error:
In file included from jni/headers/camera/ICamera.h:22:0,
from jni/headers/MyCamera.h:4,
from jni/headers/VideoWrapper.h:4,
from jni/src/com_example_jnitest_VideoJava.cpp:2
jni/headers/binder/Parcel.h:31:7: error: template argument
required for 'class Flattenable'
class Flattenable;
^
jni/headers/binder/Parcel.h:105:37: error: invalid use of
template-name 'android::Flattenable' without an argument list
status_t write(const Flattenable& val);
^
jni/headers/binder/Parcel.h:160:30: error: 'Flattenable' is not a type
status_t read(F
my Question is:How to get out of this error??
Whenever Any class Template need to be pre-declaration in another class or Anywhere then we need to give it with template
e.g:
in Parcel.h file of Android source, pre-declaration of class Flattenable is done as below:
class Flattenable;
but actually it should be:
template <typename T> class Flattenable;
because class Flattenable is Template class.
However i Amazed how this things not taken care into Android Source Code..!!