1.创建一个flutter module
flutter create -t module --org com.example my_flutter
2.在原生build.gradle下
android {
//...
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
}
3.添加Flutter模块作为依赖项 有两种方式
(1)无需安装flutter sdk Flutter库打包为由AAR和POM工件组成的通用本地Maven存储库,
(2) 需要安装sdk 原生settings.gradle下添加
// Include the host app project.
include ':app'// assumed existing content
setBinding(new Binding([gradle: this]))// new
evaluate(new File(// new
settingsDir.parentFile,// new
'my_flutter/.android/include_flutter.groovy'// new
))
原生build.gradle下
dependencies {
implementation project(':flutter')
}
4.AndroidManifest.xml
【flutter添加到android原生】@style/LaunchTheme 修改
5.启动
package com.example.myapplicationimport androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import io.flutter.embedding.android.FlutterActivityclass MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
//setContentView(R.layout.activity_main)
FlutterActivity.createDefaultIntent(this)
startActivity(
FlutterActivity
.withNewEngine()
.initialRoute("/")
.build(this)
)
}
}
推荐阅读
- 【Android进阶】Android使用 flutter
- Android 开发 3 年,被要求转 Flutter ,Flutter 真的很香吗
- Flutter主题切换 flutter redux
- Flutter AppBar入门使用
- flutter-样式
- 跨平台新潮,写给程序员的Flutter完整开发实战详解,带你玩转Flutter
- android studio flutter代理设置问题
- 适用于 Flutter 的 Google 移动广告 SDK 正式版现已发布
- 写给程序员的Flutter完整开发实战详解,轻轻松松解决跨平台烦恼