最近使用Flutter开发app,因为要编译厂商的插件需要使用Linux,我在电脑上安装了Ubuntu虚拟机。但是在vscode上运行flutter项目到真机时一直失败,查看了日志也没有特别详细的信息,发现每次运行到安装步骤时,手机会突然断开,当flutter run结束时就又会连接手机,查了好久没有找到原因。
flutter doctor也是全绿的
Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you trust this source!
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.19.6, on Ubuntu 22.04.4 LTS 6.5.0-28-generic, locale zh_CN.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Chrome - develop for the web
[✓] Linux toolchain - develop for Linux desktop
[✓] Android Studio (version 2023.2)
[✓] VS Code (version 1.88.1)
[✓] Connected device (3 available)
[✓] Network resources
以下是部分日志
✓ Built build/app/outputs/flutter-apk/app-debug.apk.
[ +1 ms] executing: /home/xxx/Android/Sdk/build-tools/34.0.0/aapt dump xmltree /home/xxx/flutter_project/com_example/com_example/build/app/outputs/flutter-apk/app-debug.apk AndroidManifest.xml
[ +11 ms] Exit code 0 from: /home/xxx/Android/Sdk/build-tools/34.0.0/aapt dump xmltree /home/xxx/flutter_project/com_example/com_example/build/app/outputs/flutter-apk/app-debug.apk AndroidManifest.xml
[ ] N: android=http://schemas.android.com/apk/res/android
E: manifest (line=2)
A: android:versionCode(0x0101021b)=(type 0x10)0x1
A: android:versionName(0x0101021c)="1.0.0" (Raw: "1.0.0")
A: android:compileSdkVersion(0x01010572)=(type 0x10)0x22
A: android:compileSdkVersionCodename(0x01010573)="14" (Raw: "14")
A: package="com.example.com_example" (Raw: "com.example.com_example")
A: platformBuildVersionCode=(type 0x10)0x22
A: platformBuildVersionName=(type 0x10)0xe
E: uses-sdk (line=7)
A: android:minSdkVersion(0x0101020c)=(type 0x10)0x15
A: android:targetSdkVersion(0x01010270)=(type 0x10)0x21
E: uses-permission (line=15)
A: android:name(0x01010003)="android.permission.INTERNET" (Raw: "android.permission.INTERNET")
E: uses-permission (line=16)
A: android:name(0x01010003)="android.permission.BLUETOOTH" (Raw: "android.permission.BLUETOOTH")
A: android:maxSdkVersion(0x01010271)=(type 0x10)0x1e
E: uses-permission (line=19)
A: android:name(0x01010003)="android.permission.BLUETOOTH_ADMIN" (Raw: "android.permission.BLUETOOTH_ADMIN")
A: android:maxSdkVersion(0x01010271)=(type 0x10)0x1e
E: uses-permission (line=22)
A: android:name(0x01010003)="android.permission.BLUETOOTH_SCAN" (Raw: "android.permission.BLUETOOTH_SCAN")
E: uses-permission (line=23)
A: android:name(0x01010003)="android.permission.BLUETOOTH_ADVERTISE" (Raw: "android.permission.BLUETOOTH_ADVERTISE")
E: uses-permission (line=24)
A: android:name(0x01010003)="android.permission.BLUETOOTH_CONNECT" (Raw: "android.permission.BLUETOOTH_CONNECT")
E: uses-permission (line=25)
A: android:name(0x01010003)="android.permission.FOREGROUND_SERVICE" (Raw: "android.permission.FOREGROUND_SERVICE")
E: uses-permission (line=26)
A: android:name(0x01010003)="android.permission.ACCESS_BACKGROUND_LOCATION" (Raw: "android.permission.ACCESS_BACKGROUND_LOCATION")
E: uses-permission (line=43)
A: android:name(0x01010003)="android.permission.WRITE_EXTERNAL_STORAGE" (Raw: "android.permission.WRITE_EXTERNAL_STORAGE")
E: uses-permission (line=44)
A: android:name(0x01010003)="android.permission.READ_EXTERNAL_STORAGE" (Raw: "android.permission.READ_EXTERNAL_STORAGE")
E: uses-permission (line=45)
A: android:name(0x01010003)="android.permission.ACCESS_COARSE_LOCATION" (Raw: "android.permission.ACCESS_COARSE_LOCATION")
E: uses-permission (line=46)
A: android:name(0x01010003)="android.permission.ACCESS_FINE_LOCATION" (Raw: "android.permission.ACCESS_FINE_LOCATION")
E: permission (line=48)
A: android:name(0x01010003)="com.example.com_example.DYNAMIC_RECEIVER_NOT_EXPORTED_PERMISSION" (Raw: "com.example.com_example.DYNAMIC_RECEIVER_NOT_EXPORTED_PERMISSION")
A: android:protectionLevel(0x01010009)=(type 0x11)0x2
E: uses-permission (line=52)
A: android:name(0x01010003)="com.example.com_example.DYNAMIC_RECEIVER_NOT_EXPORTED_PERMISSION" (Raw: "com.example.com_example.DYNAMIC_RECEIVER_NOT_EXPORTED_PERMISSION")
E: application (line=54)
A: android:label(0x01010001)="demo_debug" (Raw: "demo_debug")
A: android:icon(0x01010002)=@0x7f080000
A: android:name(0x01010003)="android.app.Application" (Raw: "android.app.Application")
A: android:debuggable(0x0101000f)=(type 0x12)0xffffffff
A: android:appComponentFactory(0x0101057a)="androidx.core.app.CoreComponentFactory" (Raw: "androidx.core.app.CoreComponentFactory")
E: activity (line=60)
A: android:theme(0x01010000)=@0x7f0a0000
A: android:name(0x01010003)="com.example.com_example.MainActivity" (Raw: "com.example.com_example.MainActivity")
A: android:exported(0x01010010)=(type 0x12)0xffffffff
A: android:launchMode(0x0101001d)=(type 0x10)0x1
A: android:configChanges(0x0101001f)=(type 0x11)0x40003fb4
A: android:windowSoftInputMode(0x0101022b)=(type 0x11)0x10
A: android:hardwareAccelerated(0x010102d3)=(type 0x12)0xffffffff
E: meta-data (line=75)
A: android:name(0x01010003)="io.flutter.embedding.android.NormalTheme" (Raw: "io.flutter.embedding.android.NormalTheme")
A: android:resource(0x01010025)=@0x7f0a0001
E: intent-filter (line=79)
E: action (line=80)
A: android:name(0x01010003)="android.intent.action.MAIN" (Raw: "android.intent.action.MAIN")
E: category (line=82)
A: android:name(0x01010003)="android.intent.category.LAUNCHER" (Raw: "android.intent.category.LAUNCHER")
E: meta-data (line=89)
A: android:name(0x01010003)="flutterEmbedding" (Raw: "flutterEmbedding")
A: android:value(0x01010024)=(type 0x10)0x2
E: activity (line=93)
A: android:theme(0x01010000)=@0x01030007
A: android:name(0x01010003)="io.flutter.plugins.urllauncher.WebViewActivity" (Raw: "io.flutter.plugins.urllauncher.WebViewActivity")
A: android:exported(0x01010010)=(type 0x12)0x0
E: service (line=98)
A: android:name(0x01010003)="com.lyokone.location.FlutterLocationService" (Raw: "com.lyokone.location.FlutterLocationService")
A: android:enabled(0x0101000e)=(type 0x12)0xffffffff
A: android:exported(0x01010010)=(type 0x12)0x0
A: android:foregroundServiceType(0x01010599)=(type 0x11)0x8
E: activity (line=104)
A: android:theme(0x01010000)=@0x01030010
A: android:name(0x01010003)="com.google.android.gms.common.api.GoogleApiActivity" (Raw: "com.google.android.gms.common.api.GoogleApiActivity")
A: android:exported(0x01010010)=(type 0x12)0x0
E: meta-data (line=109)
A: android:name(0x01010003)="com.google.android.gms.version" (Raw: "com.google.android.gms.version")
A: android:value(0x01010024)=@0x7f060000
E: uses-library (line=113)
A: android:name(0x01010003)="androidx.window.extensions" (Raw: "androidx.window.extensions")
A: android:required(0x0101028e)=(type 0x12)0x0
E: uses-library (line=116)
A: android:name(0x01010003)="androidx.window.sidecar" (Raw: "androidx.window.sidecar")
A: android:required(0x0101028e)=(type 0x12)0x0
[ +2 ms] Stopping app 'app-debug.apk' on VOG AL00.
[ ] executing: /home/xxx/Android/Sdk/platform-tools/adb -s MQS7N19501015597 shell am force-stop com.example.com_example
[ +66 ms] executing: /home/xxx/Android/Sdk/platform-tools/adb -s MQS7N19501015597 shell pm list packages com.example.com_example
[ +62 ms] Installing APK.
[ +1 ms] Installing build/app/outputs/flutter-apk/app-debug.apk...
[ ] executing: /home/xxx/Android/Sdk/platform-tools/adb -s MQS7N19501015597 install -t -r /home/xxx/flutter_project/com_example/com_example/build/app/outputs/flutter-apk/app-debug.apk
[ +91 ms] Performing Streamed Install
adb: failed to install /home/xxx/flutter_project/com_example/com_example/build/app/outputs/flutter-apk/app-debug.apk:
[ +1 ms] Installing build/app/outputs/flutter-apk/app-debug.apk... (completed in 92ms)
[ ] Warning: Failed to install APK.
[+1721 ms] "flutter run" took 9,931ms.
[ +114 ms] ensureAnalyticsSent: 113ms
[ ] Running 1 shutdown hook
[ +8 ms] Shutdown hooks complete
[ +1 ms] exiting with code 1