Android kapt java.lang.UnsatisfiedLinkError Room

半腔热情 提交于 2020-12-11 08:57:14

问题


I'm updating my project to use the jetpack libraries.

I executed this in the commandline:

./gradlew :app:kaptDebugKotlin

in my project directory, and this error was thrown:

e: [kapt] An exception occurred: java.lang.UnsatisfiedLinkError: org.sqlite.core.NativeDB._open_utf8([BI)V
        at org.sqlite.core.NativeDB._open_utf8(Native Method)
        at org.sqlite.core.NativeDB._open(NativeDB.java:71)
        at org.sqlite.core.DB.open(DB.java:174)
        at org.sqlite.core.CoreConnection.open(CoreConnection.java:220)
        at org.sqlite.core.CoreConnection.<init>(CoreConnection.java:76)
        at org.sqlite.jdbc3.JDBC3Connection.<init>(JDBC3Connection.java:25)
        at org.sqlite.jdbc4.JDBC4Connection.<init>(JDBC4Connection.java:24)
        at org.sqlite.SQLiteConnection.<init>(SQLiteConnection.java:45)
        at org.sqlite.JDBC.createConnection(JDBC.java:114)
        at androidx.room.verifier.DatabaseVerifier$Companion.create(DatabaseVerifier.kt:81)
        at androidx.room.processor.DatabaseProcessor.doProcess(DatabaseProcessor.kt:78)
        at androidx.room.processor.DatabaseProcessor.process(DatabaseProcessor.kt:54)
        at androidx.room.RoomProcessor$DatabaseProcessingStep.process(RoomProcessor.kt:63)
        at com.google.auto.common.BasicAnnotationProcessor.process(BasicAnnotationProcessor.java:330)
        at com.google.auto.common.BasicAnnotationProcessor.process(BasicAnnotationProcessor.java:181)
        at org.jetbrains.kotlin.kapt3.base.ProcessorWrapper.process(annotationProcessing.kt:99)
        at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:794)
        at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:705)
        at com.sun.tools.javac.processing.JavacProcessingEnvironment.access$1800(JavacProcessingEnvironment.java:91)
        at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1035)
        at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1176)
        at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1170)
        at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1068)
        at org.jetbrains.kotlin.kapt3.base.AnnotationProcessingKt.doAnnotationProcessing(annotationProcessing.kt:55)
        at org.jetbrains.kotlin.kapt3.base.AnnotationProcessingKt.doAnnotationProcessing$default(annotationProcessing.kt:27)
        at org.jetbrains.kotlin.kapt3.AbstractKapt3Extension.runAnnotationProcessing(Kapt3Extension.kt:216)
        at org.jetbrains.kotlin.kapt3.AbstractKapt3Extension.analysisCompleted(Kapt3Extension.kt:164)
        at org.jetbrains.kotlin.kapt3.ClasspathBasedKapt3Extension.analysisCompleted(Kapt3Extension.kt:93)
        at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM$analyzeFilesWithJavaIntegration$2.invoke(TopDownAnalyzerFacadeForJVM.kt:98)
        at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(TopDownAnalyzerFacadeForJVM.kt:108)
        at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration$default(TopDownAnalyzerFacadeForJVM.kt:85)
        at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:370)
        at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:61)
        at org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport.analyzeAndReport(AnalyzerWithCompilerReport.kt:101)
        at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.analyze(KotlinToJVMBytecodeCompiler.kt:361)
        at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:126)
        at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:154)
        at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:51)
        at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:95)
        at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:50)
        at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:88)
        at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$1$1$2.invoke(CompileServiceImpl.kt:405)
        at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$1$1$2.invoke(CompileServiceImpl.kt:98)
        at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:927)
        at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:98)
        at org.jetbrains.kotlin.daemon.common.DummyProfiler.withMeasure(PerfUtils.kt:137)
        at org.jetbrains.kotlin.daemon.CompileServiceImpl.checkedCompile(CompileServiceImpl.kt:957)
        at org.jetbrains.kotlin.daemon.CompileServiceImpl.doCompile(CompileServiceImpl.kt:926)
        at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:404)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:357)
        at sun.rmi.transport.Transport$1.run(Transport.java:200)
        at sun.rmi.transport.Transport$1.run(Transport.java:197)
        at java.security.AccessController.doPrivileged(Native Method)
        at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
        at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:573)
        at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:834)
        at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:688)
        at java.security.AccessController.doPrivileged(Native Method)
        at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:687)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)

This is my project build.gradle

ext {
archLifecycleVersion = '2.0.0'
roomVersion = '2.1.0-alpha02'
pagingVersion = '2.1.0-beta01'

supportLibVersion = '1.0.0'

}

buildscript {
    ext.kotlin_version = '1.2.51'
    repositories {
        google()
        jcenter()
        maven {
            url "https://maven.google.com"
        }
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.0'

        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

        classpath 'com.google.guava:guava:19.0'

        classpath 'com.android.tools.build.jetifier:jetifier-processor:1.0.0-beta02'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven {
            url "https://maven.google.com"
        }
        mavenCentral()
    }
}

And this is the app build.gradle

    buildscript {
    repositories {
        maven {
            url "https://maven.google.com"
        }
        jcenter()
        mavenCentral()
        google()
    }

    dependencies {
        classpath 'com.google.cloud.tools:endpoints-framework-gradle-plugin:1.0.0'
    }
}

    apply plugin: 'com.android.application'
    apply plugin: 'kotlin-android'
    apply plugin: 'kotlin-android-extensions'
    apply plugin: 'kotlin-kapt'
    apply plugin: 'com.google.cloud.tools.endpoints-framework-client'

    android {
        compileSdkVersion 28
        buildToolsVersion "28.0.3"
        defaultConfig {
            applicationId "package.name.of.app"
            minSdkVersion 15
            targetSdkVersion 28
            versionCode 1
            versionName "1.0"
            //multiDexEnabled false
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
        dexOptions {
            javaMaxHeapSize "4096m"
        }
        dataBinding {
            enabled = true
        }
    }

    dependencies {
        implementation fileTree(dir: 'libs', include: ['*.jar'])
        implementation "androidx.appcompat:appcompat:$rootProject.supportLibVersion"
        implementation "com.google.android.material:material:$rootProject.supportLibVersion"

        implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
        implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
        implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"

        implementation 'com.squareup.retrofit2:retrofit:2.1.0'
        implementation 'com.squareup.retrofit2:converter-gson:2.1.0'

        implementation 'com.github.bumptech.glide:glide:4.8.0'
        kapt 'com.github.bumptech.glide:compiler:4.8.0'

        implementation 'com.google.android.gms:play-services-maps:16.0.0'
        implementation 'com.google.android.gms:play-services-auth:16.0.1'

        // architecture components
        implementation "androidx.lifecycle:lifecycle-extensions:$rootProject.archLifecycleVersion"
        implementation "androidx.lifecycle:lifecycle-runtime:$rootProject.archLifecycleVersion"
        implementation "androidx.room:room-runtime:$rootProject.roomVersion"
        implementation "androidx.paging:paging-runtime:$rootProject.pagingVersion"
        kapt "androidx.lifecycle:lifecycle-compiler:$rootProject.archLifecycleVersion"
        kapt "androidx.room:room-compiler:$rootProject.roomVersion"

        testImplementation 'junit:junit:4.12'
    }

    configurations {
        all {
            exclude module: 'httpclient'
            exclude module: 'commons-logging'
        }
    }

Does anyone know what caused this issue? Why does the SQLite error occur during compilation instead of during actual execution? Also, has anyone successfully compiled an app with similar dependencies as described above?


回答1:


Upon searching for information regarding this issue, I found this link

https://github.com/xerial/sqlite-jdbc/issues/97

The fix was to update /etc/fstab to remove 'noexec' from /tmp, and then remounting /tmp




回答2:


In Windows grant all permissions to your user in c:\Users\\AppData\Temp and the problem will be gone. You'll have to do it everytime you update Windows.




回答3:


If you don't have permissions to remove noexec from /tmp, you can also supply an alternative java.io.tmpdir to kapt:

A Room issue has a comment from a Google engineer with a workaround:

Since you are using kapt are you sure you are passing java.io.tmpdir to Kotlin's compiler daemon and not Gradle's?

For example:

./gradlew <gradle-params> -Dkotlin.daemon.jvm.options="-Djava.io.tmpdir=path/to/a/folder" <task>

Another Room issue has a comment from a Google engineer suggesting that upgrading to 2.2.5 fixes the problem:

Can you try with Room 2.2.5 we had some further fixes in that version regarding the JDBC library and the way the Room compiler loads it and uses it.

I upgraded to 2.2.5, and the problem went away, but I didn't see this failure on every build, so I'll have to wait couple of weeks before I can say this is definitely fixed.



来源:https://stackoverflow.com/questions/53740758/android-kapt-java-lang-unsatisfiedlinkerror-room

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!