Search code examples
androidkotlingoogle-drive-api

trying to create a file from android kotlin fails with: Java.lang.IllegalArgumentException: key error


this code used to work until a couple of days ago. it still works in the debug version, but not in the release anymore. no updates have been done to SDK or gradle.

the oauth apps are correctly set in google console, the correct SHA1 keys are entered.

now it just fails with:

Error during GoogleDriveManager.uploadFile operation: java.lang.IllegalArgumentException: key error

suspend fun uploadFile(credential: GoogleAccountCredential, file: File): Date? {
        return withContext(Dispatchers.Default) {
            try {
                val drive =  Drive.Builder(
                        NetHttpTransport(),
                        JacksonFactory.getDefaultInstance(),
                        credential
                )
                .setApplicationName(string(R.string.app_name))
                .build()

                val googleDriveFile = GoogleDriveFile()
                googleDriveFile.name = file.name

                val fileContent = FileContent("text/txt", file)

                drive.Files().create(googleDriveFile, fileContent).execute()

                Date()
            } catch (exception: Exception) {
                log {
                    "Error during GoogleDriveManager.uploadFile operation: ${exception}"
                }

                null
            }
        }
    }

Solution

  • finally got it working, i included the content of this file: proguard-google-api-client.txt and this line:

    -keep class com.google.api.services.drive.** { *; }
    

    thanks to on Dan Gerchcovich to pointing out the security issues by disabled obfuscations. while i knew them, i would have happily turn it off just to make it work :)