关于Android Studio遇到的org.gradle.api.internal.file.DefaultSourceDirectorySet问题和Kotlin的JNI库问题

遇到的问题:

ERROR: Unable to find method 'org.gradle.api.internal.file.DefaultSourceDirectorySet.<init>(Ljava/lang/String;Lorg/gradle/api/internal/file/FileResolver;)V'.
Possible causes for this unexpected error include:
Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
Re-download dependencies and sync project (requires network)

The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.
Stop Gradle build processes (requires restart)

Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.

In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.

解决的办法: "File"->"Settings"->"Languages & Frameworks"->"Kotlin", 选择:

然后参考了: https://stackoverflow.com/questions/48048340/android-gradle-unable-to-find-method-org-grade-api-internal-file-defaultsourced

检查了build.gradle:

buildscript {
    ext.kotlin_version = '1.0.0'
    repositories {
        google()
        jcenter()
        
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.3'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

修正: ext.kotlin_version = '1.3.50' 

然后编译遇到了个大坑:

More than one file was found with OS independent path 'lib/armeabi-v7a/libScreenRecordLib.so'

报错截图:

后来发现需要做如下配置build.gradle(app):

android {
    ...
    packagingOptions {
        exclude 'lib/armeabi-v7a/libScreenRecordLib.so'
        exclude 'lib/x86_64/libScreenRecordLib.so'
        exclude 'lib/arm64-v8a/libScreenRecordLib.so'
        exclude 'lib/x86/libScreenRecordLib.so'
    }
}

问题成功解决

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章