Skip to content

Commit bf52953

Browse files
sfshaza2camsim99johnpryandomesticmouse
authored
Docs: Clarify native code placement in Flutter modules (#12968)
Fixes #12960. Clarifies that the .android folder is ephemeral and that native code should be placed in Plugins or the Host App. --------- Co-authored-by: Camille Simon <[email protected]> Co-authored-by: John Ryan <[email protected]> Co-authored-by: Brett Morgan <[email protected]>
1 parent c80fa26 commit bf52953

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

src/content/add-to-app/android/project-setup.md

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -122,37 +122,39 @@ follow these steps:
122122

123123
#### Create a Flutter module
124124

125-
Let's assume that you have an existing Android app at
125+
Assuming that you have an existing Android app at
126126
`some/path/MyApp`, and that you want your Flutter
127-
project as a sibling:
127+
project as a sibling, do the following:
128128

129129
```console
130130
cd some/path/
131131
flutter create -t module --org com.example flutter_module
132132
```
133133

134134
This creates a `some/path/flutter_module/` Flutter module project
135-
with some Dart code to get you started and an `.android/`
135+
with some Dart code to get you started and a `.android/`
136136
hidden subfolder. The `.android` folder contains an
137137
Android project that can both help you run a barebones
138-
standalone version of your Flutter module via `flutter run`
138+
standalone version of your Flutter module with `flutter run`
139139
and it's also a wrapper that helps bootstrap the Flutter
140140
module an embeddable Android library.
141141

142-
:::note
143-
Add custom Android code to your own existing
144-
application's project or a plugin,
145-
not to the module in `.android/`.
146-
Changes made in your module's `.android/`
147-
directory won't appear in your existing Android
148-
project using the module.
149-
150-
Do not source control the `.android/` directory
151-
since it's autogenerated. Before building the
152-
module on a new machine, run `flutter pub get`
153-
in the `flutter_module` directory first to regenerate
154-
the `.android/` directory before building the
155-
Android project using the Flutter module.
142+
:::warning
143+
**Do not** edit files in `.android/` to add native functionality.
144+
This folder is generated for testing purposes and **will be overwritten**
145+
whenever you run `flutter pub get` or build the module.
146+
147+
* To add native code that you can use across apps/modules,
148+
create a [Flutter Plugin](/packages-and-plugins/developing-packages#plugin)
149+
and depend on it.
150+
* To add **app-specific** native code,
151+
add it directly to your existing Android host application.
152+
153+
The `.android` directory contains a generated Android project that uses Java
154+
to bootstrap the Flutter module, so **do not** add it to source control.
155+
This approach helps you run a barebones standalone version
156+
of your Flutter module (with `flutter run`) and verify basic functionality.
157+
Using Java here doesn't prevent you from using Kotlin in your host app or plugins.
156158
:::
157159

158160
:::note

0 commit comments

Comments
 (0)