如何向 Android 应用添加 Flutter 屏幕

问题描述 投票:0回答:1

关于如何向 Android 应用程序添加 Flutter 屏幕的官方指南解释了如何添加一个简单的页面,但是如何添加通过 flutter 通道从本机端获取数据的屏幕。

flutter aar 中的本机调用问题:-

将模块转换为 flutter aar 后,不包含本机代码,因此本机调用将无法工作。

如何在flutter aar中添加原生代码/flutter通道代码?

android flutter plugins module aar
1个回答
0
投票

您可能会错过一些步骤。

按照说明进行操作: 添加 flutter 模块作为依赖项

运行后

flutter build aar
您需要根据控制台提示进行更多配置。

Flutter 会为你创建一个本地存储库,你需要将其路径复制到你的构建文件中。 然后将依赖项添加到您的主机应用程序。

提示如下:

Consuming the Module
  1. Open <host>/app/build.gradle
  2. Ensure you have the repositories configured, otherwise add them:

      repositories {
        maven {
            url '/Users/example/code/flutter_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.flutter_module:flutter_debug:1.0
      profileImplementation 'com.example.flutter_module:flutter_profile:1.0
      releaseImplementation 'com.example.flutter_module:flutter_release:1.0
    }


  4. Add the `profile` build type:

    android {
      buildTypes {
        profile {
          initWith debug
        }
      }
    }

To learn more, visit https://flutter.dev/go/build-aar
© www.soinside.com 2019 - 2024. All rights reserved.