react-native-rename icon indicating copy to clipboard operation
react-native-rename copied to clipboard

Incompatible with New Architecture

Open saoudnazir opened this issue 3 years ago • 3 comments

I have been trying to rename my app and run with new architecture. As soon as I rename it, android app starts to crash on start up

here is the Android logs

----- Start of Error ------ 2022-09-08 12:38:16.775 27106-27106/? E/USNET: USNET: appName: com.xxxxxxx 2022-09-08 12:38:16.925 27106-27106/com.xxxxxxx E/SoLoader: couldn't find DSO to load: libjscexecutor.so SoSource 0: com.facebook.soloader.ApkSoSource[root = /data/data/com.xxxxxxx/lib-main flags = 1] SoSource 1: com.facebook.soloader.DirectorySoSource[root = /data/app/~~aT1wYoVL7bfjHYiR_8DWpA==/com.xxxxxxx-SslWlZJVlcNX5d9nPi639Q==/lib/arm64 flags = 0] SoSource 2: com.facebook.soloader.DirectorySoSource[root = /system/lib64 flags = 2] SoSource 3: com.facebook.soloader.DirectorySoSource[root = /vendor/lib64 flags = 2] Native lib dir: /data/app/~~aT1wYoVL7bfjHYiR_8DWpA==/com.xxxxxxx-SslWlZJVlcNX5d9nPi639Q==/lib/arm64 result: 0 2022-09-08 12:38:17.134 27106-27106/com.xxxxxxx E/unknown:ReactRootView: Unable to update root layout specs for ReactRootView: no rootViewTag set yet 2022-09-08 12:38:19.439 27106-27189/com.xxxxxxx E/log: error java.lang.ClassNotFoundException: Didn't find class "com.qsaudit2.newarchitecture.modules.MainApplicationTurboModuleManagerDelegate" on path: DexPathList[[zip file "/data/app/~~aT1wYoVL7bfjHYiR_8DWpA==/com.xxxxxxx-SslWlZJVlcNX5d9nPi639Q==/base.apk"],nativeLibraryDirectories=[/data/app/~~aT1wYoVL7bfjHYiR_8DWpA==/com.xxxxxxx-SslWlZJVlcNX5d9nPi639Q==/lib/arm64, /data/app/~~aT1wYoVL7bfjHYiR_8DWpA==/com.xxxxxxx-SslWlZJVlcNX5d9nPi639Q==/base.apk!/lib/arm64-v8a, /system/lib64, /system/system_ext/lib64]] 2022-09-08 12:38:19.440 27106-27189/com.xxxxxxx A/.qscomply.audi: java_vm_ext.cc:594] JNI DETECTED ERROR IN APPLICATION: JNI NewGlobalRef called with pending exception java.lang.ClassNotFoundException: Didn't find class "com.qsaudit2.newarchitecture.modules.MainApplicationTurboModuleManagerDelegate" on path: DexPathList[[zip file "/data/app/~~aT1wYoVL7bfjHYiR_8DWpA==/com.xxxxxxx-SslWlZJVlcNX5d9nPi639Q==/base.apk"],nativeLibraryDirectories=[/data/app/~~aT1wYoVL7bfjHYiR_8DWpA==/com.xxxxxxx-SslWlZJVlcNX5d9nPi639Q==/lib/arm64, /data/app/~~aT1wYoVL7bfjHYiR_8DWpA==/com.xxxxxxx-SslWlZJVlcNX5d9nPi639Q==/base.apk!/lib/arm64-v8a, /system/lib64, /system/system_ext/lib64]] java_vm_ext.cc:594] (Throwable with no stack trace) java_vm_ext.cc:594] java_vm_ext.cc:594] in call to NewGlobalRef java_vm_ext.cc:594] from java.lang.String java.lang.Runtime.nativeLoad(java.lang.String, java.lang.ClassLoader, java.lang.Class) 2022-09-08 12:38:19.570 27106-27189/com.xxxxxxx A/.qscomply.audi: runtime.cc:675] Runtime aborting... -------- more lines (could not add new to characters limit) ----
--------- beginning of crash 2022-09-08 12:38:19.571 27106-27189/com.xxxxxxx A/libc: Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 27189 (create_react_co), pid 27106 (xxxxxxx) xxxxxxx ------ End of Error -------

saoudnazir avatar Sep 08 '22 02:09 saoudnazir

Any update?

roysG avatar Sep 10 '22 18:09 roysG

I faced the same problem, I revert all changes using git, then rerun the command, and everything works fine.

lessmore92 avatar Sep 14 '22 00:09 lessmore92

+1

