google模式:
第一步:项目目录下创建moudle。命令是:flutter create -t module name //注意name就是你的module 名称
第二步:setting.gradle 下面加上这么一段话
setBinding(new Binding([gradle:this])) evaluate(new File( settingsDir.parentFile, 'AndroidMixNativeAndFlutter/flutter_pinbo/.android/include_flutter.groovy'//这个地方是路径,要把项目外层路径也写进去 ))
同步之后就创建了module
第三步:app的gradle里面添加依赖
implementation project (':flutter:')
这个是写死的,不会变动,另外如果报错了
Manifest merger failed : uses-sdk:minSdkVersion 15 cannot be smaller than version 16 declared in library [:flutter] I:\android_project\fluter_project\AndroidMixNativeAndFlutter\flutter_pinbo\.android\Flutter\build\intermediates\merged_manifests\debug\processDebugManifest\merged\AndroidManifest.xml as the library might be using APIs not available in 15 Suggestion: use a compatible library with a minSdk of at most 15, or increase this project's minSdk version to at least 16, or use tools:overrideLibrary="com.example.flutter_pinbo" to force usage (may lead to runtime failures)
检查一下,两边的sdk设置是否统一
第四部:在原生中就可以这样用了
FlutterView flutterView = Flutter.createView(this, getLifecycle(), "route01"); FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); addContentView(flutterView,layoutParams);
出现这样错误:Error: Invoke-customs are only supported starting with Android O (--min-api 26)
flutter支持的版本比较高,老手机无法支持了
另外 gradle wrapper的版本要升级到4.10.1
工具的版本到 classpath 'com.android.tools.build:gradle:3.3.1'
所以这个混合开发,老手机是别玩了