jeroentrappers / flutter_keychain

A flutter plugin for secure storage on Android via KeyStore and iOS via Keychain
Other
56 stars 41 forks source link

Execution failed for task ':flutter_keychain:compileDebugKotlin' #47

Closed cbingos closed 2 weeks ago

cbingos commented 2 weeks ago

help, On an Android device, when I run flutter run, the following error is reported:

Execution failed for task ':flutter_keychain:compileDebugKotlin'.
> 'compileDebugJavaWithJavac' task (current target is 1.8) and 'compileDebugKotlin' task (current target is 17) jvm target compatibility should be set to the same Java version.

android/gradle.properties

org.gradle.jvmargs=-Xmx4G
android.useAndroidX=true
android.enableJetifier=true

android/build.gradle

buildscript {
    ext.kotlin_version = '1.9.0'
    // ext.kotlin_version = '1.7.10'
    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:7.4.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        // implementation 'com.google.android.gms:play-services-wallet:18.1.3'
        // implementation 'com.android.support:appcompat-v7:24.1.1'
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
// subprojects {
    // afterEvaluate {
        // project -> if (project.hasProperty("kotlinOptions")) {
            // project.kotlinOptions {
                // jvmTarget = "1.8"
            // }
        // }
    // }
// }
subprojects {
    project.evaluationDependsOn(':app')
}
tasks.register("clean", Delete) {
    delete rootProject.buildDir
}

android/app/build.gradle

plugins {
    id "com.android.application"
    id "kotlin-android"
    id "dev.flutter.flutter-gradle-plugin"
}

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}
def keystorePropertiesFile = rootProject.file("key.properties")
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))

android {
    namespace "com.xxx.xxx.xxx"
    compileSdk 34
    ndkVersion flutter.ndkVersion
    def javaVersion = JavaVersion.VERSION_1_8
    compileOptions {
        // sourceCompatibility JavaVersion.VERSION_1_8
        // targetCompatibility JavaVersion.VERSION_1_8
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
    kotlinOptions {
//        jvmTarget = '1.8'
         jvmTarget = '17'
        // jvmTarget = javaVersion.toString()
    }
    /* subprojects { */
        /* afterEvaluate{ */
            /* tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile) { */
                /* if (project.plugins.hasPlugin("com.android.application") || project.plugins.hasPlugin("com.android.library")) { */
                    /* kotlinOptions.jvmTarget = android.compileOptions.sourceCompatibility */
                /* } else { */
                    /* kotlinOptions.jvmTarget = sourceCompatibility */
                /* } */
            /* } */
        /* } */
    /* } */

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }
    // subprojects {
        // tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile) {
            // kotlinOptions.jvmTarget = "18"
        // }
    // }
    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.sckj.iching.zhouyipro"
        // You can update the following values to match your application needs.
        // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
        // minSdkVersion flutter.minSdkVersion
        // targetSdkVersion flutter.targetSdkVersion
        minSdkVersion localProperties.getProperty('flutter.minSdkVersion').toInteger()
        targetSdkVersion localProperties.getProperty('flutter.targetSdkVersion').toInteger()
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }
    signingConfigs {
        release {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile file(keystoreProperties['storeFile'])
            storePassword keystoreProperties['storePassword']
        }
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.release
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    buildToolsVersion '34.0.0'
}

flutter {
    source '../..'
}

dependencies {
    implementation 'com.stripe:stripe-android:17.1.1'
    // implementation 'com.stripe:stripe-android:20.37.4'
}
cbingos commented 2 weeks ago

I solved this problem, After configuring the following files, Then update sdk with android studio and complete it according to the prompts,

java -version

java version "1.8.0_411"
Java(TM) SE Runtime Environment (build 1.8.0_411-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.411-b09, mixed mode)

the final configuration files: android/gradle.properties:

org.gradle.jvmargs=-Xmx4G
android.useAndroidX=true
android.enableJetifier=true
android.defaults.buildfeatures.buildconfig=true
android.nonTransitiveRClass=false
android.nonFinalResIds=false

android/build.gradle

buildscript {
    ext.kotlin_version = '1.9.0'
    // ext.kotlin_version = '1.7.10'
    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:8.4.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        // implementation 'com.google.android.gms:play-services-wallet:18.1.3'
        // implementation 'com.android.support:appcompat-v7:24.1.1'
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}
subprojects {
        afterEvaluate{
            tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile) {
                if (project.plugins.hasPlugin("com.android.application") || project.plugins.hasPlugin("com.android.library")) {
                    kotlinOptions.jvmTarget = android.compileOptions.sourceCompatibility
                } else {
                    kotlinOptions.jvmTarget = sourceCompatibility
                }
            }
        }
}
rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}
tasks.register("clean", Delete) {
    delete rootProject.buildDir
}

android/app/build.gradle:

plugins {
    id "com.android.application"
    id "kotlin-android"
    id "dev.flutter.flutter-gradle-plugin"
}

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}
def keystorePropertiesFile = rootProject.file("key.properties")
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))

android {
    namespace "com.xxx.abc"
    compileSdk 34
    ndkVersion "26.1.10909125"
    // ndkVersion flutter.ndkVersion
    // def javaVersion = JavaVersion.VERSION_1_8
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
        // sourceCompatibility JavaVersion.VERSION_1_7
        // targetCompatibility JavaVersion.VERSION_1_7
    }
    kotlinOptions {
       jvmTarget = '1.8'
         // jvmTarget = '17'
         // jvmTarget = '18'
        // jvmTarget = javaVersion.toString()
    }

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }
    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.sckj.iching.zhouyipro"
        // You can update the following values to match your application needs.
        // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
        // minSdkVersion flutter.minSdkVersion
        // targetSdkVersion flutter.targetSdkVersion
        minSdkVersion localProperties.getProperty('flutter.minSdkVersion').toInteger()
        targetSdkVersion localProperties.getProperty('flutter.targetSdkVersion').toInteger()
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }
    signingConfigs {
        release {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile file(keystoreProperties['storeFile'])
            storePassword keystoreProperties['storePassword']
        }
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.release
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    buildToolsVersion '34.0.0'
}

flutter {
    source '../..'
}

dependencies {
    // implementation 'com.stripe:stripe-android:17.1.1'
    implementation 'com.stripe:stripe-android:20.37.4'
}