如何在 Android AAR 工件库中包含完整的 Flutter 模块?

How to Include Complete Flutter Modules in Android AAR Artifact Library?

提问人:Raja Peela 提问时间:10/19/2023 更新时间:10/19/2023 访问量:33

问:

我正在创建一个包含 Flutter 模块的 Android SDK 模块。我按照官方 Flutter 文档中提供的说明将 Flutter 模块集成到我的 Android 项目中。

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

我还在我的 Android 模块的 app/build.gradle 文件中添加了 Flutter 模块作为依赖项。

implementation project(':flutter')

我已经成功地将 Flutter 模块与方法通道集成,并且它按预期工作。

现在,我面临的挑战是创建一个包含完整 Flutter 模块的 AAR 工件库。当我使用以下 Gradle 代码片段生成 AAR 工件时,子模块不包含在库中:

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
    }
}

如何确保完整的 Flutter 模块包含在我的 Android AAR 工件中?我需要采取哪些修改或其他步骤?

android flutter gradle android-gradle-plugin android-module

评论

0赞 Morrison Chang 10/19/2023
你看到了吗:docs.flutter.dev/add-to-app/android/......
0赞 Raja Peela 10/19/2023
@MorrisonChang:我已经按照这个 Flutter 文档链接中概述的步骤集成了它('docs.flutter.dev/add-to-app/android/...)。我还尝试使用'flutter build aar -v'构建 AAR,但仍然不包括子依赖项。
0赞 Morrison Chang 10/20/2023
详细描述你的 Flutter 项目是如何组织的(依赖项和子依赖项)并说明在执行 .可能相关:github.com/flutter/flutter/issues/39707flutter build aar

答: 暂无答案