Сообщение об ошибке:
Код: Выделить всё
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':flutter_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.
* 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.
Код: Выделить всё
Flutter version: 3.27.0
Dart version: 3.6.0
Android Studio version: 2024.2 (Artic Fox)
Gradle version: 8.3
Java version: OpenJDK 21
Код: Выделить всё
plugins {
id "com.android.application"
id "kotlin-android"
// The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
id "dev.flutter.flutter-gradle-plugin"
}
android {
namespace = "com.example.ornek12flutter"
compileSdkVersion 34
ndkVersion = "25.1.8937393"
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
aaptOptions {
noCompress 'tflite'
noCompress 'lite'
}
kotlinOptions {
jvmTarget = 17
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId = "com.example.ornek12flutter"
// You can update the following values to match your application needs.
// For more information, see: https://flutter.dev/to/review-gradle-config.
minSdkVersion 23
targetSdkVersion 34
versionCode = flutter.versionCode
versionName = flutter.versionName
}
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 = "../.."
}
Код: Выделить всё
buildscript {
ext.kotlin_version = '1.7.20'
repositories{
google()
mavenCentral()
}
dependencies{
classpath 'com.android.tools.build:gradle:7.1.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
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
}
Код: Выделить всё
Код: Выделить всё
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-all.zip
Код: Выделить всё
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.3.2" apply false
id "org.jetbrains.kotlin.android" version "2.0.20" apply false
}
include ":app"
Код: Выделить всё
get: ^4.6.6
camera: ^0.11.0+2
permission_handler: ^11.3.1
flutter_tflite: ^1.0.1
Код: Выделить всё
import 'dart:developer';
import 'package:camera/camera.dart';
import 'package:flutter_tflite/flutter_tflite.dart';
import 'package:get/get.dart';
import 'package:permission_handler/permission_handler.dart';
class ScanController extends GetxController{
late CameraController cameraController;
late List cameras;
@override
void onInit() async{
super.onInit();
initCamera();
initTFLite();
}
@override
void dispose(){
super.dispose();
cameraController.dispose();
}
var isCameraInitialized = false.obs;
var cameraCount = 0;
var x,y,w,h = 0.0;
var label = "";
initCamera() async {
if(await Permission.camera.request().isGranted){
cameras = await availableCameras();
cameraController =
CameraController(cameras[0], ResolutionPreset.max, imageFormatGroup: ImageFormatGroup.yuv420);
await cameraController.initialize().then((value){
cameraController.startImageStream((image) {
cameraCount ++;
if(cameraCount % 10 == 0){
cameraCount = 0;
objectDetector(image);
}
update();
} );
});
isCameraInitialized(true);
update();
}else{
print("Permission denied");
}
}
initTFLite() async {
await Tflite.loadModel(
model: "assets/detect.tflite",
labels: "assets/label.txt",
isAsset: true,
numThreads: 1,
useGpuDelegate: false,
);
}
objectDetector(CameraImage image) async {
var detector = await Tflite.runModelOnFrame(
bytesList: image.planes.map((e){
return e.bytes;
}).toList(),
asynch: true,
imageHeight: image.height,
imageWidth: image.width,
imageMean: 127.5,
imageStd: 127.5,
rotation: 90,
threshold: 0.4,
);
if(detector != null){
var ourDetectedObject = detector.first;
if(ourDetectedObject['confidenceInClass'] * 100 > 45){
label = detector.first['detectedClass'].toString();
h = ourDetectedObject['rect']['h'];
w = ourDetectedObject['rect']['w'];
x = ourDetectedObject['rect']['x'];
y = ourDetectedObject['rect']['y'];
}
update();
}
}
}
Код: Выделить всё
import 'package:camera/camera.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:ornek12flutter/scan.dart';
class CameraView extends StatelessWidget {
const CameraView({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
body: GetBuilder(
init: ScanController(),
builder: (controller) {
return controller.isCameraInitialized.value
? Stack(
children: [
CameraPreview(controller.cameraController),
Positioned(
top: controller.y * 700,
right: controller.x * 500,
child: Container(
width: controller.w * 100 * context.width / 100,
height: controller.h * 100 * context.height / 100,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
border: Border.all(color: Colors.green, width: 4.0),
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
color: Colors.white,
child: Text(controller.label),
),
],
),
),
),
],
)
: const Center(child: Text("Loading Preview..."));
}),
);
}
}
Проверена версия Java (OpenJDK 21) и обеспечена совместимость с Gradle.
Искал в Интернете решения и просматривал документацию, но не смог найти четкого способа решения проблемы.
Чего вы ожидали?
Я ожидал своего проект для успешной сборки и запуска без каких-либо ошибок.
Подробнее здесь: https://stackoverflow.com/questions/793 ... ter-tflite
Мобильная версия