Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: KSP apoption does not match \S+=\S+: room.schemaLocation #604

Closed
3 tasks done
rafsanahmad opened this issue Feb 19, 2023 · 7 comments
Closed
3 tasks done

[Bug]: KSP apoption does not match \S+=\S+: room.schemaLocation #604

rafsanahmad opened this issue Feb 19, 2023 · 7 comments
Labels
bug Something isn't working

Comments

@rafsanahmad
Copy link

rafsanahmad commented Feb 19, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Is there a StackOverflow question about this issue?

  • I have searched StackOverflow

What happened?

While running the project on SImulator or Real device, it is showing error.

Android Studio Electric Eel | 2022.1.1 Patch 1
OS: Mac Ventura 13.2.1

FAILURE: Build failed with an exception.

  • What went wrong:

Configuration cache state could not be cached: field __options__ of task :core:database:kspDemoDebugKotlin of type com.google.devtools.ksp.gradle.KspTaskJvm: error writing value of type 'org.gradle.api.internal.provider.DefaultListProperty'

KSP apoption does not match \S+=\S+: room.schemaLocation=YOUR_PROJECT_DIR/nowinandroid/core/database/schemas

The problem arises from NiaDatabase.kt -> exportSchema is set to true. Room generate Database script and save them as JSON file in your local directory.

AndroidRoomConventionPlugin.kt -> Configures room schema location to export scheme using com.google.devtools.ksp. This plugin is used in build.gradle.kts (Module :core:database)

Line causing the error:

override fun asArguments() = listOf("room.schemaLocation=${schemaDir.path}")

If your project is within a folder that has space in its name, like mine, the Regex is failing as \S+=\S+ does not match in KSP.

Setting exportSchema = false also does not solve the problem. If you give a path in your schemaDir which does not contain space, build completes successfully.

can you suggest a proper solution, so it does not depend on whitespace in your schemaDIr.

Relevant logcat output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@rafsanahmad rafsanahmad added the bug Something isn't working label Feb 19, 2023
@SimonMarquis
Copy link
Contributor

This seems like a bug in KSP where "spaces" chars (\s in regex) are not supported as arguments. Also, spaces in path are notoriously prone to error in build tools, so my best advice it for you to try moving the project code in a path without spaces.

@SimonMarquis
Copy link
Contributor

SimonMarquis commented Feb 24, 2023

Here is the corresponding error thrown by KSP:

https://github.com/google/ksp/blob/f3043917af405590e9c8d9422047fb1e3aedfe6e/gradle-plugin/src/main/kotlin/com/google/devtools/ksp/gradle/KspSubplugin.kt#L161-L163

We could try to escape spaces with something like, but I'm not sure it's worthy:

-        override fun asArguments() = listOf("room.schemaLocation=${schemaDir.path}")
+        override fun asArguments() = listOf("room.schemaLocation=${schemaDir.path.replace(" ", "\\ ")}")

@SimonMarquis
Copy link
Contributor

Or maybe something even simpler:

-        override fun asArguments() = listOf("room.schemaLocation=${schemaDir.path}")
+        override fun asArguments() = listOf("room.schemaLocation=\"${schemaDir.path}\"")

Could you try this on your local machine @rafsanahmad?

@rafsanahmad
Copy link
Author

rafsanahmad commented Feb 26, 2023

Thanks, @SimonMarquis for the suggestion.

I tried both of the above ways earlier before posting the issue. but still, it failed to build the project giving the same KSP adoption error.

For now, the solution seems to be: move the project to a directory that does not contain space in its path or give a pre-defined path directory without spaces.

override fun asArguments() = listOf("room.schemaLocation=YOUR_LOCAL_PATH_WITHOUT_SPACE")

@RivanParmar
Copy link
Contributor

I'm also getting the same error on Windows with Android Studio Electric Eel | 2022.1.1

@wamiikechukwu
Copy link

I had the same error - unfortunately the root directory for my pc had white space, so there was no way i could bypass this as @rafsanahmad had sugest.

What i did to solve this error:

  • Change exportSchema = false
  • Comment out the following
    autoMigrations = [ AutoMigration(from = 1, to = 2), AutoMigration(from = 2, to = 3, spec = DatabaseMigrations.Schema2to3::class), AutoMigration(from = 3, to = 4), AutoMigration(from = 4, to = 5), AutoMigration(from = 5, to = 6), AutoMigration(from = 6, to = 7), AutoMigration(from = 7, to = 8), AutoMigration(from = 8, to = 9), AutoMigration(from = 9, to = 10), AutoMigration(from = 10, to = 11, spec = DatabaseMigrations.Schema10to11::class), AutoMigration(from = 11, to = 12, spec = DatabaseMigrations.Schema11to12::class), ],

@SimonMarquis
Copy link
Contributor

SimonMarquis commented Aug 24, 2023

@rafsanahmad Since this issue is not direclty related to the project (and we can't fix it on our end), I think we can close it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants