Home > Software design >  How to solve Flutter error with gradle 1151
How to solve Flutter error with gradle 1151

Time:02-03

After an upgrade of my flutter , i am having this issue on all my projects :

Target kernel_snapshot failed: Exception


FAILURE: Build failed with an exception.

* Where:
Script '/home/nunyalab/snap/flutter/common/flutter/packages/flutter_tools/gradle/flutter.gradle' line: 1151

here are my gradle files

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

dependencies {

    classpath 'com.android.tools.build:gradle:7.2.0'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    classpath 'com.google.gms:google-services:4.3.14'
}
 }

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

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

and

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'

android { compileSdkVersion 33 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.pikipikiafrica.pikirider"
    // 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 21
    targetSdkVersion 33
    versionCode 1
    versionName '1.0.0'
}

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" implementation platform('com.google.firebase:firebase-bom:26.6.0') implementation 'androidx.multidex:multidex:2.0.1' implementation 'com.mercadopago.android.px:checkout:4. ' }

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

CodePudding user response:

  1. Check your Gradle version and make sure it is up to date.

  2. Make sure you have the latest version of the Android SDK installed.

  3. Check your Flutter dependencies and make sure they are all up to date.

  4. Try running flutter clean and then rebuilding the project.

  5. If none of these steps work, try deleting the .gradle folder in your project directory and then rebuilding the project again.

CodePudding user response:

The error code 1151 in Gradle in Flutter typically occurs when a conflict arises between different versions of the same library. This can happen when multiple packages depend on different versions of the same library. To resolve this error, you can try the following steps:

Run flutter clean command in terminal Update Gradle to the latest version by updating the Gradle version in the gradle/wrapper/gradle-wrapper.properties file. Manually resolve the dependency conflict by specifying the correct version of the library in your pubspec.yaml file. If all else fails, try removing the conflicting library and re-adding it. If none of the above steps solve the problem, it's best to consult the library's documentation or seek help from the library's support forums.

  • Related