我用android建立了一个flutter环境。
$ flutter --version
Flutter 3.0.1 • channel stable • https://github.com/flutter/flutter.git
Framework • revision fb57da5f94 (2 weeks ago) • 2022-05-19 15:50:29 -0700
Engine • revision caaafc5604
Tools • Dart 2.17.1 • DevTools 2.12.2
$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.0.1, on Linux Mint 20.3 5.4.0-113-generic, locale
en_US.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK version
32.1.0-rc1)
[✓] Chrome - develop for the web
[✓] Linux toolchain - develop for Linux desktop
[✓] Android Studio (version 2021.2)
[✓] VS Code (version 1.67.2)
[✓] Connected device (3 available)
[✓] HTTP Host Availability
• No issues found!
$ adb devices
List of devices attached
AROFQV5V8LJ device
之后,我创建了一个新的flutter项目,并试图在上面显示的物理设备(AROFQV5V8LJ,智能手机)上运行该项目,但它不起作用:
$ flutter create key_borrow
$ cd key_borrow
$ flutter run
FAILURE: Build failed with an exception.
* What went wrong:
Gradle could not start your build.
> Could not create service of type BuildLifecycleController using ServicesProvider.createBuildLifecycleController().
> Could not create service of type GradleInternal using ServicesProvider.createGradleModel().
> Could not create an instance of type org.gradle.invocation.DefaultGradle.
> Could not configure services using GradleScopeCompileServices.configure().
* 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 644ms
Running Gradle task 'assembleDebug'... 1,292ms
Exception: Gradle task assembleDebug failed with exit code 1
我已经尝试了所有的方法,包括卸载和重新安装所有的环境。一些我已经尝试过的例子:
$ ./android/gradlew clean
$ ./android/gradlew build
$ flutter clean
$ flutter pub get
$ flutter run
所有这些命令运行没有错误,但当我试图运行或构建应用程序(与flutter cli),它总是返回相同的错误上面。
此外,我试图将./android/app/build.gradle
上的compileSdkVersion
和targetSdkVersion
更改为版本32(最新),仍然得到相同的错误。gradle版本也是如此:我做了一些降级,没有任何变化。
我也尝试在android studio上打开项目:它没有显示文件上的任何错误,但当我尝试运行它时,我仍然得到相同的错误。
有人知道吗?
编辑:
运行:
$ flutter run -v
[ +56 ms] executing: uname -m
[ +26 ms] Exit code 0 from: uname -m
[ ] x86_64
[ +5 ms] executing: [/home/bbb/app/flutter/] git -c log.showSignature=false
log -n 1 --pretty=format:%H
[ +9 ms] Exit code 0 from: git -c log.showSignature=false log -n 1
--pretty=format:%H
[ ] fb57da5f945d02ef4f98dfd9409a72b7cce74268
[ ] executing: [/home/bbb/app/flutter/] git tag --points-at
fb57da5f945d02ef4f98dfd9409a72b7cce74268
[ +12 ms] Exit code 0 from: git tag --points-at
fb57da5f945d02ef4f98dfd9409a72b7cce74268
[ ] 3.0.1
[ +7 ms] executing: [/home/bbb/app/flutter/] git rev-parse --abbrev-ref
--symbolic @{u}
[ +5 ms] Exit code 0 from: git rev-parse --abbrev-ref --symbolic @{u}
[ ] origin/stable
[ ] executing: [/home/bbb/app/flutter/] git ls-remote --get-url origin
[ +4 ms] Exit code 0 from: git ls-remote --get-url origin
[ ] https://github.com/flutter/flutter.git
[ +78 ms] executing: [/home/bbb/app/flutter/] git rev-parse --abbrev-ref HEAD
[ +5 ms] Exit code 0 from: git rev-parse --abbrev-ref HEAD
[ ] stable
[ +50 ms] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required,
skipping update.
[ ] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required,
skipping update.
[ ] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping
update.
[ ] Artifact Instance of 'FlutterWebSdk' is not required, skipping
update.
[ +3 ms] Artifact Instance of 'WindowsEngineArtifacts' is not required,
skipping update.
[ ] Artifact Instance of 'WindowsUwpEngineArtifacts' is not required,
skipping update.
[ ] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping
update.
[ ] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping
update.
[ ] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required,
skipping update.
[ ] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required,
skipping update.
[ ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required,
skipping update.
[ ] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required,
skipping update.
[ +55 ms] executing: /home/bbb/app/Android/Sdk/platform-tools/adb devices -l
[ +39 ms] List of devices attached
ROFQVSJBU845V8LJ device usb:1-3 product:maltose_global
model:MK15357EA device:maltose transport_id:3
[ +5 ms] /home/bbb/app/Android/Sdk/platform-tools/adb -s ROFQVSJBU845V8LJ
shell getprop
[ +114 ms] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required,
skipping update.
[ +2 ms] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping
update.
[ +2 ms] Artifact Instance of 'WindowsEngineArtifacts' is not required,
skipping update.
[ ] Artifact Instance of 'WindowsUwpEngineArtifacts' is not required,
skipping update.
[ ] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping
update.
[ +2 ms] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required,
skipping update.
[ ] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required,
skipping update.
[ ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required,
skipping update.
[ ] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required,
skipping update.
[ +111 ms] Skipping pub get: version match.
[ +55 ms] Generating
/home/bbb/key_borrow/android/app/src/main/java/io/flutter/plugins/GeneratedPlug
inRegistrant.java
[ +53 ms] ro.hardware = mt6785
[ ] ro.build.characteristics = default
[ +35 ms] Initializing file store
[ +11 ms] Skipping target: gen_localizations
[ +5 ms] gen_dart_plugin_registrant: Starting due to
{InvalidatedReasonKind.inputChanged: The following inputs have updated contents:
/home/bbb/key_borrow/.dart_tool/package_config_subset}
[ +21 ms] gen_dart_plugin_registrant: Complete
[ ] Skipping target: _composite
[ +1 ms] complete
[ +5 ms] Launching lib/main.dart on MK15357EA in debug mode...
[ +4 ms] /home/bbb/app/flutter/bin/cache/dart-sdk/bin/dart --disable-dart-dev
/home/bbb/app/flutter/bin/cache/dart-sdk/bin/snapshots/frontend_server.dart.sna
pshot --sdk-root
/home/bbb/app/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
/tmp/flutter_tools.CZNSCU/flutter_tool.GZIXAJ/app.dill --packages
/home/bbb/key_borrow/.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
[ +11 ms] executing: /home/bbb/app/Android/Sdk/platform-tools/adb -s
ROFQVSJBU845V8LJ shell -x logcat -v time -t 1
[ +13 ms] <- compile package:key_borrow/main.dart
[ +122 ms] --------- beginning of main
06-05 07:06:42.514 W/getprop (17384): type=1400
audit(0.0:1285517): avc: denied { map } for
path="/dev/__properties__/u:object_r:vendor_fp_prop:s0"
dev="tmpfs" ino=1297 scontext=u:r:shell:s0
tcontext=u:object_r:vendor_fp_prop:s0 tclass=file
permissive=0
[ +15 ms] executing: /home/bbb/app/Android/Sdk/platform-tools/adb version
[ +6 ms] Android Debug Bridge version 1.0.41
Version 33.0.2-8557947
Installed as /home/bbb/app/Android/Sdk/platform-tools/adb
[ +2 ms] executing: /home/bbb/app/Android/Sdk/platform-tools/adb start-server
[ +6 ms] Building APK
[ +16 ms] Running Gradle task 'assembleDebug'...
[ +2 ms] Using gradle from /home/bbb/key_borrow/android/gradlew.
[ +19 ms] executing: /home/bbb/app/android-studio/jre/bin/java -version
[ +110 ms] Exit code 0 from: /home/bbb/app/android-studio/jre/bin/java -version
[ ] openjdk version "11.0.12" 2021-07-20
OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
OpenJDK 64-Bit Server VM (build 11.0.12+0-b1504.28-7817840, mixed
mode)
[ +1 ms] executing: [/home/bbb/key_borrow/android/]
/home/bbb/key_borrow/android/gradlew -Pverbose=true
-Ptarget-platform=android-arm64 -Ptarget=/home/bbb/key_borrow/lib/main.dart
-Pbase-application-name=android.app.Application
-Pdart-defines=RkxVVFRFUl9XRUJfQVVUT19ERVRFQ1Q9dHJ1ZQ== -Pdart-obfuscation=false
-Ptrack-widget-creation=true -Ptree-shake-icons=false
-Pfilesystem-scheme=org-dartlang-root assembleDebug
[ +875 ms] FAILURE: Build failed with an exception.
[ +1 ms] * What went wrong:
[ ] Gradle could not start your build.
[ ] > Could not create service of type BuildLifecycleController using
ServicesProvider.createBuildLifecycleController().
[ ] > Could not create service of type GradleInternal using
ServicesProvider.createGradleModel().
[ ] > Could not create an instance of type
org.gradle.invocation.DefaultGradle.
[ ] > Could not configure services using
GradleScopeCompileServices.configure().
[ ] * 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 726ms
[ +323 ms] Running Gradle task 'assembleDebug'... (completed in 1,328ms)
[+7853 ms] Exception: Gradle task assembleDebug failed with exit code 1
[ ] "flutter run" took 9,950ms.
[ +7 ms]
#0 throwToolExit (package:flutter_tools/src/base/common.dart:10:3)
#1 RunCommand.runCommand (package:flutter_tools/src/commands/run.dart:699:9)
<asynchronous suspension>
#2 FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart:1183: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:281: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:229: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:94:3)
<asynchronous suspension>
[ +113 ms] ensureAnalyticsSent: 111ms
[ +1 ms] Running shutdown hooks
[ ] Shutdown hooks complete
[ ] exiting with code 1
./build.gradle
含量:
buildscript {
ext.kotlin_version = '1.6.10'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.1.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
我已经创建了这个新项目多次,总是得到相同的错误。此外,我尝试了这些建议,但我仍然得到同样的错误:
$ flutter create .
$ flutter run
$ rm pubspec.lock
$ flutter pub get
Running "flutter pub get" in key_borrow... 3.8s
$ flutter run
更改gradle版本
我改变文件android/build。gradle: changedcom.android.tools.build:gradle:7.1.2
tocom.android.tools.build:gradle:4.1.3
颤振CLI导致相同错误.所以,我试着运行gradle,我得到了这个:
$ cd android
$ ./gradlew clean build
*[Several log lines that I ommitted]*
> Task :app:lint FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:lint'.
> Lint found errors in the project; aborting build.
Fix the issues identified by lint, or add the following to your build script to proceed with errors:
...
android {
lintOptions {
abortOnError false
}
}
...
Errors found:
/home/leal/key_borrow/android/app/src/main/AndroidManifest.xml:5: Error: Class referenced in the manifest, com.example.key_borrow.${applicationName}, was not found in the project or the libraries [MissingClass]
android:name="${applicationName}"
~~~~~~~~~~~~~~~~~~
* 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
Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
See https://docs.gradle.org/7.4/userguide/command_line_interface.html#sec:command_line_warnings
Execution optimizations have been disabled for 4 invalid unit(s) of work during this build to ensure correctness.
Please consult deprecation warnings for more details.
BUILD FAILED in 1m 53s
我还试图将android/gradle/wrapper/gradle-wrapper.properties
上的变量distributionUrl
更改为distributionUrl=https://services.gradle.org/distributions/gradle-4.1-all.zip
。我明白了:
./gradlew build --stacktrace
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine java version from '11.0.15'.
* Try:
Run with --info or --debug option to get more log output.
* Exception is:
java.lang.IllegalArgumentException: Could not determine java version from '11.0.15'.
at org.gradle.api.JavaVersion.toVersion(JavaVersion.java:72)
at org.gradle.api.JavaVersion.current(JavaVersion.java:82)
at org.gradle.internal.jvm.UnsupportedJavaRuntimeException.assertUsingVersion(UnsupportedJavaRuntimeException.java:29)
at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:32)
at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:24)
at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)
at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:253)
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:182)
at org.gradle.launcher.Main.doAction(Main.java:33)
at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:60)
at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:37)
at org.gradle.launcher.GradleMain.main(GradleMain.java:23)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.gradle.wrapper.BootstrapMainStarter.start(BootstrapMainStarter.java:30)
at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:129)
at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)
执行flutter create .
命令,注意创建后有一个句号。这将添加所有缺失的文件。然后尝试构建应用程序。