0

I am working on creating an Android SDK module that includes a Flutter module. I have followed the instructions provided in the official Flutter documentation here to integrate the Flutter module into my Android project.

setBinding(new Binding([gradle: this]))
evaluate(new File(                                                     
settingsDir.parentFile,                                            // new
'flutter_module/.android/include_flutter.groovy'                   // new
))                                                                     // new

I have also added the Flutter module as a dependency in my app/build.gradle file within my Android module.

implementation project(':flutter')

I have successfully integrated the Flutter module with a method channel, and it's working as expected.

Now, my challenge is in creating an AAR artifact library that includes the complete Flutter modules. When I generate the AAR artifact using the following Gradle code snippet, the sub-modules are not included in the library:

group = 'com.example.myAndroidSdk'
version = '1.0.0'


// Add sources as an artifact
task sourceJar(type: Jar) {
    from android.sourceSets.main.java.srcDirs
    classifier "source"
}


// Loop over all variants
android.libraryVariants.all { variant ->
    variant.outputs.all { output ->
        // This creates a publication for each variant
        publishing.publications.create(variant.name, MavenPublication) {
            // The sources artifact from earlier
            artifact sourceJar

            // Variant dependent artifact, e.g. release, debug
            artifact source: output.outputFile, classifier: output.name

            // Go through all the dependencies for each variant and add them to the POM
            // file as dependencies
            pom.withXml {
                def dependencies = asNode().appendNode('dependencies')

                // Filter out anything that's not an external dependency. You shouldn't
                // be publishing artifacts that depend on local (e.g. project) dependencies,
                // but who knows...
                configurations.getByName(variant.name + "CompileClasspath").allDependencies
                        .findAll { it instanceof ExternalDependency }
                        .each {
                            def dependency = dependencies.appendNode('dependency')

                            dependency.appendNode('groupId', it.group)
                            dependency.appendNode('artifactId', it.name)
                            dependency.appendNode('version', it.version)
                        }
            }
        }
    }
}

// Ensure that the publish task depends on assembly
tasks.all { task ->
    if (task instanceof AbstractPublishToMaven) {
        task.dependsOn assemble
    }
}

How can I ensure that the complete Flutter modules are included in my Android AAR artifact? What modifications or additional steps do I need to take?

3
  • Did you see: docs.flutter.dev/add-to-app/android/… Commented Oct 19, 2023 at 9:10
  • @MorrisonChang:I have integrated it following the steps outlined in this Flutter documentation link('docs.flutter.dev/add-to-app/android/…). I have also tried building the AAR using 'flutter build aar -v', but the sub dependencies are still not included. Commented Oct 19, 2023 at 10:39
  • It would probably help to describe in detail how your Flutter project is organized (dependencies & sub dependencies) and stating any errors/warning encountered when doing flutter build aar. Possibly related: github.com/flutter/flutter/issues/39707 Commented Oct 19, 2023 at 17:05

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.