简体   繁体   English

无法在模拟器上运行 flutter 项目

[英]Cannot run flutter project on emulator

I have downloaded Android Studio Chipmunk|2021.2.1 Patch 1我已经下载了 Android Studio Chipmunk|2021.2.1 补丁 1
I have java version 8 (build 1.8.0_341-b10)我有 java 版本 8(构建 1.8.0_341-b10)
I am trying to run main.dart (default flutter program ) on vscode but it does not work\我正在尝试在 vscode 上运行 main.dart (默认 flutter 程序),但它不起作用\

I have run flutter doctor command to check for any issues but everything is correct我已经运行 flutter 医生命令来检查任何问题,但一切都是正确的在此处输入图像描述

The error list is:错误列表是:

FAILURE: Build failed with an exception.

* Where:
Build file 'G:\proj\android\app\build.gradle' line: 26

* What went wrong:
A problem occurred evaluating project ':app'.
> Could not resolve all files for configuration 'classpath'.
   > Could not resolve org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.72.
     Required by:
         unspecified:unspecified:unspecified > com.android.tools.build:gradle:4.1.0
         unspecified:unspecified:unspecified > com.android.tools.build:gradle:4.1.0 > com.android.tools.build:builder:4.1.0
         unspecified:unspecified:unspecified > com.android.tools.build:gradle:4.1.0 > com.android.tools.build:aaptcompiler:4.1.0
         unspecified:unspecified:unspecified > com.android.tools.build:gradle:4.1.0 > com.android.tools.lint:lint-gradle-api:27.1.0
         unspecified:unspecified:unspecified > com.android.tools.build:gradle:4.1.0 > com.android.tools.build:gradle-api:4.1.0
         unspecified:unspecified:unspecified > com.android.tools.build:gradle:4.1.0 > androidx.databinding:databinding-compiler-common:4.1.0
         unspecified:unspecified:unspecified > com.android.tools.build:gradle:4.1.0 > com.android.tools.build:builder:4.1.0 > com.android.tools.build:builder-model:4.1.0
         unspecified:unspecified:unspecified > com.android.tools.build:gradle:4.1.0 > com.android.tools.build:builder:4.1.0 > com.android.tools:sdk-common:27.1.0
         unspecified:unspecified:unspecified > com.android.tools.build:gradle:4.1.0 > com.android.tools.build:builder:4.1.0 > com.android.tools:common:27.1.0
         unspecified:unspecified:unspecified > com.android.tools.build:gradle:4.1.0 > com.android.tools.build:builder:4.1.0 > com.android.tools.build:manifest-merger:27.1.0
         unspecified:unspecified:unspecified > com.android.tools.build:gradle:4.1.0 > com.android.tools.build:builder:4.1.0 > com.android.tools.analytics-library:tracker:27.1.0
         unspecified:unspecified:unspecified > com.android.tools.build:gradle:4.1.0 > com.android.tools.lint:lint-gradle-api:27.1.0 > com.android.tools.lint:lint-model:27.1.0
         unspecified:unspecified:unspecified > com.android.tools.build:gradle:4.1.0 > com.android.tools.build:builder:4.1.0 > com.android.tools:sdklib:27.1.0 > com.android.tools:repository:27.1.0
         unspecified:unspecified:unspecified > com.android.tools.build:gradle:4.1.0 > com.android.tools.build:builder:4.1.0 > com.android.tools:sdk-common:27.1.0 > com.android.tools.analytics-library:shared:27.1.0
      > Could not resolve org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.72.
         > Could not get resource 'https://repo.maven.apache.org/maven2/org/jetbrains/kotlin/kotlin-stdlib-jdk8/1.3.72/kotlin-stdlib-jdk8-1.3.72.pom'.
            > Could not GET 'https://repo.maven.apache.org/maven2/org/jetbrains/kotlin/kotlin-stdlib-jdk8/1.3.72/kotlin-stdlib-jdk8-1.3.72.pom'.
               > The server may not support the client's requested TLS protocol versions: (TLSv1.2, TLSv1.3). You may need to configure the client to allow other protocols to be used. See: https://docs.gradle.org/7.4/userguide/build_environment.html#gradle_system_properties
                  > Remote host terminated the handshake
   > Could not resolve org.ow2.asm:asm:7.0.
     Required by:
         unspecified:unspecified:unspecified > com.android.tools.build:gradle:4.1.0
         unspecified:unspecified:unspecified > com.android.tools.build:gradle:4.1.0 > com.android.tools.build:builder:4.1.0
      > Could not resolve org.ow2.asm:asm:7.0.
         > Could not get resource 'https://repo.maven.apache.org/maven2/org/ow2/asm/asm/7.0/asm-7.0.pom'.
            > Could not GET 'https://repo.maven.apache.org/maven2/org/ow2/asm/asm/7.0/asm-7.0.pom'.
               > The server may not support the client's requested TLS protocol versions: (TLSv1.2, TLSv1.3). You may need to configure the client to allow other protocols to be used. See: https://docs.gradle.org/7.4/userguide/build_environment.html#gradle_system_properties
                  > Remote host terminated the handshake
   > Could not resolve org.ow2.asm:asm-analysis:7.0.
     Required by:
         unspecified:unspecified:unspecified > com.android.tools.build:gradle:4.1.0
      > Could not resolve org.ow2.asm:asm-analysis:7.0.
         > Could not get resource 'https://repo.maven.apache.org/maven2/org/ow2/asm/asm-analysis/7.0/asm-analysis-7.0.pom'.
            > Could not GET 'https://repo.maven.apache.org/maven2/org/ow2/asm/asm-analysis/7.0/asm-analysis-7.0.pom'.
               > The server may not support the client's requested TLS protocol versions: (TLSv1.2, TLSv1.3). You may need to configure the client to allow other protocols to be used. See: https://docs.gradle.org/7.4/userguide/build_environment.html#gradle_system_properties
                  > Remote host terminated the handshake
   > Could not resolve org.ow2.asm:asm-commons:7.0.
     Required by:
         unspecified:unspecified:unspecified > com.android.tools.build:gradle:4.1.0
         unspecified:unspecified:unspecified > com.android.tools.build:gradle:4.1.0 > com.android.tools.build:builder:4.1.0
      > Could not resolve org.ow2.asm:asm-commons:7.0.
         > Could not get resource 'https://repo.maven.apache.org/maven2/org/ow2/asm/asm-commons/7.0/asm-commons-7.0.pom'.
            > Could not GET 'https://repo.maven.apache.org/maven2/org/ow2/asm/asm-commons/7.0/asm-commons-7.0.pom'.
               > The server may not support the client's requested TLS protocol versions: (TLSv1.2, TLSv1.3). You may need to configure the client to allow other protocols to be used. See: https://docs.gradle.org/7.4/userguide/build_environment.html#gradle_system_properties
                  > Remote host terminated the handshake
   > Could not resolve org.ow2.asm:asm-util:7.0.
     Required by:
         unspecified:unspecified:unspecified > com.android.tools.build:gradle:4.1.0
         unspecified:unspecified:unspecified > com.android.tools.build:gradle:4.1.0 > com.android.tools.build:builder:4.1.0
      > Could not resolve org.ow2.asm:asm-util:7.0.
         > Could not get resource 'https://repo.maven.apache.org/maven2/org/ow2/asm/asm-util/7.0/asm-util-7.0.pom'.
            > Could not GET 'https://repo.maven.apache.org/maven2/org/ow2/asm/asm-util/7.0/asm-util-7.0.pom'.
               > The server may not support the client's requested TLS protocol versions: (TLSv1.2, TLSv1.3). You may need to configure the client to allow other protocols to be used. See: https://docs.gradle.org/7.4/userguide/build_environment.html#gradle_system_properties
                  > Remote host terminated the handshake
   > Could not resolve net.sf.proguard:proguard-gradle:6.0.3.
     Required by:
         unspecified:unspecified:unspecified > com.android.tools.build:gradle:4.1.0
      > Could not resolve net.sf.proguard:proguard-gradle:6.0.3.
         > Could not get resource 'https://repo.maven.apache.org/maven2/net/sf/proguard/proguard-gradle/6.0.3/proguard-gradle-6.0.3.pom'.
            > Could not GET 'https://repo.maven.apache.org/maven2/net/sf/proguard/proguard-gradle/6.0.3/proguard-gradle-6.0.3.pom'.
               > The server may not support the client's requested TLS protocol versions: (TLSv1.2, TLSv1.3). You may need to configure the client to allow other protocols to be used. See: https://docs.gradle.org/7.4/userguide/build_environment.html#gradle_system_properties
                  > Remote host terminated the handshake
   > Could not resolve org.tensorflow:tensorflow-lite-metadata:0.1.0-rc1.
     Required by:
         unspecified:unspecified:unspecified > com.android.tools.build:gradle:4.1.0
      > Could not resolve org.tensorflow:tensorflow-lite-metadata:0.1.0-rc1.
         > Could not get resource 'https://repo.maven.apache.org/maven2/org/tensorflow/tensorflow-lite-metadata/0.1.0-rc1/tensorflow-lite-metadata-0.1.0-rc1.pom'.
            > Could not GET 'https://repo.maven.apache.org/maven2/org/tensorflow/tensorflow-lite-metadata/0.1.0-rc1/tensorflow-lite-metadata-0.1.0-rc1.pom'.
               > The server may not support the client's requested TLS protocol versions: (TLSv1.2, TLSv1.3). You may need to configure the client to allow other protocols to be used. See: https://docs.gradle.org/7.4/userguide/build_environment.html#gradle_system_properties
                  > Remote host terminated the handshake
   > Could not resolve org.ow2.asm:asm-tree:7.0.
     Required by:
         unspecified:unspecified:unspecified > com.android.tools.build:gradle:4.1.0 > com.android.tools.build:builder:4.1.0
      > Could not resolve org.ow2.asm:asm-tree:7.0.
         > Could not get resource 'https://repo.maven.apache.org/maven2/org/ow2/asm/asm-tree/7.0/asm-tree-7.0.pom'.
            > Could not GET 'https://repo.maven.apache.org/maven2/org/ow2/asm/asm-tree/7.0/asm-tree-7.0.pom'.
               > The server may not support the client's requested TLS protocol versions: (TLSv1.2, TLSv1.3). You may need to configure the client to allow other protocols to be used. See: https://docs.gradle.org/7.4/userguide/build_environment.html#gradle_system_properties
                  > Remote host terminated the handshake
   > Could not resolve it.unimi.dsi:fastutil:7.2.0.
     Required by:
         unspecified:unspecified:unspecified > com.android.tools.build:gradle:4.1.0 > com.android.tools.build:builder:4.1.0
      > Could not resolve it.unimi.dsi:fastutil:7.2.0.
         > Could not get resource 'https://repo.maven.apache.org/maven2/it/unimi/dsi/fastutil/7.2.0/fastutil-7.2.0.pom'.            > Could not GET 'https://repo.maven.apache.org/maven2/it/unimi/dsi/fastutil/7.2.0/fastutil-7.2.0.pom'.
               > The server may not support the client's requested TLS protocol versions: (TLSv1.2, TLSv1.3). You may need to configure the client to allow other protocols to be used. See: https://docs.gradle.org/7.4/userguide/build_environment.html#gradle_system_properties
                  > Remote host terminated the handshake
..........

My gradle wrapper properties:我的 gradle 包装器属性:

#Fri Jun 23 08:50:38 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip

My build gradle:我的构建 gradle:

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion flutter.compileSdkVersion
    ndkVersion flutter.ndkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.example.flut"
        // You can update the following values to match your application needs.
        // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
        minSdkVersion flutter.minSdkVersion
        targetSdkVersion flutter.targetSdkVersion
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

I read some issues regarding gradle incompatibility but i don't quite understand it well and i don't get why these errors are occurring exactly.我阅读了一些关于 gradle 不兼容的问题,但我不太了解它,我不明白为什么这些错误会准确发生。

UPDATE: I tried some fixes and the error list has now reduced to this更新:我尝试了一些修复,现在错误列表已经减少到这个

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'android'.
> Could not resolve all files for configuration ':classpath'.
   > Could not resolve org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.0.
     Required by:
         project :
      > Could not resolve org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.0.
         > Could not get resource 'https://repo.maven.apache.org/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin/1.7.0/kotlin-gradle-plugin-1.7.0.pom'.
            > Could not GET 'https://repo.maven.apache.org/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin/1.7.0/kotlin-gradle-plugin-1.7.0.pom'.
               > The server may not support the client's requested TLS protocol versions: (TLSv1.2, TLSv1.3). You may need to configure the client to allow other protocols to be used. See: https://docs.gradle.org/7.4/userguide/build_environment.html#gradle_system_properties
                  > Remote host terminated the handshake

* 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 3s\

I think there is some issue of TLS protocol version.我认为 TLS 协议版本存在一些问题。 But i can't find much detail about it.但我找不到太多关于它的细节。

Open Flutter Terminal and run:打开 Flutter 终端并运行:

flutter clean
flutter pub get

Then update your classpath:然后更新你的类路径:

dependencies {
        classpath 'com.android.tools.build:gradle:7.1.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }

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

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