androidflutterkotlingradleflutter-dependencies

flutter build failure with problem occurred configuring project


i'm building a flutter app where i'm using better_player plugin, the app was running just fine until it started giving me this error when i run it:

Launching lib/main.dart on SM N950F in debug mode...

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':better_player'.
> 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.

BUILD FAILED in 1m 14s
Error: Gradle task assembleDebug failed with exit code 1

Exited (1).

this is my android/build.gradle:

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

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

tasks.register("clean", Delete) {
    delete rootProject.buildDir
}

this is app/build.gradle

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

android {
    namespace = "com.example.seriez"
    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.seriez"
        minSdk = flutter.minSdkVersion
        targetSdk = flutter.targetSdkVersion
        versionCode = flutter.versionCode
        versionName = flutter.versionName
    }

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

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

and 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"

and pubspec.yaml

name: seriez
description: "A new Flutter project."
# The following line prevents the package from being accidentally published to
# pub.dev using `flutter pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.0+1

environment:
  sdk: '>=3.4.0 <4.0.0'
dependencies:
  flutter:
    sdk: flutter

  cupertino_icons: ^1.0.6
  cached_network_image: ^3.4.1
  flutter_carousel_widget: ^2.3.0
  provider: ^6.1.2
  flutter_typeahead: ^5.2.0
  google_fonts: ^6.2.1
  flutter_blurhash: ^0.8.2
  video_player: ^2.9.2
  sembast: ^3.7.4
  path_provider: ^2.1.4
  dio: ^5.7.0
  flutter_local_notifications: ^17.2.2
  http: ^1.2.2
  wakelock_plus: ^1.2.8
  flutter_svg: ^2.0.11
  sizer: ^3.0.0
  url_launcher: ^6.3.1
  better_player: ^0.0.84
  

dev_dependencies:
  flutter_test:
    sdk: flutter
  flutter_lints: ^3.0.0

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec

# The following section is specific to Flutter packages.
flutter:
  uses-material-design: true

  # To add assets to your application, add an assets section, like this:
  assets:
    - assets/data/

thanks in advance


Solution

  • I managed to solve the issue by adding the namespace to the android section in the plugin's android/build.gradle, then i got the error

    Launching lib/main.dart on SM N950F in debug mode...
     2 ERROR:D8: com.android.tools.r8.kotlin.H
    Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
    
    

    so, i set

    compileSdk = 34
    minSdk = 24
    targetSdk = 33

    and all errors were gone and my App ran normally