按照官方文檔簽名等一些工作配置好了之後。開始使用flutter命令打包apk。在終端執行flutter build apk後等了一段時間後出現如下錯誤:
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':app:lintVitalRelease'.
> Could not resolve all artifacts for configuration ':app:releaseCompileClasspath'.
> Could not resolve io.flutter:x86_64_release:1.0.0-2d42c74a348d98d2fd372a91953c104e58f185cd.
Required by:
project :app
> Could not resolve io.flutter:x86_64_release:1.0.0-2d42c74a348d98d2fd372a91953c104e58f185cd.
> Could not get resource 'https://storage.googleapis.com/download.flutter.io/io/flutter/x86_64_release/1.0.0-2d42c74a348d98d2fd372a91953c104e58f185cd/x86_64_release-1.0.0-2d42c74a348d98d2fd372a91953c104e58f185cd.pom'.
> Could not GET 'https://storage.googleapis.com/download.flutter.io/io/flutter/x86_64_release/1.0.0-2d42c74a348d98d2fd372a91953c104e58f185cd/x86_64_release-1.0.0-2d42c74a348d98d2fd372a91953c104e58f185cd.pom'.
> Connect to storage.googleapis.com:443 [storage.googleapis.com/172.217.24.16] failed: Connection timed out: connect
> Could not resolve io.flutter:x86_64_release:1.0.0-2d42c74a348d98d2fd372a91953c104e58f185cd.
> Could not get resource 'https://storage.googleapis.com/download.flutter.io/io/flutter/x86_64_release/1.0.0-2d42c74a348d98d2fd372a91953c104e58f185cd/x86_64_release-1.0.0-2d42c74a348d98d2fd372a91953c104e58f185cd.pom'.
> Could not GET 'https://storage.googleapis.com/download.flutter.io/io/flutter/x86_64_release/1.0.0-2d42c74a348d98d2fd372a91953c104e58f185cd/x86_64_release-1.0.0-2d42c74a348d98d2fd372a91953c104e58f185cd.pom'.
> Connect to storage.googleapis.com:443 [storage.googleapis.com/172.217.24.16] failed: Read timed out
* 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 6m 39s
可能由於網絡因數,第一次打包不能支持多個平臺,那麼支持arm平臺就可以了。
所以執行命令如下
flutter build apk --target-platform android-arm
運行之後就可以了,並且下面執行的命令打出的包的體積也要小一些。
如果flutter打包出來的apk安裝到android手機上可以運行,但是無法訪問網絡,那麼在flutter項目中的android/app/src/main/AndroidMast.xml文件下把網絡權限添加上。
<uses-permission android:name="android.permission.INTERNET" />
不知道爲什麼在debug模式下不添加是可以訪問的。打包之後不添加是不可以的。所以容易疏忽。
如果文章有問題,或者建議,歡迎下方評論