【问题标题】:Not able to use kotlin library无法使用 kotlin 库
【发布时间】:2017-12-05 21:11:11
【问题描述】:

我正在尝试为我的应用程序使用 this 库,但由于它是在 kotlin 中制作的,所以我遇到了问题。我下载了这个库的模块并在项目中导入了这个模块,但在初始状态下,我找不到 kotlin 插件,所以我将等级更改为this

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.2"

    defaultConfig {
        minSdkVersion 17
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'),   'proguard-rules.pro'
        }
    }
    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }
    resourcePrefix "yal_ms_"
}
buidscript {
    ext.kotlin_version = '1.0.1-2'

    repositories {
        jcenter()
        mavenCentral()
    }

    dependencies {
        classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.0.1-2'
    }
}
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile "com.android.support:appcompat-v7:26.1.0"
    compile "com.android.support:recyclerview-v7:26.1.0"
    compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}
repositories {
    mavenCentral()
    jcenter()
}

我是第一次尝试使用 kotlin 库,但我对 kotlin 了解不多,任何关于如何使用该库的建议都会有所帮助。

【问题讨论】:

  • 您可以从使用当前的 Kotlin 版本开始。也不清楚你的错误是关于什么的。 Kotlin Plugin 也可以指 Kotlin 的 AS 插件。您应该始终确保使用最新版本的 AS。如果是这种情况,则可能是插件崩溃了,因此请查看错误日志。
  • 嘿,你能回答我的颤振问题吗

标签: android android-gradle-plugin kotlin android-library


【解决方案1】:

尝试通过 gradle 导入 this

maven { url "https://jitpack.io" } 添加到项目 gradle 的存储库中。所以会是这样的

build.gradle(项目)

buildscript {
    ext.kotlin_version = '1.1.60'
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0'
        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
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven { url "https://jitpack.io" }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

并将compile 'com.github.yalantis:multi-selection:v0.1' 添加到build.gradle(app)

中的依赖项

这可能会在构建项目时创建 Manifest Merge Conflicts 错误,以删除在 Manifest 中的 <application> 标签下添加 tools:replace="android:label"

【讨论】:

    猜你喜欢
    • 2022-06-29
    • 2022-08-21
    • 1970-01-01
    • 2017-07-21
    • 2022-10-20
    • 1970-01-01
    • 2020-01-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多