6

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.

MXC
  • 458
  • 1
  • 5
  • 21

4 Answers4

2

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'
...
}
memres
  • 439
  • 2
  • 9
1

Add the repositories into the settings.gradle like this ->

dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
    google()
    mavenCentral()
    
    maven {
        url '/Users/asharma/Documents/Flutter/animation_module/build/host/outputs/repo'
    }
    maven {
        url 'http://download.flutter.io'
    }
}

}

0

I have the same issue and solve it adding in repositories of settings.gradle inside of dependencyResolutionManagement

dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
repositories {
    google()
    mavenCentral()
    maven {
        url '/yourpath/your_flutter_module/build/host/outputs/repo'
    }
    maven {
        url 'https://storage.googleapis.com/download.flutter.io'
    }
  }
}
rcorbellini
  • 1,307
  • 1
  • 21
  • 42
-2

I have the same problem, it is solved by setting the configurations

android {
    buildTypes {
        release {
            ....
        }
        profile {
            ....
        }
        debug {
            ....
        }
    }
}

configurations {
    // Initializes a placeholder for the profileImplementation dependency configuration
    profileImplementation {}
}

dependencies {
        debugImplementation xxx
        // Then it can work
        profileImplementation xxx
        releaseImplementation xxx

}

Picking a specific build type in a dependency

zhy
  • 17
  • 2
  • 1
    Don't copy-paste and link your own answers. If you think that this question can benefit from the exact same answer as another question - this might suggest that tis question is a duplicate and should be flagged – Tomerikoo Nov 05 '20 at 12:31