Steps to get SignalR working in Android Studio

前端 未结 3 1277
旧巷少年郎
旧巷少年郎 2020-12-02 14:44

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

I successfully followed the tutorial on getting started with SignalR,

3条回答
  •  不思量自难忘°
    2020-12-02 15:15

    I got this working with just Android Studio and the files from the GitHub project.

    Here's what I had to do, for posterity's sake.

    1. Extract the zip file from github
    2. Open the contents in Android Studio as a separate project, and Build. It produces:
      • signalr-client-sdk-android-debug.aar in java-client\signalr-client-sdk-android\build\outputs\aar
      • signalr-client-sdk.jar in java-client\signalr-client-sdk\build\libs
    3. Copy these 2 files into the libs folder of your app.
    4. Go into module's build.gradle and add:
    repositories {
        flatDir{
            dirs 'libs'
        }
    }
    dependencies {
        compile 'com.google.code.gson:gson:2.3.1'
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile(name: 'signalr-client-sdk-android-release', ext: 'aar')
    }
    
    1. Tools, Android, Sync Project with Gradle Files, and when that was successful I did a Build.

    2. Then finally, this line of code gave me the ALT+Enter prompt to generate the imports for this line of code:

    Platform.loadPlatformComponent(new AndroidPlatformComponent());
    

    which gave me:

    import microsoft.aspnet.signalr.client.Platform;
    import microsoft.aspnet.signalr.client.http.android.AndroidPlatformComponent;
    

    Whew!

提交回复
热议问题