Can I use RxJava2 and RxAndroid in a single java class library? - rx-android

I'm tasked with creating an SDK that can be consumed from both Android & Java applications using ReactiveX programming. I already have an android project using RxAndroid created, but now I need to extend it with RxJava2.
The question I'm facing is whether I should create 'regular' java class library and use it for both scenarios or create 2 separate packages (which would mean a lot of duplicate code + maintenance).
Is this even possible? And if so, is it a good practice?

whether I should create 'regular' java class library and use it for both scenarios
Yes. What I would do to start is simply change your Android library project to be a standard Java library and replace RxAndroid dependency by RxJava. Most code should still compile. Code which doesn't will mostly use schedulers provided by RxAndroid and can be changed to take Scheduler parameters.
Then create an Android Library project which depends on the Java Library and put the RxAndroid-specific code there.

As an addition to #AlexeyRomanov's answer, feel free to check out this library which could be used for both Android and Java projects: https://github.com/JakeWharton/RxRelay.
Its basically an extension to RxJava, but it might give you a solid idea where to go. Good luck!

Related

How to use java libraries in ios project?(codenameone)

I need to connect native java libraries for use in the ios environment. In particular, it is necessary to use ready-made support for crypto libraries.
I tried using ikvm(.net core xamarin) for ios. but there is no support for mono-touch.
See this answer from the knowledge base.
You can't use an arbitrary JAR "as is". Please also check the maven dependency discussion in this post.
You can wrap libraries as cn1libs but a library might use arbitrary Java code which might be a problem, see this.

Using .NET Standard or Use Shared Library for a new Xamarin Forms application

When creating a new app in Xamarin Forms I see these two options:
Configure your Forms App
Shared Code:
Use .NET Standard
Use Shared Library
Can someone explain the difference? I looked at the help and I am still confused. I'd appreciate if someone can give me any advice on this. Not sure if it helps but this app is self contained and no code in the app will need to be shared with any other application.
In terms of what you can achieve with both, it is the same. So, in the end, it's mostly a matter of taste.
The biggest difference is that a shared project is compiled into the app itself. It is nothing more than it says on the tin: it's a shared folder that you can use in all platform projects. Using platform-specific code is done through compiler directives.
With a .NET Standard project, you will get a physical binary. It is a project of its own. You can reuse it in other .NET Standard projects, although you already mentioned you won't be using it for that. Executing platform-specific code requires a bit different approach, using the DependencyService.
Seeing that they made a choice to replace the PCL with .NET Standard but keep the shared project points out that the shared project is here to stay for a while. I tend to like the .NET Standard library more. It feels cleaner and forces you to write cleaner code. Also, .NET Standard isn't going anywhere soon and if you decide that code should be reused down the road, you have the ability to.
A good overview, together with pros and cons can be found in the Microsoft Docs: https://learn.microsoft.com/en-us/xamarin/cross-platform/app-fundamentals/code-sharing

EventHandlerList missing in PCL project but available on platform library projects (Android/iOS)

I have small problem - I'm trying to implement class that needs to contain a lot of events. Due to memory concerns I planned to implement EventHandlerList which is available for me in my Android Library project target also in my iOS Library project target but is not available for me inside PCL Project. Tried to change PCL Target project to most commonly used but none of them contained what i needed.
Type missing for my case :
System.ComponentModel.EventHandlerList
Is there any possibility to write such class once or I'm forced to write it two times because of missing PCL Target.
You will need Inversion Of Control (IoC) to use platform specific features or non-portable methods
Please take a look at this IoC example
Another option if you want to avoid IoC is to use Shared Project in Xamarin

How would one replace Processing IDE with Visual Studio 2015 Community?

I have been unable to find any information how would one replace Processing IDE with Visual Studio 2015 Community.
Is it even possible to replace it, if yes then how?
Processing is a couple of things:
A set of tools that convert "Processing code" into Java code, or JavaScript code with Processing.js.
An IDE that lets you write Processing code and use those tools.
A Java library (and JavaScript, for Processing.js) that is called by that converted code.
That third thing is what you care about. You can use Processing as a Java library the same way you can use any Java library. Here is a tutorial on using it from eclipse.
The steps to use it with Visual Studio will be similar: find the Processing library jar (probably called core.jar), add it to your classpath, and then write Java code that uses the classes from that library jar.
However, I will say that you should know what you're doing with both Java and Processing before trying this. Processing's IDE is designed to make things as simple as possible, so it hides a lot of behind-the-scenes stuff from you. You have to be comfortable with the idea of using an API, OOP, and setting up the classpath.
Also note that Processing 3 has changed a bunch of things, so certain aspects of that tutorial are out of date. Most notably, PApplet no longer extends Applet, so you can't treat it as a component anymore. You have to go through its Surface instead. If you have no idea what I'm talking about, it might be a better idea to stick with Processing's included IDE.

Xamarin Shared Library and PCL

What is the exact difference between xamarin shared project and portable class library?
When to use shared library and when to use portable class library?
Is this possible to write native functionality in shared projects like showing alert,accessing camera and use it for both android and iOS?
Can anyone please explain me.
In shared projects each code file will be compiled for each destination (Android, iOS, Windows Phone etc). You are able to include platform specific code by using #if compiler directives.
When you want to access the camera you need to write the access code inside an #if block for all destinated platforms. This can mess up your code but it can be easier to find the different implementations.
Learn more: http://developer.xamarin.com/guides/cross-platform/application_fundamentals/shared_projects/
Protable Class Libraries (PCL) are compiled against a general .NET subset which is compatible to all platforms you want. So you can access System.Net.Http but you cannot access any platform specific code. If you want to access the camera inside the PCL code then you need to access it by a generalized interface via dependency injection. There are some pretty good frameworks helping you to archieve this goal. One of the most famous is MVVMCross (https://github.com/MvvmCross/MvvmCross/wiki). Learn more about PCL: http://developer.xamarin.com/guides/cross-platform/application_fundamentals/building_cross_platform_applications/sharing_code_options/#Portable_Class_Libraries
I personally perefer PCLs because the code is much easier to read without any compiler directives. Using MVVMCross you are able to use plenty of plugins via NuGet. So you don't need to write your own classes for camera access, showing alerts etc.

Resources