alessioemireni avatar Oct 04 '22 10:10 alessioemireni

Any update on this?

olawalejuwonm avatar Oct 18 '22 09:10 olawalejuwonm

I was able to fix this by replacing the newArchitecture folder and renaming the neccessary bundle identifier. @junedomingo can i open a pr that fix this?

olawalejuwonm avatar Oct 18 '22 09:10 olawalejuwonm

+1

leegeunhyeok avatar Nov 08 '22 10:11 leegeunhyeok

I solved this issue.

If you want to change android package structure, should update jni native codes.

  • Edit: I opened PR for this issue (#163)

To Reproduce

(1) Create new react native project via react-native-cli

npx react-native init Test

(2) Enable fabric

# edit gradle.properties
newArchEnabled=true

(2-1) Build and run before change the package structure

# It works!
yarn android

(3) Change package structure via react-native-rename

react-native-rename "test2" -b com.example.test2

(4) Build and run

cd android && ./gradlew clean
cd ../
yarn android

# android app crash on start up

My solution

Update two files.

  • android/app/src/main/jni/MainApplicationTurboModuleManagerDelegate.h
  • android/app/src/main/jni/MainComponentsRegistry.h

(edit kJavaDescriptor value to new package path)

// MainApplicationTurboModuleManagerDelegate.h
#include <memory>
#include <string>

#include <ReactCommon/TurboModuleManagerDelegate.h>
#include <fbjni/fbjni.h>

namespace facebook {
namespace react {

class MainApplicationTurboModuleManagerDelegate
    : public jni::HybridClass<
          MainApplicationTurboModuleManagerDelegate,
          TurboModuleManagerDelegate> {
 public:
  // Adapt it to the package you used for your Java class.
  static constexpr auto kJavaDescriptor =
      "Lcom/example/test2/newarchitecture/modules/MainApplicationTurboModuleManagerDelegate;"; // <<< here

  static jni::local_ref<jhybriddata> initHybrid(jni::alias_ref<jhybridobject>);

  static void registerNatives();

  std::shared_ptr<TurboModule> getTurboModule(
      const std::string &name,
      const std::shared_ptr<CallInvoker> &jsInvoker) override;
  std::shared_ptr<TurboModule> getTurboModule(
      const std::string &name,
      const JavaTurboModule::InitParams &params) override;

  /**
   * Test-only method. Allows user to verify whether a TurboModule can be
   * created by instances of this class.
   */
  bool canCreateTurboModule(const std::string &name);
};

} // namespace react
} // namespace facebook

(edit kJavaDescriptor value to new package path)

// MainComponentsRegistry.h
#pragma once

#include <ComponentFactory.h>
#include <fbjni/fbjni.h>
#include <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h>
#include <react/renderer/componentregistry/ComponentDescriptorRegistry.h>

namespace facebook {
namespace react {

class MainComponentsRegistry
    : public facebook::jni::HybridClass<MainComponentsRegistry> {
 public:
  // Adapt it to the package you used for your Java class.
  constexpr static auto kJavaDescriptor =
      "Lcom/example/test2/newarchitecture/components/MainComponentsRegistry;"; // << here

  static void registerNatives();

  MainComponentsRegistry(ComponentFactory *delegate);

 private:
  static std::shared_ptr<ComponentDescriptorProviderRegistry const>
  sharedProviderRegistry();

  static jni::local_ref<jhybriddata> initHybrid(
      jni::alias_ref<jclass>,
      ComponentFactory *delegate);
};

} // namespace react
} // namespace facebook

and then clean and rebuild app, it works fine for me.

leegeunhyeok avatar Nov 08 '22 13:11 leegeunhyeok

I still have this error, even after modifying MainApplicationTurboModuleManagerDelegate.h and MainComponentsRegistry.h I completely cleaned and rebuild the project. Any suggestion ?

corvut avatar Nov 28 '22 11:11 corvut

I got i working by cleaning the project multiple times 🤷‍♂️

corvut avatar Dec 01 '22 12:12 corvut

@BloodyMonkey How reproduce in your case?

I followed this flow and working successfully

  • rename application with react-native-rename
  • Update MainApplicationTurboModuleManagerDelegate.h and MainComponentsRegistry.h

Please check this demo and reply to me 😁

  • https://github.com/leegeunhyeok/react-native-rename-demo

leegeunhyeok avatar Dec 03 '22 04:12 leegeunhyeok

Hope the merged PR above can be published in a new version soon. This package has had no new release for more than one year.

Jonathan0wh avatar Dec 20 '22 10:12 Jonathan0wh

Closing, please check v3

junedomingo avatar Dec 26 '22 09:12 junedomingo