【问题标题】:java.lang.NoClassDefFoundError: com/google/api/core/ApiFuturejava.lang.NoClassDefFoundError: com/google/api/core/ApiFuture
【发布时间】:2019-10-07 05:03:43
【问题描述】:

我已成功将 firebase 管理员添加到我的 kotlin jvm 后端代码中,并且可以成功发送推送通知:

object FirebaseUtils {
init {

    val credentials = GoogleCredentials.fromStream(Gson().toJson(FIREBASECREDIENTIALS).byteInputStream())
    val options = FirebaseOptions.Builder()
        .setCredentials(credentials)
        .setDatabaseUrl("url")
        .build()

    FirebaseApp.initializeApp(options)
}

fun sendPushNotification(registrationToken:String,notificationTitle:String,notificationMessage:String){
    val messageBuilder = Message.builder()
        .setNotification(Notification(notificationTitle,notificationMessage))
        .setToken(registrationToken)
    val message = messageBuilder.build()
    // Send a message to the device corresponding to the provided
// registration token.
    val response = FirebaseMessaging.getInstance().send(message)
// Response is a message ID string.
    println("Successfully sent message: $response")

}}

发送:

  FirebaseUtils.sendPushNotification(registrationToken, ,"testTitle","testMessage")

但是当我将它上传到 AWS Lamda 时,我每次调用它时都会收到这个异常

com/google/api/core/ApiFuture: java.lang.NoClassDefFoundError
java.lang.NoClassDefFoundError: com/google/api/core/ApiFuture
at utils.FirebaseUtils.<clinit>(FirebaseUtils.kt:29)
at lamdas.CourseManagerLambda.handleRequest(CourseManagerLambda.kt:57)

我尝试过导入com.google.api:api-common,但还是不行。

分级:

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
implementation "org.jetbrains.exposed:exposed:$exposed_version"
implementation "com.amazonaws:aws-lambda-java-core:$awsLambdaCoreVersion"
implementation "com.google.code.gson:gson:$gsonVersion"
implementation "com.microsoft.sqlserver:mssql-jdbc:$sqljwcVersion"
implementation 'org.slf4j:slf4j-nop:1.7.25'
implementation 'am.ik.yavi:yavi:0.2.3'
// Core dependency
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.1.1'
// Koin for Kotlin
implementation "org.koin:koin-core:$koin_version"
// Koin extended & experimental features
implementation "org.koin:koin-core-ext:$koin_version"
// Koin for Unit tests
testImplementation "org.koin:koin-test:$koin_version"
// Koin for Java developers
implementation "org.koin:koin-java:$koin_version"
testCompile group: 'junit', name: 'junit', version: '4.12'
implementation 'io.github.rybalkinsd:kohttp:0.11.0'
implementation 'com.google.firebase:firebase-admin:6.10.0'
implementation group: 'software.amazon.awssdk', name: 'bom', version: '2.5.29', ext: 'pom'
implementation group: 'software.amazon.awssdk', name: 'kinesis', version: '2.9.14'
implementation group: 'com.google.api', name: 'api-common', version: '1.8.1'
}

【问题讨论】:

    标签: kotlin google-api aws-lambda firebase-admin


    【解决方案1】:

    我正在构建像这样上传到 AWS 的 zip

    task buildDist(type: Zip) {
        appendix = "dist"
        from sourceSets.main.output
        from configurations.runtimeClasspath.findAll {
        it.name.endsWith("jar")
        }.collect {
            zipTree(it)
        }
    }
    

    由于某种原因,运行时缺少一些依赖项,所以我改用Shadow 来生成一个 Fat Jar,现在一切正常。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-05
      • 2020-11-24
      • 2015-08-02
      • 2012-06-01
      相关资源
      最近更新 更多