kotlin - java.lang.NoClassDefFoundError : com/google/api/core/ApiFuture

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

我已成功将 firebase admin 添加到我的 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 但仍然不起作用。

Gradle :

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'
}

最佳答案

我正在构建上传到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,现在一切正常。

关于kotlin - java.lang.NoClassDefFoundError : com/google/api/core/ApiFuture,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58263749/

相关文章:

kotlin - 在Lambda中调用函数与函数引用之间的区别

gradle - 从 gradle 任务运行 kotlin 应用程序的正确方法

android - Mockito 2 for Android Instrumentation 测试 : Could not initialize plugin: interface org. mockito.plugins.MockMaker

google-api - YouTube(Google)批准的范围/权限列表

php - Google Glass PHP 快速入门项目不断要求离线访问

aws-lambda - Cognito - 如何让用户同时使用电子邮件和电话号码登录

javascript - 如何保护 AWS Lambda 函数?

kotlin - 以 Kotlin 方式获取包含在字符串中的子字符串的索引

java - 仅从 Gmail 获取邮件 header

python - 我是否正确地从默认代码迁移到测试代码?