为什么 flutter build apk --release 不起作用?

问题描述 投票:0回答:1

当我运行 **flutter build apk --release ** 命令时,它不起作用并显示错误。

这是错误:

Font asset "MaterialIcons-Regular.otf" was tree-shaken, reducing it from 1645184 to 
1352 bytes (99.9% reduction). Tree-shaking can be disabled by providing the --no-tree-shake-icons flag when building your app.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:checkReleaseAarMetadata'.
 Could not resolve all files for configuration ':app:releaseRuntimeClasspath'.     
    Could not resolve androidx.lifecycle:lifecycle-common:2.2.0.
     Required by:
         project :app  io.flutter:flutter_embedding_release:1.0.0-    cdbeda788a293fa29665dc3fa3d6e63bd221cb0d
       Could not resolve androidx.lifecycle:lifecycle-common:2.2.0.
          Could not get resource     'https://storage.googleapis.com/download.flutter.io/androidx/lifecycle/lifecycle-    common/2.2.0/lifecycle-common-2.2.0.pom'.
             Could not GET     'https://storage.googleapis.com/download.flutter.io/androidx/lifecycle/lifecycle-    common/2.2.0/lifecycle-common-2.2.0.pom'. Received status code 403 from server: Forbidden
    Could not resolve androidx.lifecycle:lifecycle-common-java8:2.2.0.
     Required by:
         project :app  io.flutter:flutter_embedding_release:1.0.0-    cdbeda788a293fa29665dc3fa3d6e63bd221cb0d
       Could not resolve androidx.lifecycle:lifecycle-common-java8:2.2.0.
          Could not get resource     'https://storage.googleapis.com/download.flutter.io/androidx/lifecycle/lifecycle-common-    java8/2.2.0/lifecycle-common-java8-2.2.0.pom'.             Could not GET     'https://storage.googleapis.com/download.flutter.io/androidx/lifecycle/lifecycle-common-    java8/2.2.0/lifecycle-common-java8-2.2.0.pom'. Received status code 403 from server: Forbidden
    Could not resolve androidx.lifecycle:lifecycle-runtime:2.2.0.
     Required by:
         project :app  io.flutter:flutter_embedding_release:1.0.0-    cdbeda788a293fa29665dc3fa3d6e63bd221cb0d
       Could not resolve androidx.lifecycle:lifecycle-runtime:2.2.0.
          Could not get resource     'https://storage.googleapis.com/download.flutter.io/androidx/lifecycle/lifecycle-    runtime/2.2.0/lifecycle-runtime-2.2.0.pom'.
             Could not GET     'https://storage.googleapis.com/download.flutter.io/androidx/lifecycle/lifecycle-    runtime/2.2.0/lifecycle-runtime-2.2.0.pom'. Received status code 403 from server: Forbidden
    Could not resolve androidx.fragment:fragment:1.1.0.
     Required by:
         project :app  io.flutter:flutter_embedding_release:1.0.0-    cdbeda788a293fa29665dc3fa3d6e63bd221cb0d
       Could not resolve androidx.fragment:fragment:1.1.0.
          Could not get resource     'https://storage.googleapis.com/download.flutter.io/androidx/fragment/fragment/1.1.0/fragment-    1.1.0.pom'.
             Could not GET     'https://storage.googleapis.com/download.flutter.io/androidx/fragment/fragment/1.1.0/fragment-    1.1.0.pom'. Received status code 403 from server: Forbidden
    Could not resolve androidx.annotation:annotation:1.1.0.
     Required by:
         project :app  io.flutter:flutter_embedding_release:1.0.0-    cdbeda788a293fa29665dc3fa3d6e63bd221cb0d
       Could not resolve androidx.annotation:annotation:1.1.0.
          Could not get resource     'https://storage.googleapis.com/download.flutter.io/androidx/annotation/annotation/1.1.0/annotation-    1.1.0.pom'.
             Could not GET     'https://storage.googleapis.com/download.flutter.io/androidx/annotation/annotation/1.1.0/annotation-    1.1.0.pom'. Received status code 403 from server: Forbidden
    Could not resolve androidx.tracing:tracing:1.0.0.
     Required by:
         project :app  io.flutter:flutter_embedding_release:1.0.0-    cdbeda788a293fa29665dc3fa3d6e63bd221cb0d
       Could not resolve androidx.tracing:tracing:1.0.0.
          Could not get resource     'https://storage.googleapis.com/download.flutter.io/androidx/tracing/tracing/1.0.0/tracing-    1.0.0.pom'.
             Could not GET     'https://storage.googleapis.com/download.flutter.io/androidx/tracing/tracing/1.0.0/tracing-    1.0.0.pom'. Received status code 403 from server: Forbidden
    Could not resolve androidx.core:core:1.6.0.
     Required by:
         project :app  io.flutter:flutter_embedding_release:1.0.0-    cdbeda788a293fa29665dc3fa3d6e63bd221cb0d
       Could not resolve androidx.core:core:1.6.0.
          Could not get resource     'https://storage.googleapis.com/download.flutter.io/androidx/core/core/1.6.0/core-1.6.0.pom'.
             Could not GET     'https://storage.googleapis.com/download.flutter.io/androidx/core/core/1.6.0/core-1.6.0.pom'.     Received status code 403 from server: Forbidden
    Could not resolve androidx.window:window-java:1.0.0-beta04.
     Required by:
         project :app  io.flutter:flutter_embedding_release:1.0.0-    cdbeda788a293fa29665dc3fa3d6e63bd221cb0d
       Could not resolve androidx.window:window-java:1.0.0-beta04.
          Could not get resource     'https://storage.googleapis.com/download.flutter.io/androidx/window/window-java/1.0.0-beta04/window-    java-1.0.0-beta04.pom'.
             Could not GET     'https://storage.googleapis.com/download.flutter.io/androidx/window/window-java/1.0.0-beta04/window-    java-1.0.0-beta04.pom'. Received status 
code 403 from server: Forbidden

* 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 51s
Running Gradle task 'assembleRelease'...                           53.1s
[!] Gradle threw an error while downloading artifacts from the network.
Retrying Gradle Build: #1, wait time: 100ms

这是我的 build.gradle 文件内容:

buildscript {
    ext.kotlin_version = '1.7.10'
    repositories {
        google()
        mavenCentral()
    }

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

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

tasks.register("clean", Delete) {
    delete rootProject.buildDir
}

这也是我在 android -> 应用程序方向中的 build.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 {
    namespace "com.example.project_3"
    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.project_3"
    // You can update the following values to match your application needs.
    // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-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"
}

我搜索了很多,查看了所有与此主题相关的网站,并执行了他们所说的解决方案,但没有一个对我有用,我仍然遇到错误,这对我没有帮助。

我尝试了这些命令:

flutter build apk
flutter build apk --split-per-abi --no-tree-shake-icons
flutter build apk --no-tree-shake-icons
flutter build apk --release --no-tree-shake-icons

也可以,但不能再工作了。

如果您有解决方案,请帮忙。预先感谢

android flutter apk
1个回答
0
投票

正如Priyesh所说,这可能与网络有关

从服务器收到状态代码 403:禁止

请检查您的网络是否使用任何专用网络、VPN 或受保护网络?请再尝试另一个稳定的网络。

© www.soinside.com 2019 - 2024. All rights reserved.