react-native-community / upgrade-support

A central community-backed place to request and give help when upgrading your app.
MIT License
254 stars 2 forks source link

ClassNotFoundException: Didn't find class "com.facebook.jni.NativeRunnable" #31

Open d4vidi opened 4 years ago

d4vidi commented 4 years ago

Environment

System:
    OS: macOS Mojave 10.14.6
    CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 19.86 MB / 16.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 10.15.3 - ~/.nvm/versions/node/v10.15.3/bin/node
    Yarn: 1.3.2 - /usr/local/bin/yarn
    npm: 6.14.2 - ~/.nvm/versions/node/v10.15.3/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.8.4 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: iOS 13.2, DriverKit 19.0, macOS 10.15, tvOS 13.2, watchOS 6.1
    Android SDK:
      API Levels: 19, 21, 22, 23, 24, 25, 26, 27, 28, 29
      Build Tools: 19.1.0, 20.0.0, 21.1.2, 22.0.1, 23.0.1, 23.0.2, 23.0.3, 24.0.1, 25.0.0, 25.0.1, 25.0.2, 25.0.3, 26.0.0, 26.0.1, 26.0.2, 26.0.3, 27.0.1, 27.0.3, 28.0.0, 28.0.2, 28.0.3, 29.0.0
      System Images: android-25 | Google APIs Intel x86 Atom_64, android-26 | Google APIs Intel x86 Atom, android-26 | Google Play Intel x86 Atom, android-28 | Intel x86 Atom_64, android-28 | Google Play Intel x86 Atom, android-29 | Google APIs Intel x86 Atom
      Android NDK: 19.2.5345600
  IDEs:
    Android Studio: 3.5 AI-191.8026.42.35.6010548
    Xcode: 11.3/11C29 - /usr/bin/xcodebuild
  Languages:
    Python: 2.7.15 - /usr/local/bin/python
  npmPackages:
    @react-native-community/cli: Not Found
    react: 16.11.0 => 16.11.0
    react-native: 0.62.x => 0.62.0
  npmGlobalPackages:
    *react-native*: Not Found

Upgrading version

0.61.x -> 0.62.0

Problem

Exception after most Android-native related upgrade changes are in-effect:

04-02 16:45:09.984   5599     5629                    log  E  error java.lang.ClassNotFoundException: Didn't find class "com.facebook.jni.NativeRunnable" on path: DexPathList[[zip file "/syste
                                                            m/framework/android.test.runner.jar", zip file "/system/framework/android.test.mock.jar", zip file "/data/app/<package-id> 
                                                            -4_Awll2XOObiNOIzAi-1mg==/base.apk", zip file "/data/app/<package>-MKSEeZ2AT76gKeeTnKiTPQ==/base.apk"],nativeLibraryDi
                                                            rectories=[/data/app/<package-id>-4_Awll2XOObiNOIzAi-1mg==/lib/x86_64, /data/app/<package>-MKSEeZ2AT76gKeeTnKi
                                                            TPQ==/lib/x86_64, /data/app/<package-id>-4_Awll2XOObiNOIzAi-1mg==/base.apk!/lib/x86_64, /data/app/<package>-MK
                                                            SEeZ2AT76gKeeTnKiTPQ==/base.apk!/lib/x86_64, /system/lib64]]

(Ignored lots of consequent errors here)

Solution

This happens only when minification is enabled -- com.facebook.jni.NativeRunnable gets stripped out, and even though NativeRunnable has the @DoNotStrip annotation.

The problem is that RN's self proguard settings are incomplete. This section allegedly should do the trick here:

# Do not strip any method/class that is annotated with @DoNotStrip
-keep @com.facebook.proguard.annotations.DoNotStrip class *
-keep @com.facebook.common.internal.DoNotStrip class *
-keepclassmembers class * {
    @com.facebook.proguard.annotations.DoNotStrip *;
    @com.facebook.common.internal.DoNotStrip *;
}

But it doesn't. Adding this to your app's proguard rules should solve both that and potentially similar problems:

-keep @com.facebook.jni.annotations.DoNotStrip class *
-keep class * {
    @com.facebook.proguard.annotations.DoNotStrip *;
    @com.facebook.common.internal.DoNotStrip *;
    @com.facebook.jni.annotations.DoNotStrip *;
}
-keepclassmembers class * {
    @com.facebook.jni.annotations.DoNotStrip *;
}

Explanation: there are several DoNotStrip annotations going around in RN's and its deps. In particular, this adds the missing com.facebook.jni.annotations.DoNotStrip annotation for keeping class members, and, more importantly, applies all known DoNotStrip over classes (that includes the NativeRunnable class).

I'll consider PR-ing this.

fbartho commented 4 years ago

We're exhibiting this issue too, -- we just leapfrogged from RN 0.59 and RN 0.62 and without this Github Issue, we were blocked in Production Release Verification & QA which is bad when you have deadlines! Thanks a lot @d4vidi!

abhishekdewan101 commented 4 years ago

@d4vidi You sir are awesome :D Thank you for this 👍