我正在尝试使用dart包(https://pub.dev/packages/nfc_emulator)在flutter应用程序中创建nfc模拟器
我已将模拟器服务添加到AndroidManifest.xml文件中,然后开始出现构建错误。
这是AndroidManifest.xml的模拟器服务标签。
<service
android:name="io.flutter.plugins.nfc_emulator.NfcEmulatorService"
android:exported="true"
android:permission="android.permission.BIND_NFC_SERVICE">
<!-- Intent filter indicating that we support card emulation. -->
<intent-filter>
<action android:name="android.nfc.cardemulation.action.HOST_APDU_SERVICE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<!--
Required XML configuration file, listing the AIDs that we are emulating cards
for. This defines what protocols our card emulation service supports.
-->
<meta-data
android:name="android.nfc.cardemulation.host_apdu_service"
android:resource="@xml/aid_list" />
</service>
这是我的 dart 代码:
class NFC extends StatefulWidget {
@override
State<NFC> createState() => _NFCState();
}
class _NFCState extends State<NFC> {
// BottomSheetWidget({super.key});
TextEditingController controller = TextEditingController();
TextEditingController ctrl = TextEditingController();
String _platformVersion = 'Unknown';
NfcStatus _nfcStatus = NfcStatus.unknown;
bool _started = false;
@override
void initState() {
super.initState();
initPlatformState();
}
Future<void> initPlatformState() async {
String? platformVersion;
NfcStatus nfcStatus = NfcStatus.unknown;
try {
platformVersion = await NfcEmulator.platformVersion;
nfcStatus = await NfcEmulator.nfcStatus;
} on PlatformException {
platformVersion = 'Failed to get platform version.';
}
if (!mounted) return;
setState(() {
_platformVersion = platformVersion ?? 'Unknown';
_nfcStatus = nfcStatus;
});
}
@override
Widget build(BuildContext context) {
return Container(
height: 800,
color: Colors.white,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
// mainAxisSize: MainAxisSize.min,
children: <Widget>[
Padding(
padding: EdgeInsets.only(top: 8),
child: Text('Add details'),
),
TextField(controller: controller, hint: 'cardAid'),
TextField(
controller: ctrl,
hint: 'cardUid',
),
TextButton(
onPressed: () {
startStopEmulator();
},
child: Text('Submit'))
],
),
),
);
}
void startStopEmulator() async {
if (_started) {
await NfcEmulator.stopNfcEmulator();
} else {
await NfcEmulator.startNfcEmulator(
controller.text,
ctrl.text,
);
//}
}
}
这是我得到的构建错误。
Exception: Gradle task assembleDebug failed with exit code 1
我开始在添加模拟器服务时出错。
1条答案
按热度按时间mklgxw1f1#
minSdkVersion必须为19。
您可以更改Android〉应用程序〉build.gradle最小sdk到上限,然后19.
示例:
最小Sdk版本21目标Sdk版本31编译Sdk版本33