Xamarin Forms fails to create an instance of DI container - android

Using Visual Studio 2017.
Created the default Xamarin Forms project (.net standard 2.0 + android). No changes in project configuration, Debug mode.
Compile -> Build -> Success (simple page with a standard text).
Added Unity/Autofac and created an instance of the container in App.
In Unity:
Object reference not set to an instance of an object
Similar in AutoFac
p.s. tried the approach to skip linking assembly System.Core
upd.1
This is absolutely standard solution with the only 1 line of code:
public App ()
{
InitializeComponent();
var c = new UnityContainer(); //this is the line for Unity
MainPage = new App2.MainPage();
}
The scenario with Autofac is similar. But it fails on RegisterType with exception Target of Add is null (NullReferenceException)
upd.2
This fails both in Release and Debug mode
This does not fail in simulator!
This fails during any kind of execution on phone directly (inculding Xamarin Live)

Related

TypeError: undefined is not an object (evaluating 'argv.indexOf')

I'm running a React Native app which has a local Node project as a dependency, managed through yalc. I'm using rn-nodeify to deal with the Node libraries.
Whenever I try using one of the methods/constants from my Node project, I get the above error during react-native start after the app is built (I'm using Intellij's default "Android" configuration to run RN and have an emulator in Android Studio).
I looked up the error message and people say it's related to supports-color, but neither of my projects use that library and installing it didn't fix it either.
Edit:
I'm not sure if this could be related, but I also have to add the lines
import { Buffer } from 'buffer';
import 'reflect-metadata';
global.Buffer = global.Buffer || Buffer
When I use this file from my Node project or I get errors regarding Reflect.hasOwnMetadata and Buffer

NUnit Test Project - Unable to create Xamarin MockContext - java-interop could not be found

I have an NUnit test project which works fine on its own until I start trying to bring Xamarin into the mix. Here is what my test looks like just to start:
[Test]
public void Test1()
{
//ARRANGE
var mockContext = new Android.Test.Mock.MockContext();
var textView = new Android.Widget.TextView(mockContext);
//ASSERT
var response = 1;
Assert.AreEqual(1, response);
}
This compiles fine, but when I run it, I get an error from the first line:
Message: System.DllNotFoundException : Unable to load DLL 'java-interop' or one of its dependencies: The specified module could not be found. (Exception from HRESULT: 0x8007007E)
I have verified that this reference java.interop is included in the project and also confirmed that the .dll is in the location on the drive that the reference is pointing to:
Is it just not possible to create instances of Xamarin objects in the NUnit test project?
I've seen this brought up numerous times from my research but the conclusion is usually along the lines of "Not sure if its possible, just avoid referencing Xamarin" Does anyone know for sure?

Testing inconvenience: Android Studio JUnit vs Gradle based: testOptions ignored by Android Studio

The following was done with Android Studio 3.4, Android Gradle Plugin 3.3.2 and Gradle 4.10.3.
In the build.gradle file, I have configured some unit test options like this:
android {
testOptions {
unitTests.all {
systemProperty "debug","true"
}
}
}
I do have a test function that tries to read this property:
package com.demo;
public class SysPropTestDemo {
#Test
public static void dumpSysProps() {
System.out.println("sysprop(debug)=" + System.getProperty("debug"));
}
}
When run via command line gradlew test --test com.demo.SysPropTestDemo I will get the property debug set correctly to true. If I run the same test via Android Studio without setting any options, the value shown will be null.
In order to get the same result from Android Studio, I explicitly have to enter some values in the "Run/Debug Configurations" panel, i.e something like -Ddebug=true in the VM options.
Now this is a trivial example, but what I really want to do, is to add some path to the java.library.path property in order to be able to load a JNI library compiled within the project. (I do need to write some tests that make use a modified SQLite lib, so not using JNI is not an option here)
It does work when setting additional options, but I think this is very inconvenient, since I can't enter a variable based value in the configuration options (or at least, I don't know how to). To sum it up: when setting or changing values, I do have to go through a bunch of config screens where I would really prefer to have one place in a config file.
Shouldn't Android Studio somehow make use of the values specified in the build.gradle file? If not, the docs don't make it clear that the testOptions.unitTests.all settings can only be used via gradlew invocation.
Skybow,
I feel you have two questions
1. How to load jni lib for androidTest(not for 'test[non instrumented unit tests])
- copy your jni library in corresponding folder [JNI libraries: [app/src/androidTestFLAVORNAMEDebug/jniLibs]
- load your jni library
static {
try {
System.loadLibrary("xyzjni");
} catch (Exception e) {
Logger.error("Exception on loading the jni library : " + e.getMessage());
}
}
2. How to make android studio use your config variables defined for unitTests.
- It would have great if some text file is there which has all configs.
- Or it is part of build.gradle
- I don't have any detail on this.

How to use an external sdk with Nativescript

I'm developping a NativeScript application and want to use the WonderPush SDK. I've already used this SDK into a native Android application, so I tried to create a new plugin to wrap the SDK.
I imported the library in the gradle file, and I tried to call the library from the NativeScript plugin. But the library is empty, if I tried to log it with console.dir, the only result is an quasi-empty object:
export class NativescriptWonderpush extends Common {
init() {
console.dir(com.wonderpush);
// com.wonderpush.sdk.Wonderpush.initialize(app.android.context);
}
}
JS: ==== object dump start ====
JS: sdk: {}
JS: ==== object dump end ====
(The second line com.wonderpush.sdk.Wonderpush.initialize() crash because com.wonderpush.sdk is empty)
Thanks for your help
Native objects may not always be traceable in console like JS objects.
Though you could refer their docs and call the methods you like Or even generate typings if you are using TypeeScript by following the steps given here. The typings ensure that the classes, methods, properties etc., are public and accessible to the JS runtime.

Windows Universal app with Android binding error

I have created a simple universal app targeting Windows Phone 8.1 & Windows 8.1 in Visual Studio 2013.
I added an android project and implemented MvvmLight.
ViewmodelLocator, viewmodels & messaging all work fine.
Databinding also works for the windows projects.
When I try adding databinding within the android project - at run time I get an error Property not found: Text
Button bindingButton = FindViewById<Button>(Resource.Id.button1);
var vm = ViewModelLocator.Main;
this.AddBinding(() => vm.AsyncCompleted,
() => bindingButton.Text,
BindingMode.TwoWay);
Has anyone else encountered this?
OK - solved it myself.
I was originally following an example from the mvvm light home page which doesn't seem to work with an Android project within a Universal App.
The answer is to specify the Actual control to add the binding to and pass the fully qualified View Model property to the binding:
Button bindingButton = FindViewById<Button>(Resource.Id.button1);
bindingButton.AddBinding(
() => ViewModelLocator.Main.AsyncCompleted,
() => bindingButton.Text,
BindingMode.OneWay);

Categories

Resources