如何将 StompProtocolAndroid 添加到 Android Studio gradle?

How to add StompProtocolAndroid to Android Studio gradle?

我是 java 及其构建脚本的新手。我已经有了一个 spring 引导消息服务 stompsockjs。我想从 android 应用发送和接收消息。我想将 https://github.com/NaikSoftware/StompProtocolAndroid 用于 stomp 客户端。不过我在设置时遇到了问题。

我按照那边描述的步骤操作,但有点过时了。那里链接的服务器示例 https://github.com/NaikSoftware/stomp-protocol-example-server 有一个 build.gradle 文件,而在我的 android 工作室中有两个文件,所以我有点困惑将它们的属性放在哪里。

我已经使用默认 build.gradle 文件清理了 android 工作室项目。它们看起来像这样:

第一个文件:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:7.0.4"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

第二个文件:

plugins {
    id 'com.android.application'
}

android {
    compileSdk 32

    defaultConfig {
        applicationId "com.example.chatapp"
        minSdk 21
        targetSdk 32
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    implementation 'androidx.appcompat:appcompat:1.4.0'
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
    implementation 'com.android.volley:volley:1.2.1'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}

并且我在 mavenCentral()

下的第一个文件中添加了 maven { url "https://jitpack.io" }

implementation 'com.github.NaikSoftware:StompProtocolAndroid:{latest version}'dependencies 范围内的第二个文件。

它与警告正确同步:Failed to resolve: com.githubAffected Modules: <a href="someLongPath/app/build.gradle">app</a>

但是当我构建时,我遇到了一大堆错误:

我试图打开它们的链接,但出现 returns“错误 404”,这意味着这些网站不存在。

我也用谷歌搜索了这个错误:Could not resolve all files for configuration ':app:debugRuntimeClasspath'.

我找到了一些“修复”,但它们对我不起作用,可能它们也已过时。

如何将此库添加到我的 android 应用程序中?

我发现我必须将 maven { url 'https://jitpack.io' } 放入 settings.gradle 文件中,而不是 top-level build 文件中,它现在可以工作了。