'Execution failed for task ':share_plus:compileDebugKotlin'. Getting this compiling flutter app tried everything flutter clean etc nothing is working

Note: Some input files use or override a deprecated API. Note: Recompile with -Xlint:deprecation for details. Note: Some input files use unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. Note: C:\Users\Arslan\AppData\Local\Pub\Cache\hosted\pub.dartlang.org\launch_review-3.0.1\android\src\main\java\com\iyaffle\launchreview\LaunchReviewPlugin.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. Note: C:\Users\Arslan\AppData\Local\Pub\Cache\hosted\pub.dartlang.org\path_provider_android-2.0.12\android\src\main\java\io\flutter\plugins\pathprovider\PathProviderPlugin.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. e: C:\Users\Arslan\AppData\Local\Pub\Cache\hosted\pub.dartlang.org\share_plus-3.1.0\android\src\main\kotlin\dev\fluttercommunity\plus\share\MethodCallHandler.kt: (34, 24): Type mismatch: inferred type is String? but String was expected

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':share_plus:compileDebugKotlin'.

Compilation error. See log for more details

  • Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

  • Get more help at https://help.gradle.org

BUILD FAILED in 48s Exception: Gradle task assembleDebug failed with exit code 1

Getting this compiling flutter app tried everything flutter clean etc nothing is working.



Solution 1:[1]

I had the same problem today.

The only solution for me, was this.

  1. Go to your pubspec.yaml
  2. delete your share_plus line, and put share_plus: ^4.0.4 (or latest version from pub.dev
  3. ctrl+s
  4. flutter run
  5. enjoy

Solution 2:[2]

I had the same problem yesterday, although I do not quite remember how I solved it. Let's try to go through the standard:

  1. Wipe all flutter cache (flutter clean) and upgrade to latest flutter and dart.
  2. Update your plugins to the latest version.
  3. I'll give you my android/build.gradle file below, compare.
  4. I will also show you my android/app/build.gradle file, look for the lines where kotlin is written, its version, import, etc.

I won’t say, but as far as I remember, I had this problem when I used one of the translation plugins, this plugin added an additional translate method to the String object, it was displayed correctly in the code, but when launched it gave an error related to Kotlin. Example:
String text;
print(text.translate); //Error for no apparent reason

So check your code carefully.

Pay special attention to this warning from your error message: "Type mismatch: inferred type is String? but String was expected". Try to find this gap in the newly written functionality.

android/build.gradle:

buildscript {
    ext.kotlin_version = '1.6.10'
    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }

    // gradle.projectsEvaluated {
    //     tasks.withType(JavaCompile){
    //         options.compilerArgs << "-Xlint:deprecation" << "-Xlint:unchecked"
    //     }
    // }
}

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

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

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

android/app/build.gradle:

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 plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion flutter.compileSdkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

    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.example.legend_application"
        minSdkVersion 22 //flutter.minSdkVersion
        targetSdkVersion flutter.targetSdkVersion
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName

        multiDexEnabled true
    }

    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support:multidex:1.0.3'
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Carlos Peñaranda
Solution 2 Legend5366