Nmh1234 2024-04-29 11:27 采纳率: 0%
浏览 8

Ubuntu运行Flutter失败

最近使用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
  • 写回答

6条回答 默认 最新

  • 阿里嘎多学长 2024-04-29 11:27
    关注

    以下内容由CHATGPT及阿里嘎多学长共同生成、有用望采纳:


    【问题概括】:这个问题的目的是解决在Ubuntu虚拟机环境下使用VS Code运行Flutter项目到真机时,出现安装步骤失败,手机在运行过程中断开连接,运行结束后又重新连接的问题。

    【问题出现原因】:

    1. 根据提供的日志信息,安装APK时出现了失败的警告,这可能是由于权限问题或者APK与当前设备不兼容导致的。
    2. 手机在安装步骤时断开连接可能是由于USB调试连接不稳定或者驱动问题。
    3. Flutter doctor显示全绿,说明环境配置基本正确。

    【问题解决方案】:

    1. 检查USB连接:确保手机与电脑的USB连接是稳定的,并且手机已经开启了USB调试模式。
    2. 检查驱动:确认Ubuntu系统是否正确安装了手机的驱动程序。
    3. 检查APK兼容性:确认编译的APK是否与当前设备的架构和Android版本兼容。
    4. 检查权限:确认安装APK时是否有足够权限,尝试使用adb install -t来允许安装未知来源的应用。
    5. 清理旧的APK:在尝试重新安装之前,使用adb uninstall <package_name>命令卸载旧的APK。
    6. 检查防火墙和安全软件:有时候防火墙或安全软件可能会阻止ADB的连接。

    【提供代码】:

    # 卸载旧的APK
    adb uninstall com.example.com_example
    
    # 重新安装APK,使用-t参数允许安装未知来源的应用
    adb install -t /path/to/app-debug.apk
    

    【代码运行方式】:

    1. 确保手机已经通过USB连接到Ubuntu虚拟机,并且开启了USB调试模式。
    2. 打开终端,输入上述代码,替换/path/to/app-debug.apk为你的APK文件的实际路径。

    【代码预期运行结果】: 如果上述步骤正确执行,且没有遇到错误,你应该能够看到APK被成功安装在手机上,并且没有出现安装失败的警告。

    【推荐相关链接】:

    评论 编辑记录

报告相同问题?

问题事件

  • 创建了问题 4月29日

悬赏问题

  • ¥15 matlab数据降噪处理,提高数据的可信度,确保峰值信号的不损失?
  • ¥15 怎么看我在bios每次修改的日志
  • ¥15 python+mysql图书管理系统
  • ¥15 Questasim Error: (vcom-13)
  • ¥15 船舶旋回实验matlab
  • ¥30 SQL 数组,游标,递归覆盖原值
  • ¥15 为什么我的数据接收的那么慢呀有没有完整的 hal 库并 代码呀有的话能不能发我一份并且我用 printf 函数显示处理之后的数据,用 debug 就不能运行了呢
  • ¥20 gitlab 中文路径,无法下载
  • ¥15 用动态规划算法均分纸牌
  • ¥30 udp socket,bind 0.0.0.0 ,如何自动选取用户访问的服务器IP来回复数据