141

I am using Android Studio [Android Studio Arctic Fox | 2020.3.1 Patch 1]

My room library version is [2.3.0]
Used Gradle version [7.0.1]
Also added kapt 'org.xerial:sqlite-jdbc:3.36.0.1'


Caused by: java.lang.Exception: No native library is found for os.name=Mac and     os.arch=aarch64. path=/org/sqlite/native/Mac/aarch64 at org.sqlite.SQLiteJDBCLoader.loadSQLiteNativeLibrary(SQLiteJDBCLoader.java:333) at org.sqlite.SQLiteJDBCLoader.initialize(SQLiteJDBCLoader.java:64) at androidx.room.verifier.DatabaseVerifier.<clinit>(DatabaseVerifier.kt:71)

How to solve this error?

SOLUTION Use Room Version: 2.4.0-alpha03 or later.

Roman
  • 2,464
  • 2
  • 17
  • 21

6 Answers6

176

If you are using Apple M1 chip

One of the release notes they have mentioned by jetpack (Version 2.4.0-alpha03 )

  • Fixed an issue with Room’s SQLite native library to support Apple’s M1 chips.

Change Version to 2.4.0-alpha03 or above

implementation "androidx.room:room-runtime:2.4.0-alpha03"
annotationProcessor "androidx.room:room-compiler:2.4.0-alpha03"
kapt 'androidx.room:room-compiler:2.4.0-alpha03'

Reference

https://developer.android.com/jetpack/androidx/releases/room#version_240_2

Arun NS
  • 1,900
  • 1
  • 8
  • 8
  • This one works for me. So for anyone who get main error message about "A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution Room Database" but have to run --stacktrace to see real error "No native library is found for os.name=Mac and os.arch=aarch64". – siripan Sep 22 '21 at 08:26
  • 2
    `2.4.0-alpha05` also works. – Abhimanyu Oct 10 '21 at 07:45
  • This is weird but works. Yet dont you think being in Alpha would cause any problems in future or problems with live production apps. Thatt working with teams? @Abhimanyu – Nitin Tej Oct 11 '21 at 05:59
  • 1
    The same resolves the problem when the chip is Apple M1 Pro – MeLean Dec 03 '21 at 09:03
  • 1
    Thank you. For today version 2.4.1 works well. – Ruslan Jan 18 '22 at 20:48
  • I still fails if I have both annotationProcessor and kapt. It will compile if I have only annotationProcessor, but it crashes because I'm using it with Kotlin – Gil Becker Feb 21 '22 at 17:57
  • Thanks - this worked for me. If you're doing the Google Codelab on SQL Databases in the Basics of Kotlin course, you need to go into build.gradle file in the Parks code, and change `def room_version` under dependencies to `'2.4.0-alpha03'` – medic_dev May 03 '22 at 07:55
  • for my project, doing the above reduces the error. and now I am getting this error: Caused by: java.lang.IllegalArgumentException: @androidx.room.Database does not define an element autoMigrations() – Vikas Pandey Jun 24 '22 at 10:42
73

Update(26 October 2021) - it seems that Room got fixed in the latest updates, Therefore you may consider updating Room to the latest version : ---- 2.4.0-alpha03 ---- or above

For those who are facing this problem, you can simply add this line before the room-compiler as a workaround now:

kapt "org.xerial:sqlite-jdbc:3.34.0"

If the mentioned workaround not working, I recommend using this workaround instead, adding it to the root build.gradle. This will force using the given dependency in the whole project:

allprojects {
    configurations.all {
        resolutionStrategy {
            force 'org.xerial:sqlite-jdbc:3.34.0'
        }
    }
}

shahar keysar
  • 837
  • 5
  • 9
  • I was facing the issue even after updating room to version 2.5.1. Adding this force resolution strategy did solve this issue finally! – Ankit Deshmukh Apr 02 '23 at 15:43
22

Room [2.4.0-alpha04] fixed this issues.

And remove kapt "org.xerial:sqlite-jdbc:3.34.0"

Roman
  • 2,464
  • 2
  • 17
  • 21
22

Here is what worked for me:

Change room version to 2.3.0 in app-level build.gradle

def room_version = "2.3.0" // for Room
implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"
testImplementation "androidx.room:room-testing:$room_version"

In project-level build.gradle, add the following configuration in allprojects

allprojects {
    repositories {
        // ...
    }

    // ADD THE FOLLOWING
    configurations.all {
        resolutionStrategy {
            force 'org.xerial:sqlite-jdbc:3.34.0'
        }
    }
}

Clean & rebuild your project :)

Ref: this comment on Google IssueTracker

Utsav Barnwal
  • 985
  • 11
  • 14
  • this is really help if anyone can't update room version from 2.3.0 to 2.4.0 alpha, thanks man :)) @Utsav Barnwal – amr ismail Feb 19 '22 at 15:52
12

Room fixed this issues on Version 2.4.0-alpha03

Fixed an issue with Room’s SQLite native library to support Apple’s M1 chips.

Update: The room latest version is "2.4.2"

val roomVersion = "2.4.2"
implementation("androidx.room:room-runtime:$roomVersion")
annotationProcessor("androidx.room:room-compiler:$roomVersion")
Alan Yuan
  • 151
  • 1
  • 4
2

We used JDK 11 and we had to move from default JDK to version >= 11.0.13. And that fixed build issues on M1.

andude
  • 500
  • 1
  • 5
  • 11