# React Native Common Issues
# 1. Can I use demos from other react-native versions?
Answer: Due to significant differences between react-native versions, it is recommended to use react-native version 0.67.4 to run our official demo.
# 2. How to clean project cache?
Answer: You can use Metro's cleaning tool (opens new window) to clean the cache.
# 3. iOS cannot run pod install on M1?
Answer: Use arch -x86_64 pod install instead of pod install.
# 4. Error when running demo: No matching variant of com.facebook.react:react-native:0.71.0-rc.0 was found
Answer: Refer to #issue-35210 (opens new window) for resolution.
# 5. Error when running react-native demo with Android Studio: Cannot run program "node": error=2, No such file or directory
Answer: Open Android Studio via terminal by entering the command: open -a /Applications/Android\ Studio.app
# 6. If encountering error: Plugin with id maven not found.
Answer: Please upgrade react-native-mopsdk to version 2.0.1.
# 7. How to upgrade react-native to a higher version (e.g., 0.73.0)?
Answer:
Use the RN official version comparison tool to view all files that need updating (e.g., upgrading from 0.67.4 to 0.73.0): https://react-native-community.github.io/upgrade-helper/?from=0.67.4&to=0.73.0
Prepare the environment: Update to the latest version of Android Studio (older versions cannot compile), install a relatively new version of JDK (JDK17-JDK20), update the node version (node 18 or above, preferably 20), and install yarn (it is said that using npm to install dependency packages sometimes causes errors).
Modify the Android project and iOS project according to step 1.
The following are the files we modified during the upgrade process:
Android Section
First, modify the gradle version: file path gradle/wrapper/gradle-wrapper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Then, modify build.gradle in the app directory (app/build.gradle)
Note that some previous libraries have been removed; therefore, references to the "ReactNativeFlipper" class may cause errors. Simply delete this class from the project. The newly added libraries already include this class, so there is no need for a custom definition in the project; just import the package. Additionally, delete the package attribute in the manifest file.
apply plugin: "com.android.application"
apply plugin: "org.jetbrains.kotlin.android"
apply plugin: "com.facebook.react"
/**
* This is the configuration block to customize your React Native Android app.
* By default you don't need to apply any configuration, just uncomment the lines you need.
*/
react {
/* Folders */
// The root of your project, i.e. where "package.json" lives. Default is '..'
// root = file("../")
// The folder where the react-native NPM package is. Default is ../node_modules/react-native
// reactNativeDir = file("../node_modules/react-native")
// The folder where the react-native Codegen package is. Default is ../node_modules/@react-native/codegen
// codegenDir = file("../node_modules/@react-native/codegen")
// The cli.js file which is the React Native CLI entrypoint. Default is ../node_modules/react-native/cli.js
// cliFile = file("../node_modules/react-native/cli.js")
/* Variants */
// The list of variants to that are debuggable. For those we're going to
// skip the bundling of the JS bundle and the assets. By default is just 'debug'.
// If you add flavors like lite, prod, etc. you'll have to list your debuggableVariants.
// debuggableVariants = ["liteDebug", "prodDebug"]
/* Bundling */
// A list containing the node command and its flags. Default is just 'node'.
// nodeExecutableAndArgs = ["node"]
//
// The command to run when bundling. By default is 'bundle'
// bundleCommand = "ram-bundle"
//
// The path to the CLI configuration file. Default is empty.
// bundleConfig = file(../rn-cli.config.js)
//
// The name of the generated asset file containing your JS bundle
// bundleAssetName = "MyApplication.android.bundle"
//
// The entry file for bundle generation. Default is 'index.android.js' or 'index.js'
// entryFile = file("../js/MyApplication.android.js")
//
// A list of extra flags to pass to the 'bundle' commands.
// See https://github.com/react-native-community/cli/blob/main/docs/commands.md#bundle
// extraPackagerArgs = []
/* Hermes Commands */
// The hermes compiler command to run. By default it is 'hermesc'
// hermesCommand = "$rootDir/my-custom-hermesc/bin/hermesc"
//
// The list of flags to pass to the Hermes compiler. By default is "-O", "-output-source-map"
// hermesFlags = ["-O", "-output-source-map"]
}
/**
* Set this to true to Run Proguard on Release builds to minify the Java bytecode.
*/
def enableProguardInReleaseBuilds = false
/**
* The preferred build flavor of JavaScriptCore (JSC)
*
* For example, to use the international variant, you can use:
* `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
*
* The international variant includes ICU i18n library and necessary data
* allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
* give correct results when using with locales other than en-US. Note that
* this variant is about 6MiB larger per architecture than default.
*/
def jscFlavor = 'org.webkit:android-jsc:+'
android {
ndkVersion rootProject.ext.ndkVersion
compileSdk rootProject.ext.compileSdkVersion
namespace "com.finogeeks.finclip.demo"
defaultConfig {
applicationId "com.finogeeks.finclip.demo"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
}
signingConfigs {
debug {
storeFile file('debug.keystore')
storePassword 'android'
keyAlias 'androiddebugkey'
keyPassword 'android'
}
}
buildTypes {
debug {
signingConfig signingConfigs.debug
}
release {
// Caution! In production, you need to generate your own keystore file.
// see https://reactnative.dev/docs/signed-apk-android.
signingConfig signingConfigs.debug
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
}
dependencies {
// The version of react-native is set by the React Native Gradle Plugin
implementation("com.facebook.react:react-android")
implementation("com.facebook.react:flipper-integration")
if (hermesEnabled.toBoolean()) {
implementation("com.facebook.react:hermes-android")
} else {
implementation jscFlavor
}
}
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
Then, modify build.gradle in the root directory
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
buildToolsVersion = "33.0.1"
minSdkVersion = 21
compileSdkVersion = 33
targetSdkVersion = 33
// We use NDK 23 which has both M1 support and is the side-by-side NDK version from AGP.
ndkVersion = "23.1.7779620"
}
repositories {
google()
jcenter()
google()
jcenter()
maven {
url "https://gradle.finogeeks.club/repository/applet/"
credentials {
username "applet"
password "123321"
}
}
maven { url "https://jitpack.io" }
}
dependencies {
classpath('com.android.tools.build:gradle:8.3.0')
classpath("com.facebook.react:react-native-gradle-plugin")
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url("$rootDir/../node_modules/react-native/android")
}
maven {
// Android JSC is installed from npm
url("$rootDir/../node_modules/jsc-android/dist")
}
google()
jcenter()
maven {
url "https://gradle.finogeeks.club/repository/applet/"
credentials {
username "applet"
password "123321"
}
}
maven { url "https://jitpack.io" }
}
}
iOS Section First, modify the podfile (replace content using the suggested version).
# Resolve react_native_pods.rb with node to allow for hoisting
require Pod::Executable.execute_command('node', ['-p',
'require.resolve(
"react-native/scripts/react_native_pods.rb",
{paths: [process.argv[1]]},
)', __dir__]).strip
platform :ios, min_ios_version_supported
prepare_react_native_project!
# If you are using a `react-native-flipper` your iOS build will fail when `NO_FLIPPER=1` is set.
# because `react-native-flipper` depends on (FlipperKit,...) that will be excluded
#
# To fix this you can also exclude `react-native-flipper` using a `react-native.config.js`
# ```js
# module.exports = {
# dependencies: {
# ...(process.env.NO_FLIPPER ? { 'react-native-flipper': { platforms: { ios: null } } } : {}),
# ```
flipper_config = ENV['NO_FLIPPER'] == "1" ? FlipperConfiguration.disabled : FlipperConfiguration.enabled
linkage = ENV['USE_FRAMEWORKS']
if linkage != nil
Pod::UI.puts "Configuring Pod with #{linkage}ally linked Frameworks".green
use_frameworks! :linkage => linkage.to_sym
end
target 'example'do
config = use_native_modules!
use_react_native!(
:path => config[:reactNativePath],
# Enables Flipper.
#
# Note that if you have use_frameworks! enabled, Flipper will not work and
# you should disable the next line.
:flipper_configuration => flipper_config,
# An absolute path to your application root.
:app_path => "#{Pod::Config.instance.installation_root}/.."
)
target 'exampleTests'do
inherit! :complete
# Pods for testing
end
post_install do |installer|
# https://github.com/facebook/react-native/blob/main/packages/react-native/scripts/react_native_pods.rb#L197-L202
react_native_post_install(
installer,
config[:reactNativePath],
:mac_catalyst_enabled => false
)
end
end
Then, modify the content in AppDelegate.
If encountering FlipperTransportTypes.h' error, you can add this segment in the podfile (because #include <functional> is missing in the header file).
installer.pods_project.targets.each do |target|
if target.name == 'Flipper'
file_path = 'Pods/Flipper/xplat/Flipper/FlipperTransportTypes.h'
contents = File.read(file_path)
unless contents.include?('#include <functional>')
File.open(file_path, 'w') do |file|
file.puts('#include <functional>')
file.puts(contents)
end
end
end
end
# 8. How to customize the loading page?
- Create a subclass inheriting from FATBaseLoadingView within the iOS project.
@interface LoadingView : FATBaseLoadingView
@end
@implementation LoadingView
- (instancetype)initWithFrame:(CGRect)frame {
if ([super initWithFrame:frame]) {
// Adjust view properties here
self.loadingView.dotView.backgroundColor = [UIColor blackColor];
self.loadingView.animation.duration = 5;
self.titleLabel.textColor = [UIColor redColor];
}
return self;
}
- (void)layoutSubviews
{
[super layoutSubviews];
// Adjust view layout, etc., here.
// If modifying the logo, it must be done here.
// Note: Modifying the Mini-Program logo should be done by uploading a new Mini-Program icon from the Management Console, because the More Panel and About page will also display the Mini-Program logo. Modifying it here only affects the loading page.
self.loadingView.iconImageView.image = [UIImage imageNamed:@"mini_logo"];
}
@end
- Create a custom loading view within the Android project, inheriting from IFinAppletLoadingPage.
class CustomLoadingPage constructor(context: Context) : IFinAppletLoadingPage(context) {
override fun getFailureLayoutRes(): Int {
// Error page layout resource file
return R.layout.loading_failure_layout
}
override fun getLoadingLayoutRes(): Int {
// Loading page layout resource file
return R.layout.loading_layout
}
override fun onLoadingFailure(msg: String) {
// This method is deprecated, leave it empty, please use the following onLoadingFailure(title: String, msg: String)
}
override fun onLoadingFailure(title: String, msg: String) {
// Error page error message body
failureLayout.findViewById<TextView>(R.id.tvLoadingFailedTitle).text = title
failureLayout.findViewById<TextView>(R.id.tvLoadingFailedMsg).text = msg
}
override fun onUpdate(appTitle: String, appAvatarUrl: String) {
// Loading page Mini-Program name
loadingLayout.findViewById<TextView>(R.id.tvTitle).text = appTitle
// Loading page Mini-Program icon
ImageLoader.get(context).load(appAvatarUrl, object : DrawableCallback {
override fun onLoadFailure() {
}
override fun onLoadSuccess(r: Drawable) {
val ivAvatar = loadingLayout.findViewById<RoundedImageView>(R.id.ivAvatar)
// Do not directly use Handler post to set the icon. First check if it is the main thread. If it is the main thread, set the icon directly,
// to avoid delayed icon display caused by Handler post when updating on the main thread.
if (Looper.myLooper() == Looper.getMainLooper()) {
ivAvatar.setImageDrawable(r)
} else {
handler.post {
ivAvatar.setImageDrawable(r)
}
}
}
})
}
}
- Implement the corresponding layout files for Android
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/fin_color_bg_pure_auto"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/rlLoading"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true">
<FrameLayout
android:id="@+id/flAvatar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true">
<com.finogeeks.lib.applet.modules.appletloadinglayout.FinAppletLoadingSurfaceView
android:id="@+id/finAppletLoadingView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
<com.finogeeks.lib.applet.externallib.makeramen.roundedimageview.RoundedImageView
android:id="@+id/ivAvatar"
android:layout_width="52dp"
android:layout_height="52dp"
android:layout_gravity="center"
android:src="@color/color_ebeced"
app:fin_applet_riv_corner_radius="6dp" />
</FrameLayout>
<TextView
android:id="@+id/tvTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/flAvatar"
android:layout_centerHorizontal="true"
android:ellipsize="end"
android:gravity="center"
android:maxLines="2"
android:textAlignment="center"
android:textColor="@color/fin_color_text_auto"
android:textSize="18sp"
android:textStyle="bold" />
</RelativeLayout>
<ImageView
android:id="@+id/ivTechSupport"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="45dp"
android:src="@drawable/fin_applet_tech_support"
android:visibility="gone"
tools:visibility="visible" />
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/fin_color_bg_pure_auto"
android:orientation="vertical">
<TextView
android:id="@+id/tvAppName"
android:layout_width="wrap_content"
android:layout_height="@dimen/fin_applet_navbar_height"
android:layout_alignParentTop="@+id/rlLoadingFailed"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:gravity="center"
android:textColor="@color/fin_color_text_auto"
android:textSize="18sp"
android:textStyle="bold"
android:visibility="gone"
tools:text="Mini-Program Name"
tools:visibility="visible" />
<RelativeLayout
android:id="@+id/rlLoadingFailed"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="125dp">
<ImageView
android:id="@+id/ivLoadingFailed"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_centerHorizontal="true"
android:src="@drawable/fin_applet_loading_error"
tools:ignore="ContentDescription" />
<TextView
android:id="@+id/tvLoadingFailedTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/ivLoadingFailed"
android:layout_centerHorizontal="true"
android:layout_marginTop="25dp"
android:gravity="center"
android:text="@string/fin_applet_loading_failed_tip_without_message"
android:textColor="@color/fin_color_text_auto"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="@+id/tvLoadingFailed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tvLoadingFailedTitle"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp"
android:gravity="center"
android:textColor="@color/fin_color_secondary_text_auto"
android:textSize="15sp"
tools:text="Error Message" />
</RelativeLayout>
<!-- Note: fin_btn_fail_reload_margin_bottom distance may differ between portrait and landscape modes. -->
<TextView
android:id="@+id/btnFailReload"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="@dimen/fin_btn_fail_reload_margin_bottom"
android:background="@drawable/fin_applet_btn_reload_blue"
android:gravity="center"
android:minWidth="200dp"
android:text="@string/fin_applet_load_again"
android:textColor="@android:color/white"
android:textSize="15sp" />
</RelativeLayout>
- When initializing the SDK, set the custom loading view classes for Android and iOS
// iOS sets baseLoadingViewClass; Android sets loadingLayoutCls
let config = new Config(finStoreConfigs, {
language:LanguageType.Chinese,
userId:"123456789",
debug:true,
appletDebugMode:BOOLState.BOOLStateTrue,
baseLoadingViewClass:"LoadingView"
}) ;
let uiConfig = new UIConfig({
isHideClearCacheMenu:true,
loadingLayoutCls:"com.example.MyAppletLoadingPage"
});