让 SignalR 在 Android Studio 中工作的步骤 [英] Steps to get SignalR working in Android Studio

查看:26
本文介绍了让 SignalR 在 Android Studio 中工作的步骤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 SignalR 引入我的 Android Studio 项目.

I'm trying to bring SignalR into my Android Studio project.

我成功地遵循了SignalR入门,所以现在我有一个可用的 Hub.该教程中的客户端是 javascript,我让它在 PC 上的网页(Chrome 浏览器)和我的 Android 手机上通过家庭局域网上的 WiFi 正常工作.

I successfully followed the tutorial on getting started with SignalR, so now I have a working Hub. The client in that tutorial is javascript, and I got it working ok in a web page (in Chrome) on PC AND on my Android phone over WiFi on my home LAN.

然后我去让 Android java 客户端工作.我已经在 Android Studio 中创建了一个 Android 应用项目,我想在下一步中将其与正在运行的 Hub 作为测试进行对话.

Then I went to go get the Android java client working. I already had an Android app project in Android Studio, which I want to make talk to that working Hub as a test, as the next step.

我下载了微软官方 Android 的 java 客户端,压缩包.

I downloaded the official Microsoft java client for Android, as a zip.

然后我将其提取并作为项目加载到 Android Studio 中.它构建时没有错误.

Then I extracted it and loaded it as a project into Android Studio. It builds with no errors.

问题 #1:这个项目只给了我一个 AAR,而不是一个 JAR.我已经弄清楚如何在 Android Studio 中使用 jar,所以如果此时有办法创建一个 jar,我可能可以完成这项工作.

Problem #1: This project only gives me an AAR, not a JAR. I have figured out how to use a jar in Android Studio, so if there's a way to create a jar at this juncture, I can probably make this work.

此时我将依赖项包含到我的应用程序项目中.readme.md 说:

At this point I included the dependencies into my app project. The readme.md says to:

添加signalr-client-sdk.jar、signalr-client-sdk-android.jar gson库作为项目的 gradle 依赖项.

Add the signalr-client-sdk.jar, signalr-client-sdk-android.jar gson library as a gradle dependency to the project.

所以我试图尽可能地遵循它.这是我的 build.gradle:

so I tried to follow that as closely as possible. Here's from my build.gradle:

compile 'com.google.code.gson:gson:2.3.1'
compile files('libs/signalr-client-sdk.jar')
compile files('libs/signalr-client-sdk-android-release.aar')

问题#2:在将 aar 作为模块导入到我在 Android Studio 中的应用项目中后,它仍然没有看到使主要语句起作用所需的命名空间.这是主要语句(Android 中 SignalR 的 hello world,编译器方面):

Problem #2: Having imported the aar as a module into my app project in Android Studio, it still does not see the necessary namespace to make the primary statement work. Here is the primary statement (the hello world of SignalR in Android, compiler-wise):

Platform.loadPlatformComponent(new AndroidPlatformComponent());

起初它什么也没有,然后它为Platform选择了import microsoft.aspnet.signalr.client.Platform;.它仍然不知道要为 AndroidPlatformComponent import 做什么,所以我被卡住了,直到我能通过这个.

At first it wasn't picking up anything, then it picked up import microsoft.aspnet.signalr.client.Platform; for Platform. It still does not have a clue what to import for AndroidPlatformComponent, so I'm stuck until I can get past this.

如您所知,Android Studio 中有很多文件,我不想在知道您要查看哪些文件之前将它们全部吐出来.如果您告诉我您想查看哪些文件,我会将它们添加为编辑.

As you know there are a lot of files in Android Studio, and I don't want to just spew them all out here before I know which files you want to see. I'll add them as an edit if you tell me which files you want to see.

推荐答案

你可以从这里下载 jar 文件 链接

Well you can download the jar files from this link

第一步

在您的包中创建一个 libs 文件夹,然后将这些 jar 文件粘贴到此处即可.

Create a libs folder inside your package and simply paste these jar files here.

第 2 步

现在在 build.gradle 的依赖项中添加编译文件"

Now add "compile files" inside dependencies of build.gradle

现在按下Sync Project with Gradle file"

Now after this press "Sync Project with Gradle file"

步骤 3

即使在成功同步和导入 jar 之后,您仍然面临一些导入错误等.现在尝试使缓存无效并重新启动.几次后它会很好并导入所有类

Even after syncing and importing jar successfully you still face some import errors etc. Now try Invalidate cache and restart.After couple of times it will be fine and imports all the classes

步骤 4

现在您将看到 Platform.loadPlatformComponent() 的导入;没有任何问题

Now you will see the imports for Platform.loadPlatformComponent(); without any problems

这篇关于让 SignalR 在 Android Studio 中工作的步骤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