Error when binding an .AAR in Xamarin.Android - android

i'm trying to bind the core library: https://github.com/gabrielemariotti/cardslib
I downloaded the .AAR file from Maven Central and did everything in this tutorial Binding an .AAR, but when i'm building the Binding Library i'm getting this errors:
'CardExpandableListAdapter' does not implement inherited abstract member 'BaseExpandableListAdapter.GetGroup(int)'
Inconsistent accessibility: return type 'CardWithList.LinearListAdapter' is less accessible than method 'CardWithList.GetLinearListAdapter()'
Inconsistent accessibility: parameter type 'CardWithList.LinearListAdapter' is less accessible than method 'CardWithList.SetLinearListAdapter(CardWithList.LinearListAdapter)'
Inconsistent accessibility: property type 'CardWithList.LinearListAdapter' is less accessible than property 'LinearListView.Adapter'
'CardView' does not implement interface member 'ICardViewWrapper.SetExpanded(bool)'
'CardView' does not implement interface member 'ICardViewWrapper.SetForceReplaceInnerLayout(bool)'
'CardView' does not implement interface member 'ICardViewWrapper.SetLongClickable(bool)'
'CardView' does not implement interface member 'ICardViewWrapper.SetOnExpandListAnimatorListener(ICardViewWrapperOnExpandListAnimatorListener)'
'CardView' does not implement interface member 'ICardViewWrapper.SetRecycle(bool)'
It looks like the binding generator has some bugs, is there any fix for this?
Thanks in advance.

From Xamarin's page,
When you are generating Java Bindings, there are several common error scenarios that you may run into.
Here is the link to possible errors you might run into and how to resolve them.
Link for how to fix "Interface does not implement method"
Inconsistent accessibility issue can be resolved by changing the visibility accordingly. Here is an example of how to modify visibility
<attr path="/api/package[#name='com.somepackage']/class[#name='SomeClass']" name="visibility">public</attr>

Related

Package Level Protection in Kotlin [duplicate]

In Java, we have the package protected (default) modifier for classes, which allows us to have many classes in a single package but exposes only a few and keeps the logic encapsulated.
With Kotlin this doesn't seem to be the case. If I want a few classes to be visible to each other but no further, I have to use a private modifier which limits visibility to a single file.
So if you want 10 classes in a package but only one of them to be public, you'd have to have one huge file with all the classes in it (and private all over the place).
Is this normal practice or there is a way to achieve some similar modularity in Kotlin?
I don't understand: if they have the notion of a package, why did they get rid of package protected access?
Update: We might have package protected visibility after all
see the discussion here
Update: If you read through the discussion and still think this is a must-have feature for the language, please vote here
Kotlin, compared to Java, seems to rely on packages model to a lesser degree (e.g. directories structure is not bound to packages). Instead, Kotlin offers internal visibility, which is designed for modular project architecture. Using it, you can encapsulate a part of your code inside a separate module.
So, on top level declarations you can use
private to restrict visibility to the file
internal to restrict visibility to the module
At this point, there is no other option for visibility restriction.
As a workaround for me on android I've created #PackagePrivate annotation and lint checks to control access. Here you can find the project.
Lint checks are obviously not that strict as compiler checks and some setup needed to fail the build on errors. But android studio picks up lint checks automatically and shows error immediately while typing. Unfortunately I don't know a way to exclude annotated members from autocomplete.
Also, as lint is a purely compile-time tool, no checks at runtime performed.
As #hotkeys points out, you can use the internal keyword in a module or you can put all classes that would otherwise belong in a package inside a single file, but sticking several classes in a file may be a questionable design decision.
For me, the package visibility is helpful for its documenting value. I want to know what public interface some package is presenting to the rest of the project, hide factory implementation classes and so on.
So even if it's possible to access package-private classes and methods in Java, I still choose to use the package modifier.
For this I created a project with a single annotation:
package com.mycompany.libraries.kotlinannotations;
import static java.lang.annotation.ElementType.CONSTRUCTOR;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.SOURCE;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
#Documented
#Retention(SOURCE)
#Target({ TYPE, METHOD, CONSTRUCTOR })
/**
* Use in Kotlin code for documentation purposes.
*
* Whenever a Kotlin class or method is intended to be accesible at package level only.
*
*/
public #interface PackagePrivate {
}
Then I can use this annotation in any Kotlin project.
The second step, which I haven't done yet, is creating a PMD rule to enforce this with maven (or any other build tool for that matter) and also be able to see violations of the rule in my IDE with the pmd plugin.
There no is full Kotlin support in pmd at this moment but it seems to be expected at some point.
A near-replacement for package private visibility is available using the opt-in requirements feature (credit to pdvrieze on Kotlin discussions). This is the annotation syntax typically used to flag experimental features in an API.
To use it, create an annotation denoting package private declarations:
#RequiresOptIn(message = "Only to be used in MyPackage")
#Retention(AnnotationRetention.BINARY)
annotation class MyPackagePrivate
Then annotate any methods you want to be package private with it:
#MyPackagePrivate
fun aPackagePrivateMethod() {
// do something private within a package
}
In this way a warning will be generated on any method that calls the annotated method unless the calling method is itself annotated with the corresponding #OptIn annotation, here shown at class level:
#OptIn(MyPackagePrivate::class)
class AClassInThePackage {
fun userOfPackagePrivateMethod() {
aPackagePrivateMethod()
}
}
This, then, produces a similar effect to Java's package private, except that calling methods need to explicitly opt in to using a package private declaration.
If it is desired to generate an error rather than a warning, the level parameter of #RequiresOptIn can be specified:
#RequiresOptIn(level = RequiresOptIn.Level.ERROR, message = "Only to be used in MyPackage")
// annotation declaration as before
Package-based protection is pointless in Kotlin because packages themselves are unprotected
In Java, package was tied to directory structure. So if you put your classes in com\example\yoursecretengine, any attempt (deliberate or accidental) to add a rogue class there would be easily noticeable. This is the kind of security we've depended on.
Kotlin removes the ties between directory and package, so I can put my class in "my" directory (eg.src\java\pl\agent_l\illegalaccess) yet declare its package as com.example.yoursecretengine - and gain access to all the properties you've meant as package private.
In fact, a Kotlin project works perfectly without ANY package declarations. This only highlights that packages are "more what you'd call guidelines than actual rules". They're a convenience feature, useful only to unclutter namespace and nothing more.
Relevant quotes from kotlinlang:
unlike many other languages, Kotlin packages do not require files to have any specific locations w.r.t. itself; the connection between a file and its package is established only via a package header.
And:
an absence of a package header in a file means it belongs to the special root package.

