richardschneider / net-ipfs-http-client

InterPlanetary File System client for .Net (C#, VB, F# ...)
MIT License
158 stars 52 forks source link

Using the package in a Mono Android project #9

Closed richardschneider closed 6 years ago

richardschneider commented 7 years ago

When adding the Ipfs.Api package to a Xamarian project, NuGet complains

Could not install package 'SHA3 0.9.2'. You are trying to install this package into a project that targets 'MonoAndroid,Version=v7.0', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

richardschneider commented 7 years ago

It appears that NuGet is not using the Ipfs.Api .NET Standard 1.4 target, which doesn't depend upon SHA3.

A work-around is to add the package directly into packages.config and specify the target framework; e.g.

<package id="Ipfs.Api" version="0.9.1" targetFramework="netstandard14" />

Then run nuget restore

piravp commented 7 years ago

Does including this line alone solve it for you? Can you manage to build the project?

richardschneider commented 7 years ago

@piravp Yes, the project built for me. However, I couldn't get the emulator working, which is most likely another issue.

piravp commented 7 years ago

@richardschneider Can you show what's inside your package.config?

I'm getting this error when I add Ipfs.Api and Ipfs.Core manually and then try to build:

Severity    Code    Description Project File    Line    Suppression State
Error       Exception while loading assemblies: System.IO.FileNotFoundException: Could not load assembly 'Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'. Perhaps it doesn't exist in the Mono for Android profile?
File name: 'Newtonsoft.Json.dll'
   at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve(AssemblyNameReference reference, ReaderParameters parameters)
   at Xamarin.Android.Tasks.ResolveAssemblies.AddAssemblyReferences(DirectoryAssemblyResolver resolver, ICollection`1 assemblies, AssemblyDefinition assembly, Boolean topLevel)
   at Xamarin.Android.Tasks.ResolveAssemblies.Execute(DirectoryAssemblyResolver resolver)   TestIpfsOnAndroid           

It's complaining on dependencies that belong to Ipfs.Api/Ipfs.Core.

richardschneider commented 7 years ago

@piravp The above recommendations are wrong. The new Ipfs.Api 0.10.1 doesn't play games with optional packages. Just use Manage NuGet Packages to add it your project.

Sorry for leading you down the wrong road.

PS: Before following the above step, delete the reference to Ipfs.Api in package.config

PPS: I'm re-installing Xamarian on my machine. Once done, I'll update my fork of your code, so you can see how I do it.

piravp commented 7 years ago

@richardschneider The new version of Ipfs.Api seems to be working and letting me build.

I will get back to you after I've done some more testing.

richardschneider commented 7 years ago

Great to hear.

Please remember that IpfsClient expects to talk to a ipfs server. By default it expects it to be http://localhost:5001. On Android this will have to be something else.

piravp commented 7 years ago

Yes, I have IPFS running on the host computer and I'm trying to connect via an emulator. Usually when I'm running an emulator and have to communicate with a server on the host computer I usually do this:

λ ipfs daemon
Initializing daemon...
Swarm listening on /ip4/127.0.0.1/tcp/4001
Swarm listening on /ip4/169.254.122.173/tcp/4001
Swarm listening on /ip4/169.254.142.158/tcp/4001
Swarm listening on /ip4/169.254.187.37/tcp/4001
Swarm listening on /ip4/169.254.239.117/tcp/4001
Swarm listening on /ip4/192.168.1.2/tcp/4001
Swarm listening on /ip4/62.249.189.140/tcp/14051
Swarm listening on /ip6/::1/tcp/4001
API server listening on /ip4/127.0.0.1/tcp/5001
Gateway (readonly) server listening on /ip4/127.0.0.1/tcp/8080
Daemon is ready

IpfsClient client = new IpfsClient("http://10.0.2.2:5001"); (10.0.2.2 instead of localhost. The reason for this is stated here: https://stackoverflow.com/a/6310592/4534476)

However, when testing the connection with AddTextAsync(string), it's stuck on WaitingForActivation.

richardschneider commented 7 years ago

You are making more progress than I am. I still can't get the emulator working, cruft about Pixel Launcher!

With an Async method, either await it, e.g. asynchronous I/O, or use the Result property, e.g. synchronous I/O. See the unit tests for examples.

Asynchronous

var result = await ipfs.FileSystem.AddTextAsync("I am pinned");
var id = result.Hash;

Synchronous style

var result = ipfs.FileSystem.AddTextAsync("I am pinned").Result;
var id = result.Hash;
richardschneider commented 7 years ago

Ipfs.Api also uses Common.Logging to display debug/trace messages. Here's a blog on how to configure an app.

I really have no idea how it works on Android, specifically what is the console?

piravp commented 7 years ago

I really have no idea how it works on Android, specifically what is the console?

I'm not sure I understand what you mean by that, which console are you talking about?

richardschneider commented 6 years ago

@piravp is this still an issue? If so, please give an update or I will close this in a week.

mjeronimoa commented 6 years ago

@richardschneider have you been able to run any command on Android? I'm also stuck on this topic, not an exception at runtime when executing the commands, but not getting any response either. Here you can find some of the traces I get when I run the App.

04-19 16:28:29.166: D/Mono(1442): Assembly Loader probing location: '/storage/emulated/0/Android/data/com.mypackage.beta/files/.__override__/Ipfs.Api.dll'. 04-19 16:28:29.172: D/Mono(1442): Image addref Ipfs.Api[0xab842780] -> /storage/emulated/0/Android/data/com.mypackage.beta/files/.__override__/Ipfs.Api.dll[0xaae03e00]: 2 04-19 16:28:29.172: D/Mono(1442): Prepared to set up assembly 'Ipfs.Api' (/storage/emulated/0/Android/data/com.mypackage.beta/files/.__override__/Ipfs.Api.dll) 04-19 16:28:29.172: D/Mono(1442): Assembly Ipfs.Api[0xab842780] added to domain RootDomain, ref_count=1 04-19 16:28:29.180: D/Mono(1442): AOT: image '/storage/emulated/0/Android/data/com.mypackage.beta/files/.__override__/Ipfs.Api.dll.so' not found: dlopen failed: library "/data/app/com.mypackage.beta-1/lib/x86/libaot-Ipfs.Api.dll.so" not found 04-19 16:28:29.180: D/Mono(1442): AOT: image '/usr/local/lib/mono/aot-cache/x86/Ipfs.Api.dll.so' not found: dlopen failed: library "/data/app/com.mypackage.beta-1/lib/x86/libaot-Ipfs.Api.dll.so" not found 04-19 16:28:29.180: D/Mono(1442): Assembly Loader loaded assembly from location: '/storage/emulated/0/Android/data/com.mypackage.beta/files/.__override__/Ipfs.Api.dll'. 04-19 16:28:29.180: D/Mono(1442): Config attempting to parse: '/storage/emulated/0/Android/data/com.mypackage.beta/files/.__override__/Ipfs.Api.dll.config'. 04-19 16:28:29.185: D/Mono(1442): Config attempting to parse: '/usr/local/etc/mono/assemblies/Ipfs.Api/Ipfs.Api.config'. 04-19 16:28:29.185: D/Mono(1442): Assembly Loader probing location: '/storage/emulated/0/Android/data/com.mypackage.beta/files/.__override__/Ipfs.Core.dll'. 04-19 16:28:29.185: D/Mono(1442): Image addref Ipfs.Core[0xab8427e0] -> /storage/emulated/0/Android/data/com.mypackage.beta/files/.__override__/Ipfs.Core.dll[0xaae04300]: 2 04-19 16:28:29.185: D/Mono(1442): Prepared to set up assembly 'Ipfs.Core' (/storage/emulated/0/Android/data/com.mypackage.beta/files/.__override__/Ipfs.Core.dll) 04-19 16:28:29.185: D/Mono(1442): Assembly Ipfs.Core[0xab8427e0] added to domain RootDomain, ref_count=1 04-19 16:28:29.186: D/Mono(1442): AOT: image '/storage/emulated/0/Android/data/com.mypackage.beta/files/.__override__/Ipfs.Core.dll.so' not found: dlopen failed: library "/data/app/com.mypackage.beta-1/lib/x86/libaot-Ipfs.Core.dll.so" not found 04-19 16:28:29.186: D/Mono(1442): AOT: image '/usr/local/lib/mono/aot-cache/x86/Ipfs.Core.dll.so' not found: dlopen failed: library "/data/app/com.mypackage.beta-1/lib/x86/libaot-Ipfs.Core.dll.so" not found 04-19 16:28:29.186: D/Mono(1442): Assembly Loader loaded assembly from location: '/storage/emulated/0/Android/data/com.mypackage.beta/files/.__override__/Ipfs.Core.dll'. 04-19 16:28:29.186: D/Mono(1442): Config attempting to parse: '/storage/emulated/0/Android/data/com.mypackage.beta/files/.__override__/Ipfs.Core.dll.config'. 04-19 16:28:29.187: D/Mono(1442): Config attempting to parse: '/usr/local/etc/mono/assemblies/Ipfs.Core/Ipfs.Core.config'.

Please, tell me if you can think about any topic I can help you with if you are still at the same point.

piravp commented 6 years ago

@richardschneider I apologize for the late answer, I haven't had the time to explore this yet. I will try to get back to you within a few days. Feel free to close the issue otherwise.