Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce proguard minification into test app #1216

Closed
d4vidi opened this issue Mar 19, 2019 · 1 comment
Closed

Introduce proguard minification into test app #1216

d4vidi opened this issue Mar 19, 2019 · 1 comment

Comments

@d4vidi
Copy link
Collaborator

d4vidi commented Mar 19, 2019

Is your feature request related to a problem? Please describe.
As observed in internal projects, it seems that when minification is enabled (over react native itself in particular), Detox can find itself in troubling situations due to usage of reflection.
Therefore, it'd be better (and future-proof) if we minify the test app and introduce proguard rules to protect Detox in that sense.

Describe the solution you'd like
Minify react-native in test app and introduce a proper proguard rules schema, integrated into the build.gradle.

Describe alternatives you've considered
N/A

Additional context
This is an error effectively observed in one of the internal projects:

E  java.lang.NoSuchMethodException: No similar method getUIViewOperationQueue with params [] could be found on type class com.facebook.react.uimanager.UIImplementation.
E      at org.joor.Reflect.similarMethod(Reflect.java:488)
E      at org.joor.Reflect.call(Reflect.java:418)
E      at org.joor.Reflect.call(Reflect.java:364)
E      at com.wix.detox.espresso.ReactNativeUIModuleIdlingResource.isIdleNow(ReactNativeUIModuleIdlingResource.java:83)
E      at android.support.test.espresso.base.IdlingResourceRegistry.allResourcesAreIdle(IdlingResourceRegistry.java:265)
E      at android.support.test.espresso.base.IdlingResourceRegistry$6.isIdleNow(IdlingResourceRegistry.java:299)
@d4vidi
Copy link
Collaborator Author

d4vidi commented Mar 21, 2019

After a bit of an investigation work, it seems that since Detox is a test-dependency in its hosting apps, proguard usage is a bit tangled. Here are some insights I believe are important and true:

  1. Since Detox is a test-dep (androidTestImplementation), whatever we put inside our proguard-rules.pro only affects the androidTest apk (typically under android/app/build/outputs/mapping/androidTest/...). Therefore, there's no point in trying to add rules such as -keep class com.facebook.react.**, since they are effectively scarce.
  2. Unlike what the documentation for consumerProguardFiles says, it does bring the associated rules files into affect even if the library isn't served as an aar (as in our case) -- so we ought to keep it starting now.
  3. Continuing point 1, still a need remains of affecting the actual (production) apk when running in instrumentation mode. This is what the testProguardFiles is for. In our case, since we need to have all of facebook available, this is the way to go (i.e. introducing a custom test proguard rules files and subscribing it using testProguardFiles).
  4. In actual apps, no need to copy and paste RN's proguard-rules.pro into the app's custom rules file. It's used automatically since RN declares it using consumerProguardFiles. Depending on whether running fromSource or fromBin, it uses the rules file either in the root or inside the aar itself (respectively).

On 2nd though, point 3 doesn't make sense as the apk gets compiled once, and once only. So the only choice here I guess is for users to create a test-specific build type (e.g. releaseTest) -- where all of react native is included; We need to really well document that :-/

Note: this could be the reason as to why this old SO question has never been solved :)

@lock lock bot locked as resolved and limited conversation to collaborators Apr 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants