A Record of Problems with a Cross-platform Architecture Migration
Recently, we have made some cross-platform migration attempts, from pure RN architecture applications to general cross-platform applications. The migration process involves cross-platform technologies such as React Native and Flutter, and also encountered many problems. This article briefly records some of them and hoping to bring a little help to the reader.
Problem And Solution
The
hot-reloadoperation can be performed normally by usingflutter runin the terminal but not Android Studio.Solution: Set
no_proxyin the shell environment. For example, append the following line to the.zshrcfile.1
export no_proxy="localhost,127.0.0.1"
What a magic trick.
When we press the shortcut for auto-format function in Android Studio by using
Dartlanguage, sometimes formatting will format the parameters on the same line.Solution: Append
,to the final parameter.When we import
Flutteras Module to the Android project, the right action isNew Module->import flutter model, and then, clickSync Project With Gradle Filesto display the folder ofFlutter.If the application has already used the
AndroidXlibraries, notice that theFlutter Modulemay use theSupportlibraries by default.When using
Flutter, we may meet the problemDart SDK is not configured.Solution: Set the
DartSDK path manually. OpenFile->Setting->Language & Frameworks->Dart, and then, check theenable Dart support for the project, set the child path ofFlutteras SDK version. For example, we should set the SDK path as$FLUTTER\bin\cache\dart-sdkif we assume the path ofFlutteris$FLUTTER.After using AndroidX, the files generated by the
Fluttermodule need to be modified accordingly. In addition to changing theSupportpackage to theAndroidXpackage, you also need to modify the Gradle version. It is recommended to useRefactor->Migrate to AndroidX ...for migration.There are reference links below:
The code generated by using
Fluttercan be modified locally. For example,FlutterandFlutter Boostcontain AndroidSupportlibraries. Without modifying the remote repository, it can be changed toAndroidXlocally.The migration of AndroidX is not very compatible with abnormal modules such as Flutter, even if
android.useAndroidX = trueandandroid.enableJetifier = truehave been defined ingradle.properties.The
Fluttermodule of the remote project may only have the code without the compiled.androidfolder and the prerequisite for the Android project to correctly recognize theFluttermodule are to generate the folder, so you need to open theFluttermodule and then runflutter package get.After using
Flutteras anAndroidmodule for hybrid programming, the way ofFlutterbreakpoints are debugged has changed. When you need to run a complete project for debugging, the process should be to install the app, then close the app, perform theFlutterattach operation in theFluttermodule window, and then start the app to debug theFluttercode normally.Some problem with
method channel:Q: Can the
method channelbe registered repeatedly on the sameFlutterpage (using the same name)?
A: Yes, and they will be the same instance.Q: Can the
method channelbe registered repeatedly on the differentFlutterpage (using the same name)?
A: Yes, and they will be the same instance.Q: Does the
method channelinstantiate the same instance on different pages using the default method?
A: No.Q: Will different callbacks of the same
method channelaffect each other?
A: It is interesting that although it is the samemethod channel, callbacks will not affect each otherWhen
React Nativeexchanges data with nativeAndroid, the corresponding data structure is different. Themapon theRNside isReadableMapandWritableMaponAndroid, and theRN‘sNumbertype will be converted toDoublewhen acquired on theAndroidside, which requires special handling. And because there is noLongtype on theRNside, and the accuracy of theLongtype andDoubletype is different, special attention is required.
Some notes about Dart
Dartalso have null-aware.??equals to?:inKotlin??=means it can be assigned a value only when it was null, which is different fromKotlinx?.pequals tox?.pinKotlinx?.m()equals tox?.m()inKotlin
DartsupportsMethod Cascades...is a cascading operator, which calls the method and discards the result, returning the original object. An example is as follows:1
2
3
4mTokenTable
..add("aToken");
..add("anotherToken");
..add("theUmpteenthToken");It should be noted that, unlike chain expressions, each line of a cascade call has a characteristic semicolon of dart;
- Blog Link: https://symeonchen.com/2019/08/26/a-record-of-problems-with-a-cross-platform-architecture-migration/
- Copyright Declaration: All articles are original and follow the CC BY-NC-SA 4.0 protocol.