配置项目 ':fluttertoast' 时出现问题

A problem occurred configuring project ':fluttertoast'

提问人:Pasindu Basnayake 提问时间:10/18/2023 更新时间:10/18/2023 访问量:60

问:

当我添加 fluttertoast 并运行应用程序时,我收到以下错误:控制台中的错误

下面是我刚刚添加的代码:


import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
import 'package:lifelink_usersapp/global/global.dart';
import 'package:fluttertoast/fluttertoast.dart';


addItemToCart(String? foodItemId, BuildContext context, int itemCounter){

  List<String>? tempList = sharedPreferences!.getStringList("userCart");
  tempList!.add(foodItemId! + ":$itemCounter");

  FirebaseFirestore.instance.collection("users").doc(firebaseAuth.currentUser!.uid).update({
    "userCart": tempList, 
  }).then((value){

    Fluttertoast.showToast(msg: "Item Added Successfully");
    sharedPreferences!.setStringList("userCart", tempList);
  });
}



删除 flutter toast 并注释掉新添加的代码并像以前一样运行应用程序后,应用程序运行时不会出现任何运行时错误。

  • 我已正确指定命名空间。
  • 另外,我没有在 AndroidMinifest 文件中指定 package 属性。

我目前正在使用:

  • Gradle 版本:8.1.2
  • 颤振 : 3.13.6
  • 爪哇 : 21
  • Fluttertoast 版本:8.0.7

下面是 app\build.gradle

plugins {
    id "com.google.gms.google-services"
    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'
}

android {
    compileSdkVersion 33
    namespace "com.example.lifelink_usersapp"
    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.lifelink_usersapp"
        // 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
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        multiDexEnabled true
    }

    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
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation platform("com.google.firebase:firebase-bom:32.3.1")
    implementation "com.google.firebase:firebase-analytics"
}

我尝试像往常一样运行代码并打开应用程序。但是在运行时,将显示以下错误消息:

  • 出了什么问题: 配置项目“:fluttertoast”时出现问题。

无法创建 com.android.build.api.variant.impl.LibraryVariantBuilderImpl 类型的实例。 未指定命名空间。在模块的构建文件中指定命名空间。有关设置命名空间的信息,请参阅 https://d.android.com/r/tools/upgrade-assistant/set-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 
flutter 命名空间 build.gradle android-manifest

评论


答: 暂无答案