如何修复此Flutter错误,以便在Android上运行应用程序?

wrrgggsh  于 2022-11-25  发布在  Flutter
关注(0)|答案(1)|浏览(93)

嗨,我使用的vscode与flutter扩展,并创建了一个新的项目,并没有改变任何东西,但当我尝试运行它在Android上,我只是得到这个:

Launching lib\main.dart on SDK Gphone x86 in debug mode...
lib\main.dart:1
Warning: Mapping new ns http://schemas.android.com/repository/android/common/02 to old ns http://schemas.android.com/repository/android/common/01
Warning: Mapping new ns http://schemas.android.com/repository/android/generic/02 to old ns http://schemas.android.com/repository/android/generic/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/02 to old ns http://schemas.android.com/sdk/android/repo/addon2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/02 to old ns http://schemas.android.com/sdk/android/repo/repository2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/02 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01

FAILURE: Build failed with an exception.

* Where:
Script 'D:\flutter\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 1005

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'D:\flutter\flutter\bin\flutter.bat'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 4m 1s
Exception: Gradle task assembleDebug failed with exit code 1
Exited (sigterm)

当我尝试在网络上运行它时,它工作得很完美,但当我尝试在Android模拟器或真实的的Android手机上运行它时,它会产生如上所示的相同错误。
我已经尝试清理工作区,并更新到最新的和开发版本的flutter。
flutter doctor不会产生任何错误,表示一切正常。
有人能帮忙吗?

编辑:fluttter run --verbose输出:

20:41:03.74 | LSH | D:\programming\VScode\Flutter\TestApp\test_application_1> flutter run --verbose
[ +112 ms] executing: [D:\flutter\flutter/] git -c log.showSignature=false log -n 1 --pretty=f
[ +171 ms] Exit code 0 from: git -c log.showSignature=false log -n 1 --pretty=format:%H
[   +1 ms] 4b330ddbedab445481cc73d50a4695b9154b4e4f
[   +1 ms] executing: [D:\flutter\flutter/] git tag --points-at 4b330ddbedab445481cc73d50a4695
[ +133 ms] Exit code 0 from: git tag --points-at 4b330ddbedab445481cc73d50a4695b9154b4e4f
[        ] 2.6.0-11.0.pre
[  +16 ms] executing: [D:\flutter\flutter/] git rev-parse --abbrev-ref --symbolic @{u}
[ +101 ms] Exit code 0 from: git rev-parse --abbrev-ref --symbolic @{u}
[        ] origin/dev
[        ] executing: [D:\flutter\flutter/] git ls-remote --get-url origin
[ +102 ms] Exit code 0 from: git ls-remote --get-url origin
[        ] https://github.com/flutter/flutter.git
[ +269 ms] executing: [D:\flutter\flutter/] git rev-parse --abbrev-ref HEAD
[ +104 ms] Exit code 0 from: git rev-parse --abbrev-ref HEAD
[        ] dev
[ +130 ms] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required, skipping update
[        ] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping upda
[        ] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterWebSdk' is not required, skipping update.
[   +8 ms] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'WindowsUwpEngineArtifacts' is not required, skipping update.
[   +1 ms] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update.
is not required, skipping update.                    acts' is not required, skipping update.
[  +16 ms] Artifact Instance of 'WindowsUwpEngineArtiacts' is not required, skipping update.facts' is not required, skipping update.             facts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSEngineArtifactsmbols' is not required, skipping update.' is not required, skipping update.                  id\sdk\platform-tools\adb.exe devices -l
[        ] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update.                  duct:r8qxxx model:SM_G781B device:r8q tra
[        ] Artifact Instance of 'LinuxFuchsiaSDKArtifform-tools\adb.exe -s RFCR40FYKDA shell gacts' is not required, skipping update.              Artifacts' is not required, skipping upda
[        ] Artifact Instance of 'MacOSFuchsiaSDKArtifis not required, skipping update.acts' is not required, skipping update.              facts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerSDKArti' is not required, skipping update.facts' is not required, skipping update.             ' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerDebugSyacts' is not required, skipping update.mbols' is not required, skipping update.             acts' is not required, skipping update.
[ +164 ms] Skipping pub get: version match.          facts' is not required, skipping update.
[ +224 ms] Generating D:\programming\VScode\Flutter\Tmbols' is not required, skipping update.estApp\test_application_1\android\app\src\main\java\io\flutter\plugins\GeneratedPluginRegistrant.java     estApp\test_application_1\android\app\src
[ +240 ms] ro.hardware = qcom
[ +112 ms] Initializing file store
[  +38 ms] Skipping target: gen_localizations
[  +16 ms] Skipping target:
gen_dart_plugin_registrant
[   +8 ms] Skipping target: _composite
[   +5 ms] complete
[  +17 ms] Launching lib\main.dart on SM G781B in
debug mode...
[  +17 ms]
D:\flutter\flutter\bin\cache\dart-sdk\bin\dart.exe   
--disable-dart-dev
D:\flutter\flutter\bin\cache\artifacts\engine\windows-x64\frontend_server.dart.snapshot --sdk-root        
D:\flutter\flutter\bin\cache\artifacts\engine\common\flutter_patched_sdk/ --incremental --target=flutter  
--debugger-module-names
--experimental-emit-debug-metadata
-DFLUTTER_WEB_AUTO_DETECT=true --output-dill
C:\Users\PC\AppData\Local\Temp\flutter_tools.3b35b6d3\flutter_tool.4187a6be\app.dill --packages
D:\programming\VScode\Flutter\TestApp\test_application_1\.dart_tool\package_config.json       
-Ddart.vm.profile=false -Ddart.vm.product=false
--enable-asserts --track-widget-creation
--filesystem-scheme org-dartlang-root
--initialize-from-dill
build\c075001b96339384a97db4862b8ab8db.cache.dill.track.dill
--enable-experiment=alternative-invalidation-strategy[  +37 ms] executing:
C:\Users\PC\AppData\Local\Android\sdk\platform-tools\adb.exe -s RFCR40FYKDA shell -x logcat -v time -t 1
[  +35 ms] <- compile
package:test_application_1/main.dart
[ +611 ms] --------- beginning of system
                    10-08 20:42:31.670 E/Watchdog( 1139): !@Sync: 5393 heap: 120 / 129
                    [2021-10-08 20:42:31.669] sdogWay: softdog FD: 785
