我所有的 flutter 应用程序错误构建失败并出现异常。Flutter build APK 错误

all my flutter app error Build failed with an exception.Flutter build APK Error

提问人:reza kia 提问时间:6/13/2023 更新时间:6/13/2023 访问量:319

问:

Flutter 构建 AppBundle

Flutter 资源将从 https://storage.googleapis.com 下载。确保您信任此来源! 参数格式不正确 -

失败:生成已完成,但有 2 次失败。

1:任务失败,出现异常。

  • 出了什么问题: 任务“:connectivity:compileReleaseJavaWithJavac”执行失败。

无法解析配置“:connectivity:releaseCompileClasspath”的所有文件。 无法将生命周期运行时-2.2.0.jar (androidx.lifecycle:lifecycle-runtime:2.2.0) 转换为匹配属性 {artifactType=android-classes-jar, org.gradle.category=library, org.gradle.libraryelements=jar, org.gradle.status=release, org.gradle.usage=java-api}。 > 找不到 lifecycle-runtime-2.2.0.jar (androidx.lifecycle:lifecycle-runtime:2.2.0)。 在以下位置搜索:https://dl.google.com/dl/android/maven2/androidx/lifecycle/lifecycle-runtime/2.2.0/lifecycle-runtime-2.2.0.jar

  • 尝试:

使用 --stacktrace 选项运行以获取堆栈跟踪。 使用 --info 或 --debug 选项运行以获取更多日志输出。 使用 --scan 运行以获取完整的见解。 ==============================================================================

2:任务失败,出现异常。

  • 出了什么问题: 任务“:firebase_core:compileReleaseJavaWithJavac”执行失败。

无法解析配置“:firebase_core:releaseCompileClasspath”的所有文件。 无法将生命周期运行时-2.2.0.jar (androidx.lifecycle:lifecycle-runtime:2.2.0) 转换为匹配属性 {artifactType=android-classes-jar, org.gradle.category=library, org.gradle.libraryelements=jar, org.gradle.status=release, org.gradle.usage=java-api}。 > 找不到 lifecycle-runtime-2.2.0.jar (androidx.lifecycle:lifecycle-runtime:2.2.0)。 在以下位置搜索:https://dl.google.com/dl/android/maven2/androidx/lifecycle/lifecycle-runtime/2.2.0/lifecycle-runtime-2.2.0.jar

  • 尝试:

使用 --stacktrace 选项运行以获取堆栈跟踪。 使用 --info 或 --debug 选项运行以获取更多日志输出。 使用 --scan 运行以获取完整的见解。 ==============================================================================

构建在 1 分 28 秒内失败 正在运行 Gradle 任务“bundleRelease”...89.6秒 Gradle 任务 bundleRelease 失败,退出代码为 1

我是 ussing gradle:


distributionUrl=https://services.gradle.org/distributions/gradle-7.4-all.zip

和我的应用程序/gradle:


buildscript {
    ext.kotlin_version = '1.8.21'
    repositories {
        google()
        jcenter()
        maven {
            url 'https://download.flutter.io'
        }

    }

    dependencies {
        classpath 'com.android.tools.build:gradle:7.1.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.3.8'  // Google Services plugin

    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven {
            url 'https://download.flutter.io'
        }

    }
}

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

task clean(type: Delete) {
    delete rootProject.buildDir
}

和 progect/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"
apply plugin: 'com.google.gms.google-services'

def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

android {
    compileSdkVersion 33

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

    lintOptions {
        disable 'InvalidPackage'
        checkReleaseBuilds false //<- add this line
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.aryaclub.flutter_app"
        minSdkVersion 21
        targetSdkVersion 33
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        multiDexEnabled true
    }

    signingConfigs {
        release {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null // original code
            //storeFile file("key.jks") ? file("key.jks") : null //new solution for some customers
            storePassword keystoreProperties['storePassword']
        }
    }

    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 {
    def lifecycle_version = "2.6.1"
    def arch_version = "2.2.0"

    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.google.firebase:firebase-messaging:20.1.0'
    implementation 'com.android.support:multidex:1.0.3'
    // Import the Firebase BoM
    implementation platform('com.google.firebase:firebase-bom:28.0.1')
        implementation('com.google.firebase:firebase-auth') {
            exclude module: "play-services-safetynet"
        }

    implementation("com.google.firebase:firebase-iid")

    // When using the BoM, you don't specify versions in Firebase library dependencies

    // Declare the dependency for the Firebase SDK for Google Analytics
    implementation 'com.google.firebase:firebase-analytics-ktx'

    // Declare the dependencies for any other desired Firebase products
    // For example, declare the dependencies for Firebase Authentication and Cloud Firestore
    implementation 'com.google.firebase:firebase-auth-ktx'
    implementation 'com.google.firebase:firebase-firestore-ktx'


}
Android Flutter Maven android-gradle-插件

评论


答:

0赞 ItzDavi 6/13/2023 #1

我认为 Jcenter 和 Maven 不再受支持,否则它们很快就会死去。

这是正确的 build.gradle 结构:

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

    dependencies {
        classpath 'com.android.tools.build:gradle:7.4.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.21"
    }
}

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

Maven已替换为 。JCenter 不再可用。如果这解决了您的问题,请告诉我,祝您编码愉快!MavenCentral

评论

0赞 reza kia 6/13/2023
我根据您的建议测试了 mavencentral(),但错误仍然存在。Iam 使用 gradle 7.1.2
0赞 ItzDavi 6/13/2023
你能添加更新的build.gradle吗?@rezakia
0赞 reza kia 6/14/2023
我可以提供整个项目供您测试@Davide
0赞 ItzDavi 6/14/2023
所以它没有用?
1赞 reza kia 6/14/2023
没有@Davide。我面对这个问题很长一段时间,我几乎放弃了使用 Flutter 编程,这就是我今天有想法的原因。今天我冒了风险,完全删除了 C:\Users*****\.gradle 文件夹,并使用命令“flutter build apk”再次尝试。我尝试构建应用程序。经过3个小时,需要下载很多文件,我惊讶地看到程序被编译了:)。