0
votes

I have a Flutter project where I am using a QR code scanner plugin which is written in Kotlin for Android. After adding this to my project, I am having build issues in Android, iOS works fine:

Android Studio error message:

Could not find method implementation() for arguments [org.jetbrains.kotlin:kotlin-stdlib-jre7:1.2.31] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

My App Gradle:

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'
}

My project 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"
    }
}

Any help would be wonderful, as I am about to throw my laptop out the window.

EDIT: After prompted by AS, I changed the Kotlin version variable to ext.kotlin_version = '1.3.1'. I now Geta new error:

Could not find org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.1. Searched in the following locations: - 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 Required by: project :

1
@Mohitpatel yes, no change sadly.Robert Benedetto
Downgrading kotlin version ?? ext.kotlin_version = '1.1.1'Mohit patel
@Mohitpatel tried it, no good.Robert Benedetto
@Mohitpatel was now prompted by AS to change the version variable to 1.3.1 (edited the issue as well), but now I get another error about plugins that can't be found?Robert Benedetto

1 Answers

0
votes

The latest Kotlin version at the moment of this writing is 1.3.31.

You can also check https://blog.jetbrains.com/kotlin/category/releases/ and https://github.com/JetBrains/kotlin/releases

Or through Android Studio > Tools > Kotlin > Configure Kotlin Plugin Updates

Also, make sure you have:

buildScript {
    ext.kotlin_version = '1.3.31'
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

You can also check which plugins are available at Kotlin Gradle Plugin.

Replace:

implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"

with:

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

or

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

If you desperately need jre7 which is deprecated and not recommended make sure that your Kotlin version matches the JRE version.

Check the Kotlin Standard Library JRE 7