[  +26 ms] executing: C:\Users\PC\AppData\Local\Android\sdk\platform-tools\adb.exe version
[  +73 ms] Android Debug Bridge version 1.0.41
           Version 31.0.3-7562133
           Installed as C:\Users\PC\AppData\Local\Android\sdk\platform-tools\adb.exe
[   +3 ms] executing: C:\Users\PC\AppData\Local\Android\sdk\platform-tools\adb.exe
start-server
[  +56 ms] Building APK
[  +28 ms] Running Gradle task 'assembleDebug'...
[   +7 ms] Using gradle from
D:\programming\VScode\Flutter\TestApp\test_application_1\android\gradlew.bat.
[ +102 ms] executing: C:\Program Files\Android\Android Studio1\jre\bin\java -version
[ +986 ms] Exit code 0 from: C:\Program Files\Android\Android Studio1\jre\bin\java -version
[   +1 ms] openjdk version "11.0.10" 2021-01-19
           OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
           OpenJDK 64-Bit Server VM (build 11.0.10+0-b96-7249189, mixed mode)
[   +3 ms] executing: [D:\programming\VScode\Flutter\TestApp\test_application_1\android/]     
D:\programming\VScode\Flutter\TestApp\test_application_1\android\gradlew.bat -Pverbose=true   
-Ptarget-platform=android-arm64
-Ptarget=D:\programming\VScode\Flutter\TestApp\test_application_1\lib\main.dart
-Pdart-defines=RkxVVFRFUl9XRUJfQVVUT19ERVRFQ1Q9dHJ1ZQ== -Pdart-obfuscation=false
-Ptrack-widget-creation=true -Ptree-shake-icons=false -Pfilesystem-scheme=org-dartlang-root   
assembleDebug
[+11333 ms] Warning: Mapping new ns http://schemas.android.com/repository/android/common/02 toold ns http://schemas.android.com/repository/android/common/01
[ +250 ms] Warning: Mapping new ns http://schemas.android.com/repository/android/generic/02 toold ns http://schemas.android.com/repository/android/generic/01
[  +35 ms] Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/02 to
old ns http://schemas.android.com/sdk/android/repo/addon2/01
[   +7 ms] Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/02
to old ns http://schemas.android.com/sdk/android/repo/repository2/01
[  +13 ms] Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/02 to
old ns http://schemas.android.com/sdk/android/repo/sys-img2/01
[+2142 ms] > Task :app:compileFlutterBuildDebug
[  +20 ms] [ +146 ms] executing: [D:\flutter\flutter/] git -c log.showSignature=false log -n 1--pretty=format:%H
[ +175 ms] [ +198 ms] Exit code 0 from: git -c log.showSignature=false log -n 1
--pretty=format:%H
[   +3 ms] [        ] 4b330ddbedab445481cc73d50a4695b9154b4e4f
[        ] [        ] executing: [D:\flutter\flutter/] git tag --points-at
4b330ddbedab445481cc73d50a4695b9154b4e4f
[+1196 ms] [+1242 ms] Exit code 0 from: git tag --points-at
4b330ddbedab445481cc73d50a4695b9154b4e4f
[   +2 ms] [        ] 2.6.0-11.0.pre
[        ] [  +16 ms] executing: [D:\flutter\flutter/] git rev-parse --abbrev-ref --symbolic  
@{u}
[ +497 ms] [ +415 ms] Exit code 0 from: git rev-parse --abbrev-ref --symbolic @{u}
[   +2 ms] [        ] origin/dev
[        ] [        ] executing: [D:\flutter\flutter/] git ls-remote --get-url origin
[ +196 ms] [ +274 ms] Exit code 0 from: git ls-remote --get-url origin
[   +2 ms] [        ] https://github.com/flutter/flutter.git
[  +96 ms] [  +90 ms] executing: [D:\flutter\flutter/] git rev-parse --abbrev-ref HEAD
[ +101 ms] [ +109 ms] Exit code 0 from: git rev-parse --abbrev-ref HEAD
[   +1 ms] [        ] dev
[ +198 ms] [ +134 ms] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required,
skipping update.
[   +3 ms] [        ] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required,
skipping update.
[   +1 ms] [        ] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping     
update.
[   +2 ms] [        ] Artifact Instance of 'FlutterWebSdk' is not required, skipping update.  
[   +1 ms] [   +5 ms] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping 
update.
[   +1 ms] [        ] Artifact Instance of 'WindowsUwpEngineArtifacts' is not required,       
skipping update.
[   +2 ms] [        ] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping
update.
[   +1 ms] [        ] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping   
update.
[   +4 ms] [        ] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required,        
skipping update.
[   +3 ms] [        ] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required,
skipping update.
[   +1 ms] [        ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required,       
skipping update.
[   +1 ms] [        ] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required,       
skipping update.
[ +175 ms] [ +183 ms] Artifact Instance of 'MaterialFonts' is not required, skipping update.
[   +2 ms] [        ] Artifact Instance of 'GradleWrapper' is not required, skipping update.
[   +2 ms] [   +7 ms] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required,   
skipping update.
[   +1 ms] [        ] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping     
update.
[   +1 ms] [        ] Artifact Instance of 'FlutterWebSdk' is not required, skipping update.  
[   +1 ms] [        ] Artifact Instance of 'FlutterSdk' is not required, skipping update.
[   +3 ms] [        ] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping
update.
[  +14 ms] [        ] Artifact Instance of 'WindowsUwpEngineArtifacts' is not required,
skipping update.
[   +4 ms] [        ] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping   
update.
[   +4 ms] [        ] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping   
update.
[   +1 ms] [        ] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required,
skipping update.
[   +4 ms] [        ] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required,        
skipping update.
[   +4 ms] [        ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required,
skipping update.
[   +9 ms] [        ] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required,
skipping update.
[   +4 ms] [        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.[   +6 ms] [        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.[   +1 ms] [        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.[   +2 ms] [        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.[   +2 ms] [        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.[   +2 ms] [        ] Artifact Instance of 'FontSubsetArtifacts' is not required, skipping    
update.
[   +1 ms] [        ] Artifact Instance of 'PubDependencies' is not required, skipping update.[   +5 ms] [  +53 ms] Initializing file store
[   +1 ms] [  +26 ms] Done initializing file store
[  +11 ms] [  +97 ms] Skipping target: gen_localizations
[ +100 ms] [  +22 ms] Skipping target: gen_dart_plugin_registrant
[ +500 ms] [ +563 ms] Skipping target: kernel_snapshot
[ +299 ms] [ +313 ms] Skipping target: debug_android_application
[   +2 ms] [        ] Persisting file store
[  +97 ms] [  +11 ms] Done persisting file store
[   +1 ms] [   +7 ms] build succeeded.
[   +5 ms] [  +29 ms] "flutter assemble" took 1’339ms.
[ +193 ms] [ +218 ms] ensureAnalyticsSent: 210ms
[   +1 ms] [   +1 ms] Running shutdown hooks
[        ] [        ] Shutdown hooks complete
[   +1 ms] [        ] exiting with code 0
[  +95 ms] > Task :app:compileFlutterBuildDebug FAILED
[   +4 ms] FAILURE: Build failed with an exception.
[   +1 ms] * Where:
[   +1 ms] Script 'D:\flutter\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 1005[   +1 ms] * What went wrong:
[   +9 ms] Execution failed for task ':app:compileFlutterBuildDebug'.
[   +4 ms] > Process 'command 'D:\flutter\flutter\bin\flutter.bat'' finished with non-zero    
exit value 1
[   +2 ms] * Try:
[        ] Run with --stacktrace option to get the stack trace. Run with --info or --debug    
option to get more log output. Run with --scan to get full insights.
[   +1 ms] * Get more help at https://help.gradle.org
[        ] BUILD FAILED in 17s
[   +1 ms] Deprecated Gradle features were used in this build, making it incompatible with    
Gradle 7.0.
[   +1 ms] Use '--warning-mode all' to show the individual deprecation warnings.
[        ] See
https://docs.gradle.org/6.7/userguide/command_line_interface.html#sec:command_line_warnings   
[   +4 ms] 1 actionable task: 1 executed
[ +507 ms] Running Gradle task 'assembleDebug'... (completed in 19.5s)
[   +6 ms] Exception: Gradle task assembleDebug failed with exit code 1
[   +4 ms] "flutter run" took 22’000ms.
[  +11 ms] 
           #0      throwToolExit (package:flutter_tools/src/base/common.dart:10:3)
           #1      RunCommand.runCommand (package:flutter_tools/src/commands/run.dart:669:9)  
           <asynchronous suspension>
           #2      FlutterCommand.run.<anonymous closure>
           (package:flutter_tools/src/runner/flutter_command.dart:1125:27)
           <asynchronous suspension>
           #3      AppContext.run.<anonymous closure>
           (package:flutter_tools/src/base/context.dart:150:19)
           <asynchronous suspension>
           #4      CommandRunner.runCommand (package:args/command_runner.dart:209:13)
           <asynchronous suspension>
           #5      FlutterCommandRunner.runCommand.<anonymous closure>
           (package:flutter_tools/src/runner/flutter_command_runner.dart:288:9)
           <asynchronous suspension>
           #6      AppContext.run.<anonymous closure>
           (package:flutter_tools/src/base/context.dart:150:19)
           <asynchronous suspension>
           #7      FlutterCommandRunner.runCommand
           (package:flutter_tools/src/runner/flutter_command_runner.dart:236:5)
           <asynchronous suspension>
           #8      run.<anonymous closure>.<anonymous closure>
(package:flutter_tools/runner.dart:62:9)
           <asynchronous suspension>
           #9      AppContext.run.<anonymous closure>
           (package:flutter_tools/src/base/context.dart:150:19)
           <asynchronous suspension>
           #10     main (package:flutter_tools/executable.dart:92:3)
           <asynchronous suspension>

[  +82 ms] ensureAnalyticsSent: 73ms
[   +5 ms] Running shutdown hooks
[   +1 ms] Shutdown hooks complete
[   +1 ms] exiting with code 1
bhmjp9jg

bhmjp9jg1#

尝试

flutter clean

然后,

flutter pub get

方法二:
gradle版本升级到7.0.2 or higher
手动方式、
gradle-wrapper.properties中更改distributionUrl

distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip

更改build.gradledependencies中的gradle版本,

classpath 'com.android.tools.build:gradle:7.0.2'

相关问题