skip to Main Content

I tried to use the tflite package to create a live object detection app, but it seems that after I installed both the packages: tflite, and also wrote the detection code it didn’t seem to run.

Please help. I have been searching for a solution for a week but haven’t found one yet 🥹.

PROBLEM:

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':tflite'.
> Could not create an instance of type com.android.build.api.variant.impl.LibraryVariantBuilderImpl.
   > Namespace not specified. Specify a namespace in the module's build file. See https://d.android.com/r/tools/upgrade-assistant/set-namespace for information about setting the namespace.

     If you've specified the package attribute in the source AndroidManifest.xml, you can use the AGP Upgrade Assistant to migrate to the namespace value in the build file. Refer to https://d.android.com/r/tools/upgrade-assistant/agp-upgrade-assistant for general information about using the AGP Upgrade Assistant.

* 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.

android/app/build.gradle


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

android {
    namespace "com.example.application" 
    compileSdk = flutter.compileSdkVersion
    ndkVersion = flutter.ndkVersion

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_1_8
    }

    defaultConfig {
       applicationId = "com.example.myapp"
        minSdk = flutter.minSdkVersion
        targetSdk = flutter.targetSdkVersion
        versionCode = flutter.versionCode
        versionName = flutter.versionName
    }

    buildTypes {
        release {
            signingConfig = signingConfigs.debug
        }
    }
}

flutter {
    source = "../.."
}

android/settings.gradle


pluginManagement {
    def flutterSdkPath = {
        def properties = new Properties()
        file("local.properties").withInputStream { properties.load(it) }
        def flutterSdkPath = properties.getProperty("flutter.sdk")
        assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
        return flutterSdkPath
    }()

    includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")

    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
    }
}

plugins {
    id "dev.flutter.flutter-plugin-loader" version "1.0.0"
    id "com.android.application" version "8.1.0" apply false
    id "org.jetbrains.kotlin.android" version "1.8.22" apply false
}

include ":app"

pubspec.yaml


cupertino_icons: ^1.0.8
  flutter_svg: ^2.0.10+1
  image_picker: ^1.1.2
  camera: ^0.11.0+2
  tflite: ^1.1.2

~tflite-1.1.2androidbuild.gradle:


group 'sq.flutter.tflite'
version '1.0-SNAPSHOT'

buildscript {
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.6.3'
    }
}

rootProject.allprojects {
    repositories {
        google()
        jcenter()
    }
}

apply plugin: 'com.android.library'

android {
    compileSdkVersion 28

    defaultConfig {
        minSdkVersion 19
        testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
    }
    lintOptions {
        disable 'InvalidPackage'
    }

    dependencies {
        implementation 'org.tensorflow:tensorflow-lite:+'
        implementation 'org.tensorflow:tensorflow-lite-gpu:+'
    }
}

Can anyone help me please ? thank you

2

Answers


  1. The issue is caused by a mismatch between the Android Gradle Plugin (AGP) version used in your project and the tflite package. The tflite package is using an outdated AGP version (3.6.3), while your app is using a more recent version (8.1.0).

    Update your pubspec.yaml

      cupertino_icons: ^1.0.8
      flutter_svg: ^2.0.10+1
      image_picker: ^1.1.2
      camera: ^0.11.0+2
      tflite:
        git:
          url: https://github.com/tech-ramakant/flutter_tflite.git
          ref: Namespace_not_specified_fix
    

    update your app’s build.gradle -> from minSdkVersion 15 to minSdkVersion 19 and then follow below commands

    flutter clean
    flutter pub get
    flutter run
    
    Login or Signup to reply.
  2. This issue occurs because the library is not updated for 3 years.
    To fix this you can try out this mentioned link https://github.com/shaqian/flutter_tflite/pull/305.
    If not solved than have a look in the Git hub repo and PR section it will be really helpful because of the contributors.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search