# flutter_app_lib **Repository Path**: CarGuo/flutter_app_lib ## Basic Information - **Project Name**: flutter_app_lib - **Description**: 这是一个测试将 Flutter 工程打包成 aar 的项目,单纯支持 Android,测试混合开发结合的可行性。 - **Primary Language**: Dart - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2019-05-21 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ### Flutter Lib 这是一个测试将 Flutter 工程打包成 aar 的项目,单纯支持 Android,测试混合开发结合的可行性。 flutter packages get 之后,执行 flutter clean,之后在android目录下执行 ./gradlew assembleRelease - flutter_shared 的问题已经修复,但是 `--local-engine` 执行下依然后问题 [#21107](https://github.com/flutter/flutter/issues/21107) flutter 在打包成 aar 上比 react native 简单的原因,在于它不像 react native 那样需要 link 本地的 project - 添加完插件如果存在原生代码,会在项目里生产一个 `.flutter-plugins` 会包含有插件相关的信息 之后 `setting.gradle` ``` def flutterProjectRoot = rootProject.projectDir.parentFile.toPath() def plugins = new Properties() def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins') if (pluginsFile.exists()) { pluginsFile.withReader('UTF-8') { reader -> plugins.load(reader) } } ///include进去 plugins.each { name, path -> def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile() include ":$name" project(":$name").projectDir = pluginDirectory } ``` 之后在 app 中会使用 build.gradle ``` apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" ``` 之后在 flutter.gradle 中 include 进来。 ``` File pluginsFile = new File(project.projectDir.parentFile.parentFile, '.flutter-plugins') Properties plugins = readPropertiesIfExist(pluginsFile) plugins.each { name, _ -> def pluginProject = project.rootProject.findProject(":$name") if (pluginProject != null) { project.dependencies { if (project.getConfigurations().findByName("implementation")) { implementation pluginProject } else { compile pluginProject } } pluginProject.afterEvaluate { pluginProject.android.buildTypes { profile { initWith debug } } } pluginProject.afterEvaluate this.&addFlutterJarCompileOnlyDependency } else { project.logger.error("Plugin project :$name not found. Please update settings.gradle.") } } ``` #### 所以你需要 fat-aar 来做这件事情,因为打包 aar 时本地工程是不会打包进去的,所以需要在 dependencies 中通过配置读取相关的文件配置