[SOLVED] A problem occurred evaluating project ‘:app’

Question

This Content is from Stack Overflow. Question asked by Hephaestus

I try to use tflite package to create a live object detection app, but it seems that after i installed both the packages : tflite and camera, and also writing the detection code it doesn’t seem to run .

Packages :
Tflite : https://pub.dev/packages/tflite
Camera : https://pub.dev/packages/camera

this error occure :

A problem occurred evaluating project ':tflite'.

The entire Error :

FAILURE: Build failed with an exception.

* Where:
Build file 'C:UsersHephaDocumentsflutter_windows_2.10.3-stableflutter.pub-cachehostedpub.dartlang.orgtflite-1.1.2androidbuild.gradle' line: 24

* What went wrong:
A problem occurred evaluating project ':tflite'.
> No signature of method: build_a7q9josm4oau2t0m3mow48bac.android() is applicable for argument types: (build_a7q9josm4oau2t0m3mow48bac$_run_closure2) values: [build_a7q9josm4oau2t0m3mow48bac$_run_closure2@c7c7456]   

* 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 1m 43s
Running Gradle task 'assembleDebug'... 104,7s|Exception: Gradle task assembleDebug failed with exit code 1

My pubspec.yaml file :

dependencies:
  flutter:
    sdk: flutter

  cupertino_icons: ^1.0.2
  camera: ^0.9.4+1
  image_picker: ^0.8.4+11
  tflite: ^1.1.2

dev_dependencies:
  flutter_test:
    sdk: flutter

  flutter_lints: ^2.0.0

flutter:

  uses-material-design: true

  assets:
      - assets/
      - assets/labels.txt
      - assets/metadata_V2.tflite

My android/app/build.gradle file :

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
    ndkVersion flutter.ndkVersion
    
    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.aiassistantapp"
        // You can update the following values to match your application needs.
        // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
        minSdkVersion 21
        targetSdkVersion flutter.targetSdkVersion
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

    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.debug
        }
    }
     aaptOptions {
        noCompress 'tflite'
        noCompress 'lite'
    }
}

flutter {
    source '../..'
}

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

Can anyone help me please ? thank you

Solution

Update 2022-04-26:

It is possible that the root cause is using a Kotlin version which is not compatible with older versions of Gradle. A possible fix is downgrading the version of Kotlin below 1.2.71, or more sensibly, upgrading Gradle.

Update 2019-12-13:

As of Flutter 1.12 (stable) released on Dec 11 2019, Flutter boilerplate now includes gradle distribution 5.6.2 and plugin version 3.5.0 which will hopefully make this a historical SO question. Plugin version 3.5.3 is current, but even version 3.5.0 should fix the issue as initially reported.

Original answer:

This appears to be caused by the Flutter boilerplate specifying an old version of the gradle plugin. I’m still unclear if Flutter package updates in pubspec.yaml/lock are triggering the issue, I rolled back a way but it was still present here.

For some reason this affects my Windows 10 system, but not my Mac development environment. Both are up-to-date (Flutter 1.7.8+hotfix.4) and on the same versions of everything as far as I’m aware. On account of this Windows path separators are used in the notes below.

In android\gradle\wrapper\gradle-wrapper.properties the Flutter boilerplate specifies a gradle distribution of 4.10.2, which supports a plugin version of up to 3.3.2. However, android\build.gradle only depends on plugin version 3.2.1 (classpath 'com.android.tools.build:gradle:3.2.1'). It’s unclear why the Flutter boilerplate isn’t more internally consistent.

To resolve, change com.android.tools.build:gradle:3.2.1 => com.android.tools.build:gradle:3.3.2, run flutter clean and try the build again.

According to the gradle release notes, the current (July 2019) version of the plugin and gradle are 3.4.2 and 5.1.1 respectively. I don’t know if Flutter officially supports this version, although it seems to work on my project here and a clean build is markedly faster. The release notes cover some of the changes from 3.2.x => 3.3.x => 3.4.x.

To upgrade to the current version, edit android\gradle\wrapper\gradle-wrapper.properties to source gradle 5.1.1, and then you’re able to upgrade the gradle plugin to 3.4.2.

gradle-wrapper.properties:

distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip

build.gradle:

classpath 'com.android.tools.build:gradle:3.4.2'

Note that once gradle 5.1.1 is being used, you can still set the plugin version back to 3.2.1 to reproduce the issue.

I’ve opened an issue with the Flutter team to try and understand this better and will update this answer if they come back with anything concrete.


Answered by repentsinner, This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of
CC BY-SA 2.5.
CC BY-SA 3.0.
CC BY-SA 4.0.

people found this article helpful. What about you?