Cannot find local aar built through Flutter Module

684

I have a project with several library modules and an app module. I faced the same issue as I wanted to start the flutter module from one of my library modules.

I solved it by adding

repositories {
maven {
    url '../path/to_your/flutter_repo'
}
maven {
    url 'https://storage.googleapis.com/download.flutter.io'
}

in both app module and library module build.gradle

I didn't need mavenLocal().

I also needed to add

profile {
    initWith debug
}

in each modules build.gradle.

This is now how my app module and library module build.gradle looks like:

App module build.gradle:

plugins {
    id 'com.android.application'
}

repositories {
    maven {
        url '../core/webshop/flutter_repo'
    }
    maven {
        url 'https://storage.googleapis.com/download.flutter.io'
    }
}

android {
    compileSdkVersion toolVersions.compileSdk

    defaultConfig {
       ...
    }

    signingConfigs {
        release {
            ...
        }
    }

    buildTypes {
        release {
            ...
        }
        profile {
            initWith debug
        }
    }

    compileOptions {
        sourceCompatibility 1.8
        targetCompatibility 1.8
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    // Project modules
    implementation project('your_lib_module1')
    implementation project('your_lib_module2')
    ...

}

Library module build.gradle, where you want to add flutter module:

apply plugin: 'com.android.library'

repositories {
    maven {
        url './flutter_repo'
    }
    maven {
        url 'https://storage.googleapis.com/download.flutter.io'
    }
}

android {
    compileSdkVersion toolVersions.compileSdk

    defaultConfig {
        ...
    }

    buildTypes {
        release {
            ...
        }

        profile {
            initWith debug
        }
    }

    compileOptions {
        sourceCompatibility 1.8
        targetCompatibility 1.8
    }

    kotlinOptions {
        jvmTarget = "1.8"
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    // Project modules
    implementation project('your_lib_module3')

    // flutter
    debugImplementation 'com.example.animation_module:flutter_debug:1.0'
    profileImplementation 'com.example.animation_module:flutter_profile:1.0'
    releaseImplementation 'com.example.animation_module:flutter_release:1.0'
...
}
Share:
684
MXC
Author by

MXC

Updated on December 20, 2022

Comments

  • MXC
    MXC over 1 year

    I am trying to add the flutter module as aar dependency on my Android Project. Here is the guide https://flutter.dev/docs/development/add-to-app/android/project-setup#add-the-flutter-module-as-a-dependency I am able to generate the local AAR and I can see these steps to be done:

     1. Open <host>/app/build.gradle
      2. Ensure you have the repositories configured, otherwise add them:
    
          repositories {
            maven {
                url '/Users/asharma/Documents/Flutter/animation_module/build/host/outputs/repo'
            }
            maven {
                url 'http://download.flutter.io'
            }
          }
    
      3. Make the host app depend on the Flutter module:
    
        dependencies {
          debugImplementation 'com.example.animation_module:flutter_debug:1.0
          profileImplementation 'com.example.animation_module:flutter_profile:1.0
          releaseImplementation 'com.example.animation_module:flutter_release:1.0
        }
    
    
      4. Add the `profile` build type:
    
        android {
          buildTypes {
            profile {
              initWith debug
            }
          }
        }
    

    In my Android project, I have app module and library module. I want to include this aar in my library module, here is my library module build.gradle

    apply plugin: 'com.android.library'
    apply plugin: 'kotlin-android'
    apply plugin: 'kotlin-android-extensions'
    
    android {
        compileSdkVersion 29
        buildToolsVersion "29.0.2"
    
        defaultConfig {
            minSdkVersion 21
            targetSdkVersion 29
            versionCode 1
            versionName "1.0"
    
            testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
            consumerProguardFiles 'consumer-rules.pro'
        }
    
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            }
            profile {
                initWith debug
            }
        }
    
    }
    
    dependencies {
        debugImplementation 'com.example.animation_module:flutter_debug:1.0'
        profileImplementation 'com.example.animation_module:flutter_profile:1.0'
        releaseImplementation 'com.example.animation_module:flutter_release:1.0'
    }
    
    repositories {
        maven {
            url '/Users/asharma/Documents/Flutter/animation_module/build/host/outputs/repo'
        }
        maven {
            url 'http://download.flutter.io'
        }
    }
    

    I have also added mavenLocal() at my project's build.gradle in repository. (Tried with and without it) But dependencies are not resolved. I get an error:

    Could not find com.example.animation_module:flutter_debug:1.0.
    Searched in the following locations:
      - https://dl.google.com/dl/android/maven2/com/example/animation_module/flutter_debug/1.0/flutter_debug-1.0.pom
      - https://dl.google.com/dl/android/maven2/com/example/animation_module/flutter_debug/1.0/flutter_debug-1.0.jar
      - https://jcenter.bintray.com/com/example/animation_module/flutter_debug/1.0/flutter_debug-1.0.pom
      - https://jcenter.bintray.com/com/example/animation_module/flutter_debug/1.0/flutter_debug-1.0.jar
    Required by:
        project :app > project :animation_flutter_sdk
    

    I know dependency is not present on the remote at https://dl.google.com but it is present in my local and gradle should pick it up from my local. Please help me how to build this project.