Flutter集成honeywell_scanner插件编译及依赖问题求助
问题
初始编译错误
执行任务:honeywell_scanner:compileDebugJavaWithJavac失败,编译输出错误信息如下:
symbol: variable BarcodeReader location: class HoneywellScannerNative /Users/ddo/development/flutter/.pub-cache/hosted/pub.dartlang.org/honeywell_scanner-3.2.0+13/android/src/main/java/com/plugin/flutter/honeywell_scanner/HoneywellScannerNative.java:108: error: cannot find symbol properties.put(BarcodeReader.PROPERTY_UPC_E_ENABLED, true); ^ symbol: variable BarcodeReader location: class HoneywellScannerNative Note: /Users/ddo/development/flutter/.pub-cache/hosted/pub.dartlang.org/honeywell_scanner-3.2.0+13/android/src/main/java/com/plugin/flutter/honeywell_scanner/HoneywellScannerPlugin.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. 37 errors
构建提示:编译失败,需查看编译器错误输出详情。
后续依赖错误
编辑后再次构建失败,错误信息:
无法确定:app:mergeDebugAssets任务的依赖关系,无法解析:app:debugRuntimeClasspath配置的所有任务依赖,找不到匹配的:honeywell项目配置,该依赖由:app > :honeywell_scanner所需。消费者配置要求找到符合以下属性的运行时组件:
com.android.build.api.attributes.BuildTypeAttr值为'debug'com.android.build.api.attributes.AgpVersionAttr值为'7.2.2'org.jetbrains.kotlin.platform.type值为'androidJvm'
但所有可用配置均无对应属性。
项目配置文件
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="com.example.deneme_kaynak"> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.CAMERA" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <application android:name="${applicationName}" android:label="deneme_kaynak" android:icon="@mipmap/launcher_icon" android:requestLegacyExternalStorage="true" android:usesCleartextTraffic="true"> <activity android:name=".MainActivity" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" android:exported="true" android:hardwareAccelerated="true" android:launchMode="singleTop" android:theme="@style/LaunchTheme" android:windowSoftInputMode="adjustResize"> <!-- Specifies an Android theme to apply to this Activity as soon as the Android process has started. This theme is visible to the user while the Flutter UI initializes. After that, this theme continues to determine the Window background behind the Flutter UI. --> <meta-data android:name="io.flutter.embedding.android.NormalTheme" android:resource="@style/NormalTheme" /> <meta-data android:name="io.flutter.embedding.android.SplashScreenDrawable" android:resource="@drawable/launch_background" /> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <!-- Don't delete the meta-data below. This is used by the Flutter tool to generate GeneratedPluginRegistrant.java --> <receiver android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationBootReceiver" android:exported="false"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED"></action> </intent-filter> </receiver> <receiver android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationReceiver" /> <meta-data android:name="flutterEmbedding" android:value="2" /> </application> </manifest>
app/build.gradle
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 FileNotFoundException("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 33 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.deneme_kaynak" // 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 29 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 } } } flutter { source '../..' } dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" }
根目录build.gradle
buildscript { ext.kotlin_version = '1.6.10' repositories { google() mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:7.2.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') } task clean(type: Delete) { delete rootProject.buildDir }
解决方案
解决初始编译错误(找不到BarcodeReader)
错误原因是honeywell_scanner插件未正确引入霍尼韦尔扫描SDK依赖,修复步骤:
- 打开本地插件缓存目录:
/Users/ddo/development/flutter/.pub-cache/hosted/pub.dartlang.org/honeywell_scanner-3.2.0+13/android/ - 编辑该目录下的
build.gradle,在dependencies块中添加霍尼韦尔SDK依赖:
版本号可根据插件兼容性调整dependencies { implementation 'com.honeywell.scanning:scanedge:1.13.0.5' } - 返回项目根目录,执行
flutter clean和flutter pub get,重新编译项目
若不想修改缓存插件,可在项目android/build.gradle中全局添加该依赖,或使用patch插件持久化修改。
解决依赖解析错误
错误原因是插件依赖的:honeywell模块不存在,或Gradle配置冲突,修复步骤:
- 确认项目中无本地
:honeywell模块,若没有则说明插件配置错误,需确保插件引用的是远程SDK而非本地模块 - 编辑根目录
build.gradle,删除干扰依赖解析的配置:// 注释或删除以下块 // subprojects { // project.evaluationDependsOn(':app') // } - 确保
allprojects块中的repositories包含google()和mavenCentral(),保证Gradle能下载SDK依赖 - 执行
flutter clean、flutter pub get后重新构建项目
另外,建议尝试升级honeywell_scanner插件至最新版本,新版本可能已修复此类兼容性问题。
内容的提问来源于stack exchange,提问作者Umutcan Bağdu
相关产品推荐
相关产品推荐

