我有一个Flutter项目,在这里我使用的是QR码扫描仪插件,该插件是用Kotlin for Android编写的。将其添加到我的项目后,我在Android中遇到构建问题,iOS正常运行:
Android Studio错误消息:
找不到参数的方法Implementation() [org.jetbrains.kotlin:kotlin-stdlib-jre7:1.2.31]关于类型的对象 org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler。
我的应用程式摇篮:
buildscript {
repositories {
// ...
maven { url 'https://plugins.gradle.org/m2/' } // Gradle Plugin Portal
}
// Added for QR
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
dependencies {
// Added for QR
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
// implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
// ...
// OneSignal-Gradle-Plugin
classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.10.2, 0.99.99]'
}
}
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
android {
compileSdkVersion 27
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "net.cadsys.app"
minSdkVersion 16
targetSdkVersion 27
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
}
flutter {
source '../..'
}
dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
我的项目Gradle:
buildscript {
ext.kotlin_version = '1.2.31'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: 'kotlin'
allprojects {
repositories {
google()
jcenter()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
repositories {
mavenCentral()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
}
compileKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
}
compileTestKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
}
任何帮助都会很棒,因为我正要把笔记本电脑扔到窗外。
编辑:在AS提示后,我将Kotlin版本变量更改为ext.kotlin_version ='1.3.1'。现在我得到一个新错误:
找不到org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.1。 在以下位置搜索: -https://dl.google.com/dl/android/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin/1.3.1/kotlin-gradle-plugin-1.3.1.pom -https://dl.google.com/dl/android/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin/1.3.1/kotlin-gradle-plugin-1.3.1.jar -https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-gradle-plugin/1.3.1/kotlin-gradle-plugin-1.3.1.pom -https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-gradle-plugin/1.3.1/kotlin-gradle-plugin-1.3.1.jar 要求: 项目:
答案 0 :(得分:0)
撰写本文时,最新的Kotlin版本是1.3.31
。
您还可以选中https://blog.jetbrains.com/kotlin/category/releases/和https://github.com/JetBrains/kotlin/releases
或通过Android Studio
> Tools
> Kotlin
> Configure Kotlin Plugin Updates
另外,请确保您拥有:
buildScript {
ext.kotlin_version = '1.3.31'
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
您还可以在Kotlin Gradle Plugin上查看哪些插件可用。
替换:
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
具有:
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
或
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
如果您非常需要jre7
的{{1}},并且不建议使用,请确保您的Kotlin版本与JRE版本匹配。