简体   繁体   English

Flutter如何构建APK

[英]Flutter how to build APK

I'm created an empty flutter project.我创建了一个空的 flutter 项目。 Flutter installed success. Flutter 安装成功。 And I'm created an empty project, but I can't build an APK and start my application on Android device when I connect my phone through USB.我创建了一个空项目,但是当我通过 USB 连接手机时,我无法构建 APK 并在 Android 设备上启动我的应用程序。

And after building apk I'm getting an error:在构建 apk 之后,我收到一个错误:

Building with sound null safety


FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'android'.
> Could not resolve all artifacts for configuration ':classpath'.
   > Could not download gradle-4.1.0.jar (com.android.tools.build:gradle:4.1.0)
      > Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/4.1.0/gradle-4.1.0.jar'.
         > Premature end of Content-Length delimited message body (expected: 6�041�440; received: 4�456�416)
   > Could not download builder-4.1.0.jar (com.android.tools.build:builder:4.1.0)
      > Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/tools/build/builder/4.1.0/builder-4.1.0.jar'.
         > Premature end of Content-Length delimited message body (expected: 9�546�513; received: 6�553�552)
   > Could not download bundletool-0.14.0.jar (com.android.tools.build:bundletool:0.14.0)
      > Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/tools/build/bundletool/0.14.0/bundletool-0.14.0.jar'.
         > Premature end of Content-Length delimited message body (expected: 7�826�780; received: 4�456�416)

* 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 1h 23m 34s
Running Gradle task 'assembleRelease'...                         5015,6s
[!] Gradle threw an error while downloading artifacts from the network. Retrying to download...
Checking the license for package Android SDK Build-Tools 29.0.2 in C:\Users\User\AppData\Local\Android\sdk\licenses
Warning: License for package Android SDK Build-Tools 29.0.2 not accepted.
Checking the license for package Android SDK Platform 30 in C:\Users\User\AppData\Local\Android\sdk\licenses
Warning: License for package Android SDK Platform 30 not accepted.

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':app:lintVitalRelease'.
> Could not resolve all dependencies for configuration ':app:lintClassPath'.
   > Could not create task ':app:minifyReleaseWithR8'.
      > Failed to install the following Android SDK packages as some licences have not been accepted.
           platforms;android-30 Android SDK Platform 30
           build-tools;29.0.2 Android SDK Build-Tools 29.0.2
        To build this project, accept the SDK license agreements and install the missing components using the Android Studio SDK Manager.
        Alternatively, to transfer the license agreements from one workstation to another, see http://d.android.com/r/studio-ui/export-licenses.html

        Using Android SDK: C:\Users\User\AppData\Local\Android\sdk

* 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 19s
Running Gradle task 'assembleRelease'...                          380,2s
Gradle task assembleRelease failed with exit code 1

I'm creating an Android application at first.我首先创建了一个 Android 应用程序。 And I'm haven't an experience.而且我没有经验。

What's wrong?怎么了?

Thanks a lot.非常感谢。

I'm fixed an error adding jcenter() to build.gradle .我修复了将 jcenter() 添加到build.gradle的错误。 But now I'm getting an error:但现在我收到一个错误:

 FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':app:compileReleaseJavaWithJavac'.
> Failed to install the following Android SDK packages as some licences have not been accepted.
     platforms;android-30 Android SDK Platform 30
     build-tools;29.0.2 Android SDK Build-Tools 29.0.2
  To build this project, accept the SDK license agreements and install the missing components using the Android Studio SDK Manager.
  Alternatively, to transfer the license agreements from one workstation to another, see http://d.android.com/r/studio-ui/export-licenses.html

  Using Android SDK: C:\Users\User\AppData\Local\Android\sdk

* 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 9s

if it is the first launch... Make sure you are connected to internet!如果是第一次启动...请确保您已连接到互联网! Some dependencies should be installed and cached应该安装和缓存一些依赖项

If the error persists... Try to run flutter pub clean and then flutter pub get如果错误仍然存在...尝试运行flutter pub clean然后flutter pub get

You can build the apk throw the command line with:您可以使用以下命令构建 apk 并抛出命令行:

flutter build apk --release flutter 构建 apk --release

or directly with Android Studio或直接使用 Android Studio

构建颤振 APK

I can see you are having some problems with license agreements.我可以看到您在许可协议方面遇到了一些问题。 You should try to open the terminal and type:您应该尝试打开终端并输入:

flutter doctor --android-licenses flutter 医生 --android-licenses

Then you should press y to accept every license, after completing the process try building the project again.然后您应该按y接受每个许可证,完成该过程后再次尝试构建项目。

According to the error, what happens is that you do not have some components installed, you can open the android studio, settings, sdk and look for the buildtools and plattforms versions after installing them because your problem will be solved, in the same way to create the applications I like to do it with the following command that gives you the releases by architectures flutter build apk --split-per-abi根据报错,是你没有安装某些组件,你可以打开android studio,settings,sdk,安装后查找buildtools和plattforms版本,因为你的问题会解决,同样的方法创建我喜欢的应用程序,使用以下命令为您提供架构 flutter build apk --split-per-abi 的版本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM