diff --git a/ReactAndroid/src/main/jni/react/jni/OnLoad.cpp b/ReactAndroid/src/main/jni/react/jni/OnLoad.cpp index b9c4240d3..478eda666 100644 --- a/ReactAndroid/src/main/jni/react/jni/OnLoad.cpp +++ b/ReactAndroid/src/main/jni/react/jni/OnLoad.cpp @@ -853,7 +853,7 @@ static void handleMemoryPressureCritical(JNIEnv* env, jobject obj) { namespace executors { -std::string getDeviceCacheDir() { +static std::string getApplicationDir(const char* methodName) { // Get the Application Context object auto getApplicationClass = findClassLocal( "com/facebook/react/common/ApplicationHolder"); @@ -864,23 +864,32 @@ std::string getDeviceCacheDir() { auto application = getApplicationMethod(getApplicationClass); // Get getCacheDir() from the context - auto getCacheDirMethod = findClassLocal("android/app/Application") - ->getMethod("getCacheDir", - "()Ljava/io/File;" + auto getDirMethod = findClassLocal("android/app/Application") + ->getMethod(methodName, + "()Ljava/io/File;" ); - auto cacheDirObj = getCacheDirMethod(application); + auto dirObj = getDirMethod(application); // Call getAbsolutePath() on the returned File object auto getAbsolutePathMethod = findClassLocal("java/io/File") ->getMethod("getAbsolutePath"); - return getAbsolutePathMethod(cacheDirObj)->toStdString(); + return getAbsolutePathMethod(dirObj)->toStdString(); +} + +static std::string getApplicationCacheDir() { + return getApplicationDir("getCacheDir"); +} + +static std::string getApplicationPersistentDir() { + return getApplicationDir("getFilesDir"); } struct CountableJSCExecutorFactory : CountableJSExecutorFactory { public: CountableJSCExecutorFactory(folly::dynamic jscConfig) : m_jscConfig(jscConfig) {} virtual std::unique_ptr createJSExecutor(Bridge *bridge) override { - return JSCExecutorFactory(getDeviceCacheDir(), m_jscConfig).createJSExecutor(bridge); + m_jscConfig["PersistentDirectory"] = getApplicationPersistentDir(); + return JSCExecutorFactory(getApplicationCacheDir(), m_jscConfig).createJSExecutor(bridge); } private: