Home > Software engineering >  Build Pipeline on BitBucket for flutter project
Build Pipeline on BitBucket for flutter project

Time:02-06

I have created pipelines for my android projects on bitbucket which are built great! I am trying to do the same for my flutter project! The first time i uploaded it in the bitbucket the project was built perfectly and the artifact was installed and played as well!

From the second time and then i get an error which i cannot understand! (i havent changed something in the project neither on the build gradle nor the .yml on the bitbucket.

This is the error i am getting:

    FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:checkReleaseAarMetadata'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
   > The minCompileSdk (31) specified in a
     dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties)
     is greater than this module's compileSdkVersion (android-30).
     Dependency: androidx.window:window-java:1.0.0-beta04.
     AAR metadata file: /root/.gradle/caches/transforms-2/files-2.1/82304f0dc7152d4b977a2625d27b0c35/jetified-window-java-1.0.0-beta04/META-INF/com/android/build/gradle/aar-metadata.properties.
* 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 4m 15s
Running Gradle task 'assembleRelease'...                          255.9s
Gradle task assembleRelease failed with exit code 1

and this is my bitbucket .yml

image: cirrusci/flutter

options:
  size: 2x
  
pipelines:
  default:
     - step:
          name: IMON
          deployment: Test
          caches:
            - gradle
          size: 2x
          script:
            - echo 'Start Building'
            - flutter clean
            - flutter build apk
            - echo 'Building Finished'
          artifacts:
            -  build/app/outputs/flutter-apk/**

and this is my app/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"
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 30

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

    lintOptions {
        disable 'InvalidPackage'
        checkReleaseBuilds false
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "example.project.flutter"
        minSdkVersion 25
        targetSdkVersion 30
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

    signingConfigs {
//        release {
//            keyAlias keystoreProperties['keyAlias']
//            keyPassword keystoreProperties['keyPassword']
//            storeFile file(keystoreProperties['storeFile'])
//            storePassword keystoreProperties['storePassword']
////            storeFile file("key.jks")
//
//        }
    }

    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
//            signingConfig signingConfigs.release
            minifyEnabled true
            shrinkResources false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.core:core:1.3.1'
    implementation 'com.google.firebase:firebase-messaging:21.0.1'
    implementation 'com.google.firebase:firebase-analytics:18.0.3'
    implementation 'com.android.support:multidex:1.0.3'
    implementation("com.google.android.gms:play-services-fitness:20.0.0")
    implementation("com.google.android.gms:play-services-auth:19.0.0")
}

Please keep in mind that i dont want to put my sdkversion at 31! i want to keep it at 30. I dont understand why the first time it worked and not all the other times. Can you please help me?

CodePudding user response:

Sounds like you have an dependency with SDK with level 31, but on your project are using SDK with level 30. You can:

  1. find dependency that use 31 level of SDK and downgrade it;
  2. set 31 level of SDK for your project.

For second solution it could be similar like this:

android {
    compileSdkVersion 31

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

    lintOptions {
        disable 'InvalidPackage'
        checkReleaseBuilds false
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "example.project.flutter"
        minSdkVersion 25
        targetSdkVersion 31
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }
    // ...
}

CodePudding user response:

So yes i made a change which worked for me well.

In the app/build.gradle i have added this one little guy:

configurations.all {
        resolutionStrategy { force 'androidx.window:window-java:1.0.0-alpha10' }
    }

which actually forces the specific version of the library. In my error as you can see it says that it crashes due to that dependency:

Dependency: androidx.window:window-java:1.0.0-beta04.
  •  Tags:  
  • Related