注意:Android项目和Flutter项目在同一个文件夹;
这时flutter项目就不需要动了,开始动Android项目;
- setBinding(new Binding([gradle: this]))
- evaluate(new File(
- settingsDir,
- '../flutter_m1/.android/include_flutter.groovy'
- ))
MyFlutterAndroidDemo/app/build.gradle中添加
implementation project(path: ':flutter')
【 implementation project(path: ':flutter') 写法是固定的 , 不要写成 implementation project(path: ':flutter_m1') 】
- <activity
- android:name="io.flutter.embedding.android.FlutterActivity"
- android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
- android:hardwareAccelerated="true"
- android:theme="@style/Theme.MyFlutterAndroidDemo"
- android:windowSoftInputMode="adjustResize" >
- </activity>
打开FlutterActivity就可以跳转了;
startActivity(new Intent(MainActivity.this , FlutterActivity.class));
遇到的问题:
Caused by: org.gradle.api.internal.plugins.PluginApplicationException: Failed to apply plugin class 'FlutterPlugin'.
修改Android项目settings.gradle
- repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
- 修改为:
- repositoriesMode.set(RepositoriesMode.PREFER_PROJECT)
build.gradle添加
- allprojects {
- repositories {
- google()
- mavenCentral()
- }
- }