Kotshi issue - unresolved reference for KotshiApplicationJsonAdapterFactory

So I'm trying to follow the simple read.me for Kotshi and get it set up for my project but I seem to be hitting a little snag.
I'm currently at this portion of the read.me
#KotshiJsonAdapterFactory
object ApplicationJsonAdapterFactory: KotshiApplicationJsonAdapterFactory()
but KotshiApplicationJsonAdapterFactory seems to give me an unresolved reference error. Now this sounds like an absolutely silly question but is KotshiApplicationJsonAdapterFactory supposed to be a custom class that I set up? If so I don't see anywhere in the documentation regarding it. My gradle has the two dependencies added so I'm absolutely baffled.
#KotshiJsonAdapterFactory makes Kotshi generate a JsonAdapter factory.
Should be placed on an abstract class that implements
JsonAdapter.Factory.
So yes, KotshiApplicationJsonAdapterFactory is a custom class that you've to setup and which fulfills the above condition.
KotshiJsonAdapterFactory is an annotation that you apply to a class that you write. This will make Kotshi generate a class with the same name as your class + the Kotshi prefix. That class will implement the actual factory.
When you write your class it will look like you have a compile error, but it will not prevent compilation.

Android (Xamarin) binding project for Android Studio library

I'm trying to use an external library from android into my Xamarin.Android application, but am facing quite a few issues.
The external library I require is a Calendar library. After looking at Xamarin Component's limited collection of Calendar library, I was unable to find one that suits the needs of my application. I then read up on using Android Studio's external libraries, using this Xamarin tutorial and this youtube tutorial.
However, of the two libraries I've tried -
Material Calendar View
Caldroid
both were not able to build.
Here is the error list when I try to build Material Calendar View:
The type or namespace name 'CalendarPagerView' does not exist in the namespace 'Com.Prolificinteractive.Materialcalendarview' (are you missing an assembly reference?)
'WeekView.ThresholdClass': no suitable method found to override
'WeekView.ThresholdType': no suitable method found to override
'WeekView.Rows': no suitable method found to override
'WeekView.BuildDayViews(ICollection<DayView>, Calendar)': no suitable method found to override
The type or namespace name 'DayView' does not exist in the namespace 'Com.Prolificinteractive.Materialcalendarview' (are you missing an assembly reference?)
'WeekView.IsDayEnabled(CalendarDay)': no suitable method found to override
'WeekView.OnClick(View)': no suitable method found to override
'WeekView.OnInitializeAccessibilityEvent(AccessibilityEvent)': no suitable method found to override
'WeekView.OnInitializeAccessibilityNodeInfo(AccessibilityNodeInfo)': no suitable method found to override
'WeekView.SetDateTextAppearance(int)': no suitable method found to override
'WeekView.SetDayFormatter(IDayFormatter)': no suitable method found to override
'WeekView.SetMaximumDate(CalendarDay)': no suitable method found to override
'WeekView.SetMinimumDate(CalendarDay)': no suitable method found to override
'WeekView.SetSelectedDates(ICollection)': no suitable method found to override
'WeekView.SetSelectionColor(int)': no suitable method found to override
'WeekView.SetSelectionEnabled(bool)': no suitable method found to override
'WeekView.SetShowOtherDates(int)': no suitable method found to override
'WeekView.SetWeekDayFormatter(IWeekDayFormatter)': no suitable method found to override
'WeekView.SetWeekDayTextAppearance(int)': no suitable method found to override
'WeekView.ShouldDelayChildPressedState()': no suitable method found to override
'IExperimentalInvoker.Equals(Object)' hides inherited member 'Object.Equals(Object)'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword.
'IExperimentalInvoker.GetHashCode()' hides inherited member 'Object.GetHashCode()'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword.
'IExperimentalInvoker.ToString()' hides inherited member 'Object.ToString()'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword.
The member 'WeekView.java_class_handle' does not hide an inherited member. The new keyword is not required.
The member 'WeekView.class_ref' does not hide an inherited member. The new keyword is not required.
Error encountered while loading the project. Some project features, such as full solution analysis for the failed project and projects that depend on it, have been disabled.
top ancestor WeekPagerAdapter not found for nested type Com.Prolificinteractive.Materialcalendarview.WeekPagerAdapter.Weekly.
top ancestor MaterialCalendarView not found for nested type Com.Prolificinteractive.Materialcalendarview.MaterialCalendarView.IShowOtherDates.
top ancestor MaterialCalendarView not found for nested type Com.Prolificinteractive.Materialcalendarview.MaterialCalendarView.SavedState.1.
top ancestor MaterialCalendarView not found for nested type Com.Prolificinteractive.Materialcalendarview.MaterialCalendarView.4.
top ancestor MaterialCalendarView not found for nested type Com.Prolificinteractive.Materialcalendarview.MaterialCalendarView.ISelectionMode.
top ancestor MonthPagerAdapter not found for nested type Com.Prolificinteractive.Materialcalendarview.MonthPagerAdapter.Monthly.
top ancestor MaterialCalendarView not found for nested type Com.Prolificinteractive.Materialcalendarview.MaterialCalendarView.LayoutParams.
Unknown parameter type com.prolificinteractive.materialcalendarview.MaterialCalendarView in method OnRangeSelected in managed type Com.Prolificinteractive.Materialcalendarview.IOnRangeSelectedListener.
Invalid return type com.prolificinteractive.materialcalendarview.CalendarPagerView.LayoutParams in method GenerateLayoutParams in managed type Com.Prolificinteractive.Materialcalendarview.WeekView.
Invalidating Com.Prolificinteractive.Materialcalendarview.IOnRangeSelectedListener and all nested types because some of its methods were invalid.
top ancestor MaterialCalendarView not found for nested type Com.Prolificinteractive.Materialcalendarview.MaterialCalendarView.SavedState.
Unknown parameter type com.prolificinteractive.materialcalendarview.MaterialCalendarView in method OnDateSelected in managed type Com.Prolificinteractive.Materialcalendarview.IOnDateSelectedListener.
top ancestor MaterialCalendarView not found for nested type Com.Prolificinteractive.Materialcalendarview.MaterialCalendarView.1.
For StateBuilder, could not find enclosing type 'MaterialCalendarView'.
Unknown parameter type com.prolificinteractive.materialcalendarview.MaterialCalendarView in method OnMonthChanged in managed type Com.Prolificinteractive.Materialcalendarview.IOnMonthChangedListener.
Invalidating Com.Prolificinteractive.Materialcalendarview.IOnDateSelectedListener and all nested types because some of its methods were invalid.
Unknown parameter type com.prolificinteractive.materialcalendarview.MaterialCalendarView in method CalendarPagerView in managed type Com.Prolificinteractive.Materialcalendarview.CalendarPagerView.
top ancestor MaterialCalendarView not found for nested type Com.Prolificinteractive.Materialcalendarview.MaterialCalendarView.State.
Invalidating Com.Prolificinteractive.Materialcalendarview.IOnMonthChangedListener and all nested types because some of its methods were invalid.
top ancestor MaterialCalendarView not found for nested type Com.Prolificinteractive.Materialcalendarview.MaterialCalendarView.StateBuilder.
Unknown parameter type com.prolificinteractive.materialcalendarview.MaterialCalendarView in method WeekView in managed type Com.Prolificinteractive.Materialcalendarview.WeekView.
ignoring option UseSplitVerifier; support was removed in 8.0
missing class error was raised while reflecting com.prolificinteractive.materialcalendarview.MaterialCalendarView : android/support/v4/view/ViewPager$OnPageChangeListener
Couldn't load class com/prolificinteractive/materialcalendarview/MonthPagerAdapter : java.lang.NoClassDefFoundError: android/support/v4/view/PagerAdapter
Couldn't load class com/prolificinteractive/materialcalendarview/CalendarPager : java.lang.NoClassDefFoundError: android/support/v4/view/ViewPager
Couldn't load class com/prolificinteractive/materialcalendarview/MaterialCalendarView$3 : java.lang.NoClassDefFoundError: android/support/v4/view/ViewPager$PageTransformer
Couldn't load class com/prolificinteractive/materialcalendarview/CalendarPagerAdapter : java.lang.NoClassDefFoundError: android/support/v4/view/PagerAdapter
Couldn't load class com/prolificinteractive/materialcalendarview/MaterialCalendarView$2 : java.lang.NoClassDefFoundError: android/support/v4/view/ViewPager$OnPageChangeListener
Couldn't load class android/support/v4/view/BetterViewPager : java.lang.NoClassDefFoundError: android/support/v4/view/ViewPager
Couldn't load class com/prolificinteractive/materialcalendarview/WeekPagerAdapter : java.lang.NoClassDefFoundError: android/support/v4/view/PagerAdapter
Caldroid also produces a similar error list.
I have tried directly using existing Xamarin libraries for the library, such as the one from this question but also had similar build problems, which led me to believe I was probably doing something obviously wrong, but I can't figure it out.
As I'm rather new to Android development, a step-by-step guide to bind this exact library would help me out a lot.
---Update---
After building the library and adding it as a reference in my project, viewing the library in the object browser shows that it is empty.
Missing members and error:
In your project solution, you could choose Add Existing Project, add a MaterialCalendarLibrary from Xamarin.MaterialCalendarView project.
Then you could follow this Xamarin tutorial, to use the material-calendarview. All works fine and if I found a better solution I will come back and update this answer.
Effect like this.
EDIT :
Its object browser.

Is there a way to bind to the ExceptionManagerModule similar to RCTExceptionManager?

In React Native you can bind a delegate to RCTExceptionManager on the iOS side to catch errors and handle them yourself (like this).
However, looking into Android the ExceptionManagerModule only takes in a DevSupportManager and seems to be instantiated inside the CoreModulesPackage. I tried instantiating the module a second time using a DevSupportManager subclass, but you cannot instantiate the same module more than once.
Is there any way to add a custom error handler on the native Android side?
It is possible to override core modules if the getName() return the same as the core module and if canOverrideExistingModule() returns true.
You can see an example of that on the library that I did to support Crashlytics https://github.com/aoriani/ReactNative-StackTracer/blob/master/rnstacktracer/src/main/java/com/github/aoriani/rnstacktracer/StackTraceManagerModule.java

Android ActivityMontior with XTend

I am trying to write an Android app using Xtend, however, I am more or less new in both. I have created a couple of Android examples with Java, but I'm still learning.
In these apps i used the android.app.Instrumentation.ActivityMonitor
in order to check that an Activity had started.
I have read that Xtend does not support Nested classes
No var args, no nested classes, no anonymous classes?
Those language features are not mentioned in the docs, and I could not guess a valid syntax. >I assume they are not available, but I could be wrong.
http://blogs.atlassian.com/2011/11/xtend-first-impressions/
Does this mean the ActivityMonitor cannot be accessed when using Xtend or am I just doing something wrong?
It depends how you used the ActivityMonitor. You cannot define inner classes on your own right now, but static inner classes can be accessed from within Xtend. There are issues with non-static inner classes. The syntax is different to Java, though. Instead of the '.' dot as the delimiter of declaring class and inner class, Xtend uses the '$'. A respective import declaration can ease the pain, here, e.g. import android.app.Instrumentation$ActivityMonitor.

Categories

Resources