'Caused by: java.lang.Exception: No native library is found for os.name=Mac and os.arch=aarch64. path=/org/sqlite/native/Mac/aarch64

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.



Solution 1:[1]

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

Solution 2:[2]

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

Solution 3:[3]

Room [2.4.0-alpha04] fixed this issues.

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

Solution 4:[4]

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

Solution 5:[5]

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

Solution 6:[6]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Arun NS
Solution 2
Solution 3
Solution 4 Utsav Barnwal
Solution 5 andude
Solution 6 Alan Yuan