My working Gradle build, for an Android project, started to not compile when using Apple Silicon (M1 Pro). The error it gives is the following:
Execution failed for task ':persistence-database:createDatabase'.
> java.sql.SQLException: Error opening connection
No native library is found for os.name=Mac and os.arch=aarch64. path=/org/sqlite/native/Mac/aarch64
I have my project set up similar to this guide and sample to prepopulate a Room database during the Gradle build.
For that, I am using a sqlite-jdbc driver to open an SQLite database to populate some data ahead of execution using a task. The connection is done like this:
private fun openSQL(dbFile: File, schemaFile: File, logger: Logger) =
Sql.newInstance("jdbc:sqlite:$dbFile", "org.sqlite.JDBC").apply {
...
}
}
With a quick Google search, I found that it seems that the underlying issue comes from an incompatibility from the xerial jdbc-sqlite driver used. They seemed to have added support in version 3.32.3.3. This was also fixed in Room in version 2.4.0-alpha03, which I am also using. What I don't understand is that even if updating to that version or newer (currently using the latest 3.36.0.3) still is giving me the same No native library is found error.
Any idea what it could be going on or what I am missing?
Thank you in advance!
CodePudding user response:
TLDR: use the x64 version of Java through Rosetta 2 to make jdbc-sqlite work on the M1 based macOS.
So... After trying everything, black magic included, it looks like the only way to solve it was to use a x86_64 build of Java to run this code. I still don't really understand the reason behind it but it's been the only consistent way of making this build.
For not compromising on speed, you can normally use the bundled java version for normal compilations and have the x86_64 Java as the default one in the terminal for using it when you see this error again. Hopefully they can fix this issue soon in the Java builds for ARM...
