Merge "copy new native libs if they are loaded in another classloader" into androidx-master-dev
diff --git a/room/compiler/src/main/kotlin/androidx/room/verifier/DatabaseVerifier.kt b/room/compiler/src/main/kotlin/androidx/room/verifier/DatabaseVerifier.kt
index a7e87c6..0a38780 100644
--- a/room/compiler/src/main/kotlin/androidx/room/verifier/DatabaseVerifier.kt
+++ b/room/compiler/src/main/kotlin/androidx/room/verifier/DatabaseVerifier.kt
@@ -62,9 +62,16 @@
          */
         private val SQLITE_NATIVE_LIB_EXTENSIONS = arrayOf(".so", ".jnilib", ".dll")
 
-        private val sqliteNativeLibDir: File
+        private lateinit var sqliteNativeLibDir: File
 
         init {
+            copyNativeLibs()
+        }
+
+        /**
+         * Copies native libraries into a tmp folder to be loaded.
+         */
+        private fun copyNativeLibs() {
             // see: https://github.com/xerial/sqlite-jdbc/issues/97
             val tmpDir = System.getProperty("java.io.tmpdir")
             checkNotNull(tmpDir) {
@@ -106,7 +113,14 @@
                         nativeLibs.forEach {
                             it.setExecutable(true)
                             context.logger.d("reloading the sqlite native file: $it")
-                            System.load(it.absoluteFile.absolutePath)
+                            try {
+                                System.load(it.absoluteFile.absolutePath)
+                            } catch (unsatisfied: UnsatisfiedLinkError) {
+                                // https://issuetracker.google.com/issues/146061836
+                                // workaround for b/146061836 where we just copy it again as
+                                // another file.
+                                copyNativeLibs()
+                            }
                         }
                     } else {
                         context.logger.w(Warning.CANNOT_CREATE_VERIFICATION_DATABASE, element,