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

Viewed 368

I have successfully added firebase admin to my kotlin jvm backend code and i can successfully send push notification with this:

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")

}}

To send:

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

But when i uploaded this to an AWS Lamda i keep getting this exception every time i call it

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)

I've tried importing com.google.api:api-common but that still didn't work.

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

I was building the zip i uploaded to AWS like this

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

And for some reason some dependencies were missing at runtime so i switched to using Shadow to generate a Fat Jar and everything works fine now.

Related