mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
d8fa1206c3
Summary:
Co-Authored: zamotany
With React Native 0.59.8 the app keeps crashing with indexed RAM bundle on Android with the following error:
```
2019-05-09 11:58:06.684 2793-2856/? E/AndroidRuntime: FATAL EXCEPTION: mqt_js
Process: com.ramtestapp, PID: 2793
com.facebook.jni.CppException: getPropertyAsObject: property '__fbRequireBatchedBridge' is not an Object
no stack
at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:29)
at android.os.Looper.loop(Looper.java:193)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:232)
at java.lang.Thread.run(Thread.java:764)
```
After investigation we found that when using any bundle, let it be non-ram, FIle RAM bundle or Index RAM bundle, the `CatalystInstanceImpl.java` is always using `loadScriptsFromAsset`, which is calling `CatalystInstanceImpl::jniLoadScriptFromAssets` in C++. This method when checking if bundle is a RAM bundle, uses `JniJSModulesUnbundle::isUnbundle` which only check for js-modules/UNBUNDLE - file generated when building File RAM bundle. There is no other logic to handle Indexed RAM bundle, so it figures that the bundle is not RAM, cause there is no js-modules/UNBUNDLE file and tries to load as regular bundle and fails.
In this PR we added check if it is indexed RAM bundle in `jniLoadScriptFromAssets` and handle it if it is.
## Changelog
[Android] [Fixed] fix indexed RAM bundle
Solves https://github.com/facebook/react-native/issues/21282
Pull Request resolved: https://github.com/facebook/react-native/pull/24967
Differential Revision: D15575924
Pulled By: cpojer
fbshipit-source-id: 5ea428e0b793edd8242243f39f933d1092b35260
71 lines
1.9 KiB
C++
71 lines
1.9 KiB
C++
// Copyright (c) Facebook, Inc. and its affiliates.
|
|
|
|
// This source code is licensed under the MIT license found in the
|
|
// LICENSE file in the root directory of this source tree.
|
|
|
|
#pragma once
|
|
|
|
#include <istream>
|
|
#include <memory>
|
|
|
|
#include <cxxreact/JSBigString.h>
|
|
#include <cxxreact/JSModulesUnbundle.h>
|
|
|
|
#ifndef RN_EXPORT
|
|
#define RN_EXPORT __attribute__((visibility("default")))
|
|
#endif
|
|
|
|
namespace facebook {
|
|
namespace react {
|
|
|
|
class RN_EXPORT JSIndexedRAMBundle : public JSModulesUnbundle {
|
|
public:
|
|
static std::function<std::unique_ptr<JSModulesUnbundle>(std::string)> buildFactory();
|
|
|
|
// Throws std::runtime_error on failure.
|
|
JSIndexedRAMBundle(const char *sourceURL);
|
|
JSIndexedRAMBundle(std::unique_ptr<const JSBigString> script);
|
|
|
|
// Throws std::runtime_error on failure.
|
|
std::unique_ptr<const JSBigString> getStartupCode();
|
|
// Throws std::runtime_error on failure.
|
|
Module getModule(uint32_t moduleId) const override;
|
|
|
|
private:
|
|
struct ModuleData {
|
|
uint32_t offset;
|
|
uint32_t length;
|
|
};
|
|
static_assert(
|
|
sizeof(ModuleData) == 8,
|
|
"ModuleData must not have any padding and use sizes matching input files");
|
|
|
|
struct ModuleTable {
|
|
size_t numEntries;
|
|
std::unique_ptr<ModuleData[]> data;
|
|
ModuleTable() : numEntries(0) {};
|
|
ModuleTable(size_t entries) :
|
|
numEntries(entries),
|
|
data(std::unique_ptr<ModuleData[]>(new ModuleData[numEntries])) {};
|
|
size_t byteLength() const {
|
|
return numEntries * sizeof(ModuleData);
|
|
}
|
|
};
|
|
|
|
void init();
|
|
std::string getModuleCode(const uint32_t id) const;
|
|
void readBundle(char *buffer, const std::streamsize bytes) const;
|
|
void readBundle(
|
|
char *buffer, const
|
|
std::streamsize bytes,
|
|
const std::istream::pos_type position) const;
|
|
|
|
mutable std::unique_ptr<std::istream> m_bundle;
|
|
ModuleTable m_table;
|
|
size_t m_baseOffset;
|
|
std::unique_ptr<JSBigBufferString> m_startupCode;
|
|
};
|
|
|
|
} // namespace react
|
|
} // namespace facebook
|