【问题标题】:Android Studio importing Jetbrains ExposedAndroid Studio 导入 Jetbrains Exposed
【发布时间】:2018-05-22 18:39:45
【问题描述】:

我是 Android 开发的新手。我已经使用 Android Studio 创建了一个新项目,需要将 jetbrains 公开库导入到我现有的项目中。当我尝试按照公开的入门指南将以下内容添加到 build.grade 文件中时:

repositories {
  maven {
    url  "https://dl.bintray.com/kotlin/exposed" 
  }
}
dependencies {
  compile 'org.jetbrains.exposed:exposed:0.10.2'
}

我收到以下错误:

Could not find method compile() for arguments [org.jetbrains.exposed:exposed:0.10.2] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

我已经在互联网上搜索了几天,但仍然无法找出问题所在。

这是 build.gradle 文件:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

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

repositories {
    maven {
        url  "https://dl.bintray.com/kotlin/exposed"
    }
}

dependencies {
    compile 'org.jetbrains.exposed:exposed:0.10.2'
}

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

希望有人可以帮助我。

提前致谢。

【问题讨论】:

    标签: android kotlin


    【解决方案1】:

    您应该将此依赖项放在模块级别的 build.gradle 文件中 - 默认情况下,它位于 app 文件夹中,而不是项目级别的 build.gradle 文件中,该文件位于项目的根目录中。

    此外,您应该使用implementation 而不是compile,因为您使用的是高于 3.0 版本的 Android Gradle 插件:

    repositories {
        maven {
            url  "https://dl.bintray.com/kotlin/exposed"
        }
    }
    
    dependencies {
        implementation 'org.jetbrains.exposed:exposed:0.10.2'
    }
    

    【讨论】:

    • 感谢您的回复。在我按照建议将代码移动到 app 文件夹 build.gradle 文件并尝试将 Database.connect(jdbc:h2:mem:test", driver = "org.h2.Driver") 添加到我的项目中后,我收到 10 个错误:例如,意外的类型规范,期待')',期待一个元素,未解析的引用:jdbc等。你知道根源是什么吗?
    • 我认为您应该将与实际使用该库相关的任何问题作为单独的问题发布,因为它们不再与有关 Gradle 依赖项的问题相关..
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-05
    • 2021-06-03
    • 1970-01-01
    • 2022-08-06
    • 2015-07-29
    • 1970-01-01
    相关资源
    最近更新 更多