Run the Flutter HelloWorld project in Android Studio under Win10 environment

I. Introduction

        Android Studio is the official IDE (Integrated Development Environment) for Android. Built for Android, it speeds up development and builds the highest quality apps for Android devices.

        Flutter is an open-source mobile application development framework launched by Google, featuring cross-platform, high-fidelity, and high-performance. Developers can develop apps through the Dart language, and realize a set of codes running on iOS and Android platforms at the same time.

        Dart is a client-optimized language for developing fast applications on any platform. Its goal is to provide the most efficient programming language for multi-platform development, and a flexible runtime execution platform for the application framework. Generally speaking, programming languages ​​​​will contain some technical barriers, that is, the choices in the design of the language determine its functions and advantages. Dart's language design is aimed at client-side development, and it prioritizes development on multiple platforms (web, mobile, and desktop) (sub-second state hot reload) and high-quality production environment experience. Dart is also the foundation of Flutter. Dart, as a programming language for Flutter applications, provides an environment for driving applications. At the same time, Dart also supports many core development tasks, such as formatting, analysis, and code testing.

2. Basic environment

        You need to install Android Studio and Flutter. The emulator in Android Studio can be installed instead of a real machine.

        Android development tools download: https://www.androiddevtools.cn/

        Install Android Studio to view this blog (for reference only): https://blog.csdn.net/tao_789456/article/details/118093106 .

        Real machine running APP (test Android Studio development environment, for reference only): https://blog.csdn.net/mfysss/article/details/128104855

        To install Flutter, you can check this blog (for reference only): https://zhuanlan.zhihu.com/p/628479851 (basically download, decompress, and set environment variables).

3. My environment

        Win10 version : 10.0.19042

        Android Studio version :

        Real machine environment : Meizu Pro 6 Plus (Android7.0.0)

        Flutter version :

        Flutter 3.3.10 • channel stable • https://github.com/flutter/flutter.git
        Framework • revision 135454af32 (7 months ago) • 2022-12-15 07:36:55 -0800
        Engine • revision 3316dd8728
        Tools • Dart 2.18.6 • DevTools 2.15.0

4. Problems encountered

        1. When installing Android Studio, the mobile phone emulator cannot be installed, probably because the CPU of the computer does not support VT-x. If I can't install it, I won't be brave (because this is not my personal computer, and the computer desktop is also a cloud desktop, which is not easy to fiddle with), and then I chose to run it on a real machine.

        2. When installing Flutter, flutter-related commands do not respond, do not run, or get stuck. In addition to the above phenomena, if you rashly create a Flutter project in Android Studio, it will also display abnormalities (for example, there is no Project Type, Android language, and iOS language for you to choose), or you will be stuck when creating a project. Solution: Migrate the installation location of Flutter according to the guidelines of the blog https://blog.csdn.net/huanggan08/article/details/88641198 . For example, I installed "Program Files" on the C drive at the beginning (avoid, The installation path with spaces is the main cause of this problem), and then I migrated to the root directory of the C drive.

        3. When creating a Flutter project, "Invalid module name: 'XxxxXxxx' - must be a valid Dart package name(lower_case_with_underscores)" appears. Solution: Name the project using a combination of lowercase letters or underscores.

        4. Flutter App Run stuck in Running Gradle task 'assembleDebug'. The solution is to switch the source of Flutter (source, mainly flutter.gradle in flutter\packages\flutter_tools\gradle), the specific build.gradle in the Flutter project (that is, the android/build.gradle file) can also be changed here . I mainly refer to this blog to solve the problems I encountered: https://www.bilibili.com/read/cv22572083 . specific method:

修改Flutter SDK中packages\flutter_tools\gradle\flutter.gradle文件:

将buildscript.repositories下面两行代码注释掉
//google()
//mavenCentral()
改成
maven {
   allowInsecureProtocol = true
   url 'https://maven.aliyun.com/repository/google'
}
maven {
   allowInsecureProtocol = true
   url 'https://maven.aliyun.com/repository/jcenter'
}
maven {
   allowInsecureProtocol = true
   url 'http://maven.aliyun.com/nexus/content/groups/public'
}

在修改过程中请注意空格字符应与文件保持一致。

        5. When running flutter doctor, it prompts me that Visual Studio is not installed. In fact, this Visual Studio can also develop Flutter projects without installation. It depends on the individual whether to install it or not.

5. Run the Flutter HelloWorld project in Android Studio

        Create a Flutter project:

        Select the Flutter SDK path (this step is very important, the path cannot contain spaces, which must be ensured when installing Flutter), and then next:

        Name the project (note the lowercase), select the language for Android and iOS, and click Finish. If the following interface does not appear, it means that Flutter is not installed correctly, and you need to check and adjust it yourself.

        Write code, or run directly:

        Then the Meizu Pro 6 Plus mobile phone connected to the computer will prompt to install it. After installation, open the app, and the screen will display Hello World Times: 0. If you keep tapping the "+" icon, the number will keep increasing.

        Alright, the blog is almost finished, see you in the comment section if you have any questions.

6. References

        1. Android Studio Features | Android Developers | Android Developers

        2. Introduction to Flutter

        3. Dart overview

Supongo que te gusta

Origin blog.csdn.net/qq_36158230/article/details/131805401
Recomendado
Clasificación