reza kia
reza kia

Reputation: 163

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

flutter build appbundle

Flutter assets will be downloaded from https://storage.googleapis.com. Make sure you trust this source! Parameter format not correct -

FAILURE: Build completed with 2 failures.

1: Task failed with an exception.

Could not resolve all files for configuration ':connectivity:releaseCompileClasspath'. Failed to transform lifecycle-runtime-2.2.0.jar (androidx.lifecycle:lifecycle-runtime:2.2.0) to match attributes {artifactType=android-classes-jar, org.gradle.category=library, org.gradle.libraryelements=jar, org.gradle.status=release, org.gradle.usage=java-api}. > Could not find lifecycle-runtime-2.2.0.jar (androidx.lifecycle:lifecycle-runtime:2.2.0). Searched in the following locations: https://dl.google.com/dl/android/maven2/androidx/lifecycle/lifecycle-runtime/2.2.0/lifecycle-runtime-2.2.0.jar

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. ==============================================================================

2: Task failed with an exception.

Could not resolve all files for configuration ':firebase_core:releaseCompileClasspath'. Failed to transform lifecycle-runtime-2.2.0.jar (androidx.lifecycle:lifecycle-runtime:2.2.0) to match attributes {artifactType=android-classes-jar, org.gradle.category=library, org.gradle.libraryelements=jar, org.gradle.status=release, org.gradle.usage=java-api}. > Could not find lifecycle-runtime-2.2.0.jar (androidx.lifecycle:lifecycle-runtime:2.2.0). Searched in the following locations: https://dl.google.com/dl/android/maven2/androidx/lifecycle/lifecycle-runtime/2.2.0/lifecycle-runtime-2.2.0.jar

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. ==============================================================================

BUILD FAILED in 1m 28s Running Gradle task 'bundleRelease'... 89.6s Gradle task bundleRelease failed with exit code 1

i am ussing gradle:


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

and my app/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
}

and 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'


}

Upvotes: 0

Views: 665

Answers (1)

ItzDavi
ItzDavi

Reputation: 1078

Jcenter and Maven I think are not longer supported, or they will die soon.

This is the correct build.gradle structure:

...
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 has been replaced with MavenCentral. And JCenter is no more available. Let me know if this solved your problem, happy coding!

Upvotes: 0

Related Questions