这是调试控制台中的完整错误:
Launching lib\main.dart on Android SDK built for x86 in debug mode...
Built build\app\outputs\apk\debug\app-debug.apk.
I/FlutterActivityDelegate( 4158): onResume setting current activity to this
D/ ( 4158): HostConnection::get() New Host Connection established 0xdc74b680, tid 4178
D/EGL_emulation( 4158): eglMakeCurrent: 0xdc741300: ver 2 0 (tinfo 0xdc74c480)
F/libc ( 4158): Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0xd in tid 4177 (Thread-2), pid 4158 (le.startupnamer)
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Build fingerprint: 'google/sdk_gphone_x86/generic_x86:9/PPP4.180612.007/4860066:userdebug/dev-keys'
Revision: '0'
ABI: 'x86'
pid: 4158, tid: 4177, name: Thread-2 >>> com.example.startupnamer <<<
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0xd
Cause: null pointer dereference
eax ca0a8aac ebx ca0a8aac ecx 0000000a edx c9046c80
edi de6638d0 esi c90479f8
ebp c9046b58 esp c9046b58 eip c96e31d8
backtrace:
#00 pc 006981d8 /data/app/com.example.startupnamer-Doz3k_Pl0QfJtnmxYqiyHg==/lib/x86/libflutter.so
#01 pc 008f5b75 /data/app/com.example.startupnamer-Doz3k_Pl0QfJtnmxYqiyHg==/lib/x86/libflutter.so
#02 pc 008e87ea /data/app/com.example.startupnamer-Doz3k_Pl0QfJtnmxYqiyHg==/lib/x86/libflutter.so
#03 pc 008f3ad6 /data/app/com.example.startupnamer-Doz3k_Pl0QfJtnmxYqiyHg==/lib/x86/libflutter.so
#04 pc 008e8b2f /data/app/com.example.startupnamer-Doz3k_Pl0QfJtnmxYqiyHg==/lib/x86/libflutter.so
#05 pc 008ffb03 /data/app/com.example.startupnamer-Doz3k_Pl0QfJtnmxYqiyHg==/lib/x86/libflutter.so
#06 pc 008eb310 /data/app/com.example.startupnamer-Doz3k_Pl0QfJtnmxYqiyHg==/lib/x86/libflutter.so
#07 pc 008f3d98 /data/app/com.example.startupnamer-Doz3k_Pl0QfJtnmxYqiyHg==/lib/x86/libflutter.so
#08 pc 008e8b2f /data/app/com.example.startupnamer-Doz3k_Pl0QfJtnmxYqiyHg==/lib/x86/libflutter.so
#09 pc 008eafc8 /data/app/com.example.startupnamer-Doz3k_Pl0QfJtnmxYqiyHg==/lib/x86/libflutter.so
#10 pc 008f997f /data/app/com.example.startupnamer-Doz3k_Pl0QfJtnmxYqiyHg==/lib/x86/libflutter.so
#11 pc 008eaff8 /data/app/com.example.startupnamer-Doz3k_Pl0QfJtnmxYqiyHg==/lib/x86/libflutter.so
#12 pc 008fc81c /data/app/com.example.startupnamer-Doz3k_Pl0QfJtnmxYqiyHg==/lib/x86/libflutter.so
#13 pc 008eaf69 /data/app/com.example.startupnamer-Doz3k_Pl0QfJtnmxYqiyHg==/lib/x86/libflutter.so
#14 pc 008f997f /data/app/com.example.startupnamer-Doz3k_Pl0QfJtnmxYqiyHg==/lib/x86/libflutter.so
#15 pc 008eaff8 /data/app/com.example.startupnamer-Doz3k_Pl0QfJtnmxYqiyHg==/lib/x86/libflutter.so
#16 pc 008ef41e /data/app/com.example.startupnamer-Doz3k_Pl0QfJtnmxYqiyHg==/lib/x86/libflutter.so
#17 pc 008f0570 /data/app/com.example.startupnamer-Doz3k_Pl0QfJtnmxYqiyHg==/lib/x86/libflutter.so
#18 pc 0091433e /data/app/com.example.startupnamer-Doz3k_Pl0QfJtnmxYqiyHg==/lib/x86/libflutter.so
#19 pc 0092fad4 /data/app/com.example.startupnamer-Doz3k_Pl0QfJtnmxYqiyHg==/lib/x86/libflutter.so
#20 pc 00932f2a /data/app/com.example.startupnamer-Doz3k_Pl0QfJtnmxYqiyHg==/lib/x86/libflutter.so
#21 pc 00934573 /data/app/com.example.startupnamer-Doz3k_Pl0QfJtnmxYqiyHg==/lib/x86/libflutter.so
#22 pc 00933d2b /data/app/com.example.startupnamer-Doz3k_Pl0QfJtnmxYqiyHg==/lib/x86/libflutter.so
#23 pc 0093004a /data/app/com.example.startupnamer-Doz3k_Pl0QfJtnmxYqiyHg==/lib/x86/libflutter.so
#24 pc 0000056b <anonymous:c7680000>
Lost connection to device.
Exited (sigterm)
我正在使用带有Flutter扩展名的Visual Studio Code,但没有使用Dart扩展名。我还尝试在Android模拟器上运行Flutter应用,该模拟器是具有API 28 x86的Nexus 6。仿真性能设置为“硬件-GLES 2.0”。其余设置保留为默认设置。
在与Flutter结合使用之前,我先冷启动该模拟器,这是由于adb连接问题导致如果我正常启动该模拟器而无法加载该模拟器。可能不相关,但还是值得一提。
在命令行中输入flutter doctor -v
将显示以下内容:
[√] Flutter (Channel beta, v0.5.1, on Microsoft Windows [Version 10.0.17134.112], locale en-AU)
• Flutter version 0.5.1 at C:\dev\flutter
• Framework revision c7ea3ca377 (6 weeks ago), 2018-05-29 21:07:33 +0200
• Engine revision 1ed25ca7b7
• Dart version 2.0.0-dev.58.0.flutter-f981f09760
[√] Android toolchain - develop for Android devices (Android SDK 28.0.1)
• Android SDK at C:\Android\android-sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-28, build-tools 28.0.1
• ANDROID_HOME = C:\Android\android-sdk
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b02)
• All Android licenses accepted.
[√] Android Studio (version 3.1)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin version 26.0.1
• Dart plugin version 173.4700
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b02)
[√] IntelliJ IDEA Community Edition (version 2018.1)
• IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2018.1.2
• Flutter plugin version 26.0.2
• Dart plugin version 181.4668.60
[!] VS Code, 64-bit edition (version 1.25.0)
• VS Code at C:\Program Files\Microsoft VS Code
• Flutter extension not installed; install from
https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter
[!] Connected devices
! No devices available
! Doctor found issues in 2 categories.
现在是实际问题了:
当我加载Flutter应用程序时,无论代码处于哪种状态,该应用程序都会从创建后第一次保存它时的状态启动。如果我尝试对代码进行任何更改(我只是更改主题颜色)并尝试热重装,则应用程序将崩溃,并显示我上面发布的错误。为什么会发生这种情况,我该怎么解决?
加载项目或不更改代码进行热加载时都没有错误。
感谢您的帮助。
编辑:我无法使用同一项目在Android Studio中复制此错误。此错误仅对我显示在Visual Studio代码中。
答案 0 :(得分:0)
您发布的第一个错误是当机,应该为raised on GitHub。应该有某种方式来符号化堆栈跟踪(因此它具有真实的方法名称等),但是我找不到用于它的指令。我不确定这可能与this或this相同。
我正在使用带有Flutter扩展名的Visual Studio Code,但没有使用Dart扩展名。
在这里不相关,但是仅供参考,Flutter扩展依赖于Dart扩展,因此安装Flutter会自动安装Dart。
当我加载Flutter应用程序时,无论代码处于哪种状态,该应用程序都会从创建后第一次保存它时的状态启动。
这听起来像this issue;值得一提的是,您在那里拥有它来帮助收集信息(我不确定Flutter团队中是否有人能够在本地复制该信息以进行调试)。
编辑:我无法使用同一项目在Android Studio中复制此错误。此错误仅对我显示在Visual Studio代码中。
两个IDE都使用相同的工具,因此环境之间可能存在细微的差异(例如,我认为大多数人在IntelliJ / Android Studio中都没有调试器的情况下运行,但在VS Code中默认情况下带有调试器)。您可以在VS Code fairly easily中捕获日志,但我不知道IntelliJ / Android Studio是否具有可比较的功能。
答案 1 :(得分:0)
我找到“ 与设备的连接断开”的原因
添加 contacts_service 依赖项
后,我发现了此问题如果您安装了需要用户权限的任何插件,但尚未以编程方式获得权限,则发现此错误。
要手动解决此问题
要以编程方式解决此问题。
答案 2 :(得分:0)
我设法将其修复在我的机器上。对我来说,诀窍是切换稳定的频道并使用以下命令更新抖动:
-flutter upgrade
-flutter pub get
答案 3 :(得分:0)
2个月以来,我一直出现此错误,我能够使用热重载模式。解决了此问题,只需更换我们的移动充电电缆并使用USB电缆进行调试,希望可以为您提供帮助,如果可以,请投票。< / p>
答案 4 :(得分:0)
只需更新您的拍动
$ flutter升级--force
对我来说很好 试试吧
答案 5 :(得分:0)
我有类似的问题。升级对我没有帮助。
仅当我尝试从相机或画廊上传照片时,该应用程序才会失去连接。
错误-这是我的图片上传页面
W/ThreadedRenderer( 7044): ThreadedRenderer::detachAnimators pid = 7044 threadid = 7089
V/PhoneWindow( 7044): DecorView setVisiblity: visibility = 4, Parent = ViewRoot{2fd9ffd com.finde.med/com.finde.med.MainActivity,ident = 0}, this = DecorView@e0877a7[MainActivity]
W/ThreadedRenderer( 7044): ThreadedRenderer::detachAnimators pid = 7044 threadid = 7089
Lost connection to device.
Exited (sigterm)
代码片段
import 'dart:io';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:firebase_storage/firebase_storage.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:findemed/models/user.dart';
import 'package:findemed/pages/home.dart';
import 'package:findemed/widgets/progress.dart';
import 'package:geolocator/geolocator.dart';
import 'package:image_picker/image_picker.dart';
import 'package:path_provider/path_provider.dart';
import 'package:image/image.dart' as Im;
import 'package:uuid/uuid.dart';
class Upload extends StatefulWidget {
final User currentUser;
Upload({this.currentUser});
@override
_UploadState createState() => _UploadState();
}
class _UploadState extends State<Upload>
with AutomaticKeepAliveClientMixin<Upload> {
TextEditingController captionController = TextEditingController();
TextEditingController locationController = TextEditingController();
File file;
bool isUploading = false;
String postId = Uuid().v4();
handleTakePhoto() async {
Navigator.pop(context);
File file = await ImagePicker.pickImage(
source: ImageSource.camera,
maxHeight: 675,
maxWidth: 960,
);
setState(() {
this.file = file;
});
}
handleChooseFromGallery() async {
Navigator.pop(context);
File file = await ImagePicker.pickImage(source: ImageSource.gallery);
setState(() {
this.file = file;
});
}
selectImage(parentContext) {
return showDialog(
context: parentContext,
builder: (context) {
return SimpleDialog(
title: Text("Create Post"),
children: <Widget>[
SimpleDialogOption(
child: Text("Photo with Camera"), onPressed: handleTakePhoto),
SimpleDialogOption(
child: Text("Image from Gallery"),
onPressed: handleChooseFromGallery),
SimpleDialogOption(
child: Text("Cancel"),
onPressed: () => Navigator.pop(context),
)
],
);
},
);
}
Container buildSplashScreen() {
return Container(
color: Theme.of(context).primaryColor.withOpacity(0.6),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SvgPicture.asset('assets/images/upload.svg', height: 170.0),
Padding(
padding: EdgeInsets.only(top: 50.0),
child: RaisedButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15.0),
),
child: Text(
"Upload Image",
style: TextStyle(
color: Colors.white,
fontSize: 16.0,
),
),
color: Theme.of(context).accentColor,
onPressed: () => selectImage(context)),
),
],
),
);
}
clearImage() {
setState(() {
file = null;
});
}
compressImage() async {
final tempDir = await getTemporaryDirectory();
final path = tempDir.path;
Im.Image imageFile = Im.decodeImage(file.readAsBytesSync());
final compressedImageFile = File('$path/img_$postId.jpg')
..writeAsBytesSync(Im.encodeJpg(imageFile, quality: 85));
setState(() {
file = compressedImageFile;
});
}
Future<String> uploadImage(imageFile) async {
StorageUploadTask uploadTask =
storageRef.child("post_$postId.jpg").putFile(imageFile);
StorageTaskSnapshot storageSnap = await uploadTask.onComplete;
String downloadUrl = await storageSnap.ref.getDownloadURL();
return downloadUrl;
}
createPostInFirestore(
{String mediaUrl, String location, String description}) {
postsRef
.document(widget.currentUser.id)
.collection("userPosts")
.document(postId)
.setData({
"postId": postId,
"ownerId": widget.currentUser.id,
"username": widget.currentUser.username,
"mediaUrl": mediaUrl,
"description": description,
"location": location,
"timestamp": timestamp,
"likes": {},
});
}
handleSubmit() async {
setState(() {
isUploading = true;
});
await compressImage();
String mediaUrl = await uploadImage(file);
createPostInFirestore(
mediaUrl: mediaUrl,
location: locationController.text,
description: captionController.text,
);
captionController.clear();
locationController.clear();
setState(() {
file = null;
isUploading = false;
postId = Uuid().v4();
});
}
Scaffold buildUploadForm() {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.white70,
leading: IconButton(
icon: Icon(Icons.arrow_back, color: Colors.black),
onPressed: clearImage),
title: Text(
"Caption Post",
style: TextStyle(color: Colors.black),
),
actions: [
FlatButton(
onPressed: isUploading ? null : () => handleSubmit(),
child: Text(
"Post",
style: TextStyle(
color: Colors.blueAccent,
fontWeight: FontWeight.bold,
fontSize: 20.0,
),
),
),
],
),
body: ListView(
children: <Widget>[
isUploading ? linearProgress(context) : Text(""),
Container(
height: 220.0,
width: MediaQuery.of(context).size.width * 0.8,
child: Center(
child: AspectRatio(
aspectRatio: 16 / 9,
child: Container(
decoration: BoxDecoration(
image: DecorationImage(
fit: BoxFit.cover,
image: FileImage(file),
),
),
),
),
),
),
Padding(
padding: EdgeInsets.only(top: 10.0),
),
ListTile(
leading: CircleAvatar(
backgroundImage:
CachedNetworkImageProvider(widget.currentUser.photoUrl),
),
title: Container(
width: 250.0,
child: TextField(
controller: captionController,
decoration: InputDecoration(
hintText: "Write a caption...",
border: InputBorder.none,
),
),
),
),
Divider(),
ListTile(
leading: Icon(
Icons.pin_drop,
color: Colors.orange,
size: 35.0,
),
title: Container(
width: 250.0,
child: TextField(
controller: locationController,
decoration: InputDecoration(
hintText: "Where was this photo taken?",
border: InputBorder.none,
),
),
),
),
Container(
width: 200.0,
height: 100.0,
alignment: Alignment.center,
child: RaisedButton.icon(
label: Text(
"Usef Current Location",
style: TextStyle(color: Colors.white),
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30.0),
),
color: Colors.blue,
onPressed: getUserLocation,
icon: Icon(
Icons.my_location,
color: Colors.white,
),
),
),
],
),
);
}
getUserLocation() async {
Position position = await Geolocator()
.getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
List<Placemark> placemarks = await Geolocator()
.placemarkFromCoordinates(position.latitude, position.longitude);
Placemark placemark = placemarks[0];
String completeAddress =
'${placemark.subThoroughfare} ${placemark.thoroughfare}, ${placemark.subLocality} ${placemark.locality}, ${placemark.subAdministrativeArea}, ${placemark.administrativeArea} ${placemark.postalCode}, ${placemark.country}';
print(completeAddress);
String formattedAddress = "${placemark.locality}, ${placemark.country}";
locationController.text = formattedAddress;
}
bool get wantKeepAlive => true;
@override
Widget build(BuildContext context) {
super.build(context);
return file == null ? buildSplashScreen() : buildUploadForm();
}
}
我也收到有关图像选择器的警告
{
"resource": "/F:/_dev/findemed/lib/pages/upload.dart",
"owner": "dart",
"code": {
"value": "deprecated_member_use",
"target": {
"$mid": 1,
"external": "https://dart.dev/tools/diagnostic-messages#deprecated_member_use",
"path": "/tools/diagnostic-messages",
"scheme": "https",
"authority": "dart.dev",
"fragment": "deprecated_member_use"
}
},
"severity": 2,
**"message": "' pickImage ' is deprecated and shouldn't be used. Use imagePicker.getImage() method instead..\nTry replacing the use of the deprecated member with the replacement.",
"source": "dart",
"startLineNumber": 47,
"startColumn": 35,
"endLineNumber": 47,
"endColumn": 44,
"tags": [
2
]
}
```**