flutter环境搭建及其遇到的坑

总的来说需要的也就4样东西,找齐了配置一下就OK;

  • Flutter SDK[https://flutter.io/docs/get-started/install/windows] (建议下载官网的,下载完直接能用)

  • 下载Dart插件

  • 下载Flutter插件

    • 配置环境变量
  • 准备ide(Androidstudio或者IntelliJ IDEA)配置flutter的SDK即可

遇到的问题:

  • 不能下载插件 问题

    File->Settings->Apparence & Behavior->System Settings->Updates->use secure connnection
    
    勾去掉
    
  • 文件加载失败,换阿里镜像

    * Error running Gradle:
    ProcessException: Process "E:\flutter\demo\flutter_app\android\gradlew.bat" exited abnormally:
    Starting a Gradle Daemon (subsequent builds will be faster)
    
    > Configure project :app
    
    Project evaluation failed including an error in afterEvaluate {}. Run with --stacktrace for details of the afterEvaluate {} error.
    
    FAILURE: Build failed with an exception.
    
    * Where:
    Build file 'E:\flutter\demo\flutter_app\android\app\build.gradle' line: 26
    
    * What went wrong:
    A problem occurred evaluating project ':app'.
    > Could not resolve all artifacts for configuration 'classpath'.
       > Could not download kotlin-reflect.jar (org.jetbrains.kotlin:kotlin-reflect:1.2.0)
          > Could not get resource 'https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-reflect/1.2.0/kotlin-reflect-1.2.0.jar'.
             > Could not HEAD 'https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-reflect/1.2.0/kotlin-reflect-1.2.0.jar'.
                > Connect to d29vzk4ow07wi7.cloudfront.net:443 [d29vzk4ow07wi7.cloudfront.net/13.32.253.234, d29vzk4ow07wi7.cloudfront.net/13.32.253.66,
                d29vzk4ow07wi7.cloudfront.net/13.32.253.201, d29vzk4ow07wi7.cloudfront.net/13.32.253.237] 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 2m 13s
      Command: E:\flutter\demo\flutter_app\android\gradlew.bat app:properties
    
    
    Please review your Gradle project setup in the android/ folder.
    
    

        flutter_app/android/build/gradle中修改文件
        
        repositories {
            //google()
            //jcenter()
            maven{ url 'https://maven.aliyun.com/repository/google' }
            maven{ url 'https://maven.aliyun.com/repository/jcenter' }
            maven{url 'http://maven.aliyun.com/nexus/content/groups/public'}
        }
    
        allprojects {
            repositories {
                //google()
                //jcenter()
                maven{ url 'https://maven.aliyun.com/repository/google' }
                maven{ url 'https://maven.aliyun.com/repository/jcenter' }
                maven{url 'http://maven.aliyun.com/nexus/content/groups/public'}
            }
        }
    

    在 flutterSDK\flutter\packages\flutter_tools\gradle\flutter.gradle这个文件修改一下(或者使用翻墙软件也行),我就使用一下阿里的镜像服务器把
    
    buildscript {
        repositories {
            //google()
            //jcenter()
    	maven{ url 'https://maven.aliyun.com/repository/google' }
            maven{ url 'https://maven.aliyun.com/repository/jcenter' }
            maven{url 'http://maven.aliyun.com/nexus/content/groups/public'}
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:3.2.1'
        }
    }
    

  • 缺少ndk-bundle (https://developer.android.google.cn/ndk/downloads/)

        * Error running Gradle:
        ProcessException: Process "E:\flutter\demo\flutter_app\android\gradlew.bat" exited abnormally:
        
        > Configure project :app
        Checking the license for package Android SDK Platform 27 in C:\Users\kingsoft\AppData\Local\Android\sdk\licenses
        Warning: License for package Android SDK Platform 27 not accepted.
        
        
        FAILURE: Build failed with an exception.
        
        * Where:
        Build file 'E:\flutter\demo\flutter_app\android\build.gradle' line: 26
        
        * What went wrong:
        A problem occurred evaluating root project 'android'.
        > A problem occurred configuring project ':app'.
           > Failed to install the following Android SDK packages as some licences have not been accepted.
                platforms;android-27 Android SDK Platform 27
             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\kingsoft\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.
        
        E:\flutter\demo\flutter_app>flutter run
        Using hardware rendering with device Android SDK built for x86. If you get graphics artifacts, consider enabling software rendering with
        "--enable-software-rendering".
        Launching lib/main.dart on Android SDK built for x86 in debug mode...
        Initializing gradle...                                       0.9s
        Resolving dependencies...
        * Error running Gradle:
        ProcessException: Process "E:\flutter\demo\flutter_app\android\gradlew.bat" exited abnormally:
        
        > Configure project :app
        Checking the license for package Android SDK Platform 27 in C:\Users\kingsoft\AppData\Local\Android\sdk\licenses
        Warning: License for package Android SDK Platform 27 not accepted.
        
        
        FAILURE: Build failed with an exception.
        
        * Where:
        Build file 'E:\flutter\demo\flutter_app\android\build.gradle' line: 32
        
        * What went wrong:
        A problem occurred evaluating root project 'android'.
        > A problem occurred configuring project ':app'.
           > Failed to install the following Android SDK packages as some licences have not been accepted.
                platforms;android-27 Android SDK Platform 27
             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\kingsoft\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
          Command: E:\flutter\demo\flutter_app\android\gradlew.bat app:properties
        
        
        Please review your Gradle project setup in the android/ folder.
    
  • Build file ‘E:\flutter\project\flutter_app\android\build.gradle’ line: 32

创建一个lib【common】,app:依赖【common】出现该原因

subprojects {
//    project.evaluationDependsOn(':app')
    project.configurations.all {
        resolutionStrategy.eachDependency { details ->
            if (details.requested.group == 'com.android.support'
                    && !details.requested.name.contains('multidex') ) {
                details.useVersion "27.1.1"
            }
        }
    }
}!

猜你喜欢

转载自blog.csdn.net/luchuanqi67/article/details/91283884