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-reload
operation can be performed normally by usingflutter run
in the terminal but not Android Studio.Solution: Set
no_proxy
in the shell environment. For example, append the following line to the.zshrc
file.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
Dart
language, sometimes formatting will format the parameters on the same line.Solution: Append
,
to the final parameter.When we import
Flutter
as Module to the Android project, the right action isNew Module
->import flutter model
, and then, clickSync Project With Gradle Files
to display the folder ofFlutter
.If the application has already used the
AndroidX
libraries, notice that theFlutter Module
may use theSupport
libraries by default.When using
Flutter
, we may meet the problemDart SDK is not configured
.Solution: Set the
Dart
SDK path manually. OpenFile
->Setting
->Language & Frameworks
->Dart
, and then, check theenable Dart support for the project
, set the child path ofFlutter
as SDK version. For example, we should set the SDK path as$FLUTTER\bin\cache\dart-sdk
if we assume the path ofFlutter
is$FLUTTER
.After using AndroidX, the files generated by the
Flutter
module need to be modified accordingly. In addition to changing theSupport
package to theAndroidX
package, 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
Flutter
can be modified locally. For example,Flutter
andFlutter Boost
contain AndroidSupport
libraries. Without modifying the remote repository, it can be changed toAndroidX
locally.The migration of AndroidX is not very compatible with abnormal modules such as Flutter, even if
android.useAndroidX = true
andandroid.enableJetifier = true
have been defined ingradle.properties
.The
Flutter
module of the remote project may only have the code without the compiled.android
folder and the prerequisite for the Android project to correctly recognize theFlutter
module are to generate the folder, so you need to open theFlutter
module and then runflutter package get
.After using
Flutter
as anAndroid
module for hybrid programming, the way ofFlutter
breakpoints 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 theFlutter
attach operation in theFlutter
module window, and then start the app to debug theFlutter
code normally.Some problem with
method channel
:Q: Can the
method channel
be registered repeatedly on the sameFlutter
page (using the same name)?
A: Yes, and they will be the same instance.Q: Can the
method channel
be registered repeatedly on the differentFlutter
page (using the same name)?
A: Yes, and they will be the same instance.Q: Does the
method channel
instantiate the same instance on different pages using the default method?
A: No.Q: Will different callbacks of the same
method channel
affect each other?
A: It is interesting that although it is the samemethod channel
, callbacks will not affect each otherWhen
React Native
exchanges data with nativeAndroid
, the corresponding data structure is different. Themap
on theRN
side isReadableMap
andWritableMap
onAndroid
, and theRN
‘sNumber
type will be converted toDouble
when acquired on theAndroid
side, which requires special handling. And because there is noLong
type on theRN
side, and the accuracy of theLong
type andDouble
type is different, special attention is required.
Some notes about Dart
Dart
also have null-aware.??
equals to?:
inKotlin
??=
means it can be assigned a value only when it was null, which is different fromKotlin
x?.p
equals tox?.p
inKotlin
x?.m()
equals tox?.m()
inKotlin
Dart
supportsMethod 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;