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

Android release build with proguard enabled throws exception at start #6624

Closed
dgladkov opened this issue Mar 24, 2016 · 14 comments
Closed

Android release build with proguard enabled throws exception at start #6624

dgladkov opened this issue Mar 24, 2016 · 14 comments
Labels
Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot.

Comments

@dgladkov
Copy link
Contributor

I get following exception on my release APK with proguard enabled after upgrading RN to 0.22.+. Disabling proguard solves the issue.

java.lang.NoSuchMethodError: no non-static method "Lcom/facebook/react/bridge/queue/NativeRunnable;.<init>(Lcom/facebook/jni/HybridData;)V"
   at com.facebook.react.bridge.ReactBridge.callFunction(Native Method)
   at com.facebook.react.bridge.CatalystInstanceImpl.callFunction(CatalystInstanceImpl.java:189)
   at com.facebook.react.bridge.JavaScriptModuleRegistry$JavaScriptModuleInvocationHandler.invoke(JavaScriptModuleRegistry.java:97)
   at java.lang.reflect.Proxy.invoke(Proxy.java:397)
   at $Proxy5.emit(Unknown Source)
   at com.facebook.react.modules.appstate.AppStateModule.sendAppStateChangeEvent(AppStateModule.java:73)
   at com.facebook.react.modules.appstate.AppStateModule.onHostResume(AppStateModule.java:51)
   at com.facebook.react.bridge.ReactContext.onHostResume(ReactContext.java:147)
   at com.facebook.react.ReactInstanceManagerImpl.moveToResumedLifecycleState(ReactInstanceManagerImpl.java:559)
   at com.facebook.react.ReactInstanceManagerImpl.moveReactContextToCurrentLifecycleState(ReactInstanceManagerImpl.java:904)
   at com.facebook.react.ReactInstanceManagerImpl.setupReactContext(ReactInstanceManagerImpl.java:728)
   at com.facebook.react.ReactInstanceManagerImpl.access$800(ReactInstanceManagerImpl.java:104)
   at com.facebook.react.ReactInstanceManagerImpl$ReactContextInitAsyncTask.onPostExecute(ReactInstanceManagerImpl.java:210)
   at com.facebook.react.ReactInstanceManagerImpl$ReactContextInitAsyncTask.onPostExecute(ReactInstanceManagerImpl.java:183)
   at android.os.AsyncTask.finish(AsyncTask.java:636)
   at android.os.AsyncTask.access$500(AsyncTask.java:177)
   at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:653)
   at android.os.Handler.dispatchMessage(Handler.java:102)
   at android.os.Looper.loop(Looper.java:135)
   at android.app.ActivityThread.main(ActivityThread.java:5254)
   at java.lang.reflect.Method.invoke(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:372)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
@charpeni
Copy link
Contributor

@facebook-github-bot label android

@facebook-github-bot facebook-github-bot added Android Ran Commands One of our bots successfully processed a command. labels Mar 24, 2016
@satya164
Copy link
Contributor

Yeah, currently enabling proguard breaks the build. Would be great if someone could look into fixing this. cc @mkonicek

@dgladkov
Copy link
Contributor Author

I tried manually adding both com.facebook.react.bridge.queue.NativeRunnable and com.facebook.jni.HybridData as proguard exceptions even though they are both annotated with @DoNotStrip but had no luck. Will investigate it more today

@satya164
Copy link
Contributor

Thanks for looking into it. Much appreciated.
On 24 Mar 2016 7:15 p.m., "Dmitry Gladkov" notifications@github.com wrote:

I tried manually adding both
com.facebook.react.bridge.queue.NativeRunnable and
com.facebook.jni.HybridData as proguard exceptions even though they are
both annotated with @DoNotStrip but had no luck. Will investigate it more
today


You are receiving this because you commented.
Reply to this email directly or view it on GitHub
#6624 (comment)

@dgladkov
Copy link
Contributor Author

Found the problem. NativeRunnable has a private constuctor that must be annotated with @DoNotStrip. Will add a pull request now, temporary solution is to add following line to your app proguard rules

-keep class com.facebook.react.bridge.queue.NativeRunnable { *; }

@tyao1
Copy link
Contributor

tyao1 commented Mar 31, 2016

Finally found this issue. Saved my day.

@cpunion
Copy link
Contributor

cpunion commented Apr 15, 2016

The problem is still exists. I created a project with react-native init TestRN23, so it installed react-native@0.23.1. Then add @DoNotStrip to NativeRunnable.java:

$ find . -iname NativeRunnable.java
./node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/queue/NativeRunnable.java
$ cat `find . -iname NativeRunnable.java` | grep -B 3 -A 3 "private NativeRunnable"
  private final HybridData mHybridData;

  @DoNotStrip
  private NativeRunnable(HybridData hybridData) {
    mHybridData = hybridData;
  }

Then I added proguard, build and run release version, app crashed:

E/AndroidRuntime(10770): Process: com.testrn23, PID: 10770
E/AndroidRuntime(10770): java.lang.NoSuchMethodError: no method with name='<init>' signature='(Lcom/facebook/jni/HybridData;)V' in class Lcom/facebook/react/bridge/queue/NativeRunnable;
E/AndroidRuntime(10770):    at com.facebook.react.bridge.ReactBridge.setGlobalVariable(Native Method)
E/AndroidRuntime(10770):    at com.facebook.react.bridge.CatalystInstanceImpl.initializeBridge(CatalystInstanceImpl.java:127)
E/AndroidRuntime(10770):    at com.facebook.react.bridge.CatalystInstanceImpl.access$200(CatalystInstanceImpl.java:39)
E/AndroidRuntime(10770):    at com.facebook.react.bridge.CatalystInstanceImpl$1.call(CatalystInstanceImpl.java:96)
E/AndroidRuntime(10770):    at com.facebook.react.bridge.CatalystInstanceImpl$1.call(CatalystInstanceImpl.java:91)
E/AndroidRuntime(10770):    at com.facebook.react.bridge.queue.MessageQueueThreadImpl$1.run(MessageQueueThreadImpl.java:73)
E/AndroidRuntime(10770):    at android.os.Handler.handleCallback(Handler.java:733)
E/AndroidRuntime(10770):    at android.os.Handler.dispatchMessage(Handler.java:95)
E/AndroidRuntime(10770):    at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:31)
E/AndroidRuntime(10770):    at android.os.Looper.loop(Looper.java:136)
E/AndroidRuntime(10770):    at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:187)
E/AndroidRuntime(10770):    at java.lang.Thread.run(Thread.java:841)

proguard-rules.pro was copied from master: https://gist.github.com/cpunion/f0712cae8ad552f9d49db86cc60ebeb4

@dgladkov
Copy link
Contributor Author

@cpunion RN Android does not build from source code by default because it's quite slow and requires Android NDK installed in order to build JavaScriptCore. You need to either update to 0.24 RC or follow this guide to set up your gradle script to compile RN Android from source:
https://facebook.github.io/react-native/docs/android-building-from-source.html

@dgladkov
Copy link
Contributor Author

dgladkov commented Apr 15, 2016

@cpunion of course much easier solution would be to add a line to your project proguard config that I mentioned here:
#6624 (comment)

@cpunion
Copy link
Contributor

cpunion commented Apr 15, 2016

@dgladkov Thanks so much, it works find.

zebulgar pushed a commit to nightingale/react-native that referenced this issue Jun 18, 2016
Summary:Fixes proguard in RN 0.22.+. Closes facebook#6624
Closes facebook#6626

Differential Revision: D3092892

fb-gh-sync-id: 3aaf97c6f1c7b5d575cb912196b43955d9ef10fb
shipit-source-id: 3aaf97c6f1c7b5d575cb912196b43955d9ef10fb
@iegik
Copy link

iegik commented May 25, 2017

Add also

-keep class com.facebook.react.cxxbridge.ModuleRegistryHolder { *; }

@mkonicek
Copy link
Contributor

Uh the Proguard config files are quite fragile. We have to keep adding stuff to them. Having a test on Circle CI that runs Proguard would help. Could anyone add that test?

Could you please send a pull request adding the lines to the default RN Proguard config, such as:

-keep class com.facebook.react.cxxbridge.ModuleRegistryHolder { *; }

@iegik
Copy link

iegik commented May 25, 2017

I`l do that

iegik added a commit to iegik/react-native that referenced this issue Aug 23, 2017
facebook-github-bot pushed a commit that referenced this issue Apr 6, 2018
Summary:
The original proguard rules are put in the template, which is not very convenient and easy to get wrong. Because new rules get put, people also has two copy paste the rule. And there are also existing project import react native as a dependency. So the best way to  keep a android library project proguard rule is to manage the rule itself, using `consumerProguardFiles` like [dagger](https://github.com/JakeWharton/butterknife/blob/46baef6d96e93a1872efa17fdfc1d2af59b36f0c/butterknife/build.gradle#L9) and other android library project.

<!--
  Required: Write your motivation here.
  If this PR fixes an issue, type "Fixes #issueNumber" to automatically close the issue when the PR is merged.
-->

Use RNTester to build the release flavor (now it has bugs #18460, I keep my change in local for now), after build success, run to check if crash.

In the process, I also fix #12994 and #6624 by adding the following to proguard rules
```proguard
-keep,includedescriptorclasses class com.facebook.react.bridge.** { *; }
```

<!--
  Does this PR require a documentation change?
  Create a PR at https://github.com/facebook/react-native-website and add a link to it here.
-->

[ANDROID] [ENHANCEMENT and BUGFIX] [Proguard rules] - inline and fix proguard rules .

<!--
  **INTERNAL and MINOR tagged notes will not be included in the next version's final release notes.**

    CATEGORY
  [----------]      TYPE
  [ CLI      ] [-------------]    LOCATION
  [ DOCS     ] [ BREAKING    ] [-------------]
  [ GENERAL  ] [ BUGFIX      ] [ {Component} ]
  [ INTERNAL ] [ ENHANCEMENT ] [ {Filename}  ]
  [ IOS      ] [ FEATURE     ] [ {Directory} ]   |-----------|
  [ ANDROID  ] [ MINOR       ] [ {Framework} ] - | {Message} |
  [----------] [-------------] [-------------]   |-----------|

 EXAMPLES:

 [IOS] [BREAKING] [FlatList] - Change a thing that breaks other things
 [ANDROID] [BUGFIX] [TextInput] - Did a thing to TextInput
 [CLI] [FEATURE] [local-cli/info/info.js] - CLI easier to do things with
 [DOCS] [BUGFIX] [GettingStarted.md] - Accidentally a thing/word
 [GENERAL] [ENHANCEMENT] [Yoga] - Added new yoga thing/position
 [INTERNAL] [FEATURE] [./scripts] - Added thing to script that nobody will see
-->
Closes #18461

Differential Revision: D7527533

Pulled By: hramos

fbshipit-source-id: 447dbc16983bcfb597187b40c1be3987a8c5a832
campsafari pushed a commit to exozet/react-native that referenced this issue Apr 11, 2018
Summary:
The original proguard rules are put in the template, which is not very convenient and easy to get wrong. Because new rules get put, people also has two copy paste the rule. And there are also existing project import react native as a dependency. So the best way to  keep a android library project proguard rule is to manage the rule itself, using `consumerProguardFiles` like [dagger](https://github.com/JakeWharton/butterknife/blob/46baef6d96e93a1872efa17fdfc1d2af59b36f0c/butterknife/build.gradle#L9) and other android library project.

<!--
  Required: Write your motivation here.
  If this PR fixes an issue, type "Fixes #issueNumber" to automatically close the issue when the PR is merged.
-->

Use RNTester to build the release flavor (now it has bugs facebook#18460, I keep my change in local for now), after build success, run to check if crash.

In the process, I also fix facebook#12994 and facebook#6624 by adding the following to proguard rules
```proguard
-keep,includedescriptorclasses class com.facebook.react.bridge.** { *; }
```

<!--
  Does this PR require a documentation change?
  Create a PR at https://github.com/facebook/react-native-website and add a link to it here.
-->

[ANDROID] [ENHANCEMENT and BUGFIX] [Proguard rules] - inline and fix proguard rules .

<!--
  **INTERNAL and MINOR tagged notes will not be included in the next version's final release notes.**

    CATEGORY
  [----------]      TYPE
  [ CLI      ] [-------------]    LOCATION
  [ DOCS     ] [ BREAKING    ] [-------------]
  [ GENERAL  ] [ BUGFIX      ] [ {Component} ]
  [ INTERNAL ] [ ENHANCEMENT ] [ {Filename}  ]
  [ IOS      ] [ FEATURE     ] [ {Directory} ]   |-----------|
  [ ANDROID  ] [ MINOR       ] [ {Framework} ] - | {Message} |
  [----------] [-------------] [-------------]   |-----------|

 EXAMPLES:

 [IOS] [BREAKING] [FlatList] - Change a thing that breaks other things
 [ANDROID] [BUGFIX] [TextInput] - Did a thing to TextInput
 [CLI] [FEATURE] [local-cli/info/info.js] - CLI easier to do things with
 [DOCS] [BUGFIX] [GettingStarted.md] - Accidentally a thing/word
 [GENERAL] [ENHANCEMENT] [Yoga] - Added new yoga thing/position
 [INTERNAL] [FEATURE] [./scripts] - Added thing to script that nobody will see
-->
Closes facebook#18461

Differential Revision: D7527533

Pulled By: hramos

fbshipit-source-id: 447dbc16983bcfb597187b40c1be3987a8c5a832
LukeDurrant pushed a commit to LukeDurrant/react-native that referenced this issue Apr 11, 2018
Summary:
The original proguard rules are put in the template, which is not very convenient and easy to get wrong. Because new rules get put, people also has two copy paste the rule. And there are also existing project import react native as a dependency. So the best way to  keep a android library project proguard rule is to manage the rule itself, using `consumerProguardFiles` like [dagger](https://github.com/JakeWharton/butterknife/blob/46baef6d96e93a1872efa17fdfc1d2af59b36f0c/butterknife/build.gradle#L9) and other android library project.

<!--
  Required: Write your motivation here.
  If this PR fixes an issue, type "Fixes #issueNumber" to automatically close the issue when the PR is merged.
-->

Use RNTester to build the release flavor (now it has bugs facebook#18460, I keep my change in local for now), after build success, run to check if crash.

In the process, I also fix facebook#12994 and facebook#6624 by adding the following to proguard rules
```proguard
-keep,includedescriptorclasses class com.facebook.react.bridge.** { *; }
```

<!--
  Does this PR require a documentation change?
  Create a PR at https://github.com/facebook/react-native-website and add a link to it here.
-->

[ANDROID] [ENHANCEMENT and BUGFIX] [Proguard rules] - inline and fix proguard rules .

<!--
  **INTERNAL and MINOR tagged notes will not be included in the next version's final release notes.**

    CATEGORY
  [----------]      TYPE
  [ CLI      ] [-------------]    LOCATION
  [ DOCS     ] [ BREAKING    ] [-------------]
  [ GENERAL  ] [ BUGFIX      ] [ {Component} ]
  [ INTERNAL ] [ ENHANCEMENT ] [ {Filename}  ]
  [ IOS      ] [ FEATURE     ] [ {Directory} ]   |-----------|
  [ ANDROID  ] [ MINOR       ] [ {Framework} ] - | {Message} |
  [----------] [-------------] [-------------]   |-----------|

 EXAMPLES:

 [IOS] [BREAKING] [FlatList] - Change a thing that breaks other things
 [ANDROID] [BUGFIX] [TextInput] - Did a thing to TextInput
 [CLI] [FEATURE] [local-cli/info/info.js] - CLI easier to do things with
 [DOCS] [BUGFIX] [GettingStarted.md] - Accidentally a thing/word
 [GENERAL] [ENHANCEMENT] [Yoga] - Added new yoga thing/position
 [INTERNAL] [FEATURE] [./scripts] - Added thing to script that nobody will see
-->
Closes facebook#18461

Differential Revision: D7527533

Pulled By: hramos

fbshipit-source-id: 447dbc16983bcfb597187b40c1be3987a8c5a832
LukeDurrant pushed a commit to LukeDurrant/react-native that referenced this issue Apr 11, 2018
Summary:
The original proguard rules are put in the template, which is not very convenient and easy to get wrong. Because new rules get put, people also has two copy paste the rule. And there are also existing project import react native as a dependency. So the best way to  keep a android library project proguard rule is to manage the rule itself, using `consumerProguardFiles` like [dagger](https://github.com/JakeWharton/butterknife/blob/46baef6d96e93a1872efa17fdfc1d2af59b36f0c/butterknife/build.gradle#L9) and other android library project.

<!--
  Required: Write your motivation here.
  If this PR fixes an issue, type "Fixes #issueNumber" to automatically close the issue when the PR is merged.
-->

Use RNTester to build the release flavor (now it has bugs facebook#18460, I keep my change in local for now), after build success, run to check if crash.

In the process, I also fix facebook#12994 and facebook#6624 by adding the following to proguard rules
```proguard
-keep,includedescriptorclasses class com.facebook.react.bridge.** { *; }
```

<!--
  Does this PR require a documentation change?
  Create a PR at https://github.com/facebook/react-native-website and add a link to it here.
-->

[ANDROID] [ENHANCEMENT and BUGFIX] [Proguard rules] - inline and fix proguard rules .

<!--
  **INTERNAL and MINOR tagged notes will not be included in the next version's final release notes.**

    CATEGORY
  [----------]      TYPE
  [ CLI      ] [-------------]    LOCATION
  [ DOCS     ] [ BREAKING    ] [-------------]
  [ GENERAL  ] [ BUGFIX      ] [ {Component} ]
  [ INTERNAL ] [ ENHANCEMENT ] [ {Filename}  ]
  [ IOS      ] [ FEATURE     ] [ {Directory} ]   |-----------|
  [ ANDROID  ] [ MINOR       ] [ {Framework} ] - | {Message} |
  [----------] [-------------] [-------------]   |-----------|

 EXAMPLES:

 [IOS] [BREAKING] [FlatList] - Change a thing that breaks other things
 [ANDROID] [BUGFIX] [TextInput] - Did a thing to TextInput
 [CLI] [FEATURE] [local-cli/info/info.js] - CLI easier to do things with
 [DOCS] [BUGFIX] [GettingStarted.md] - Accidentally a thing/word
 [GENERAL] [ENHANCEMENT] [Yoga] - Added new yoga thing/position
 [INTERNAL] [FEATURE] [./scripts] - Added thing to script that nobody will see
-->
Closes facebook#18461

Differential Revision: D7527533

Pulled By: hramos

fbshipit-source-id: 447dbc16983bcfb597187b40c1be3987a8c5a832
bunnyc1986 pushed a commit to bunnyc1986/react-native that referenced this issue May 11, 2018
Summary:
The original proguard rules are put in the template, which is not very convenient and easy to get wrong. Because new rules get put, people also has two copy paste the rule. And there are also existing project import react native as a dependency. So the best way to  keep a android library project proguard rule is to manage the rule itself, using `consumerProguardFiles` like [dagger](https://github.com/JakeWharton/butterknife/blob/46baef6d96e93a1872efa17fdfc1d2af59b36f0c/butterknife/build.gradle#L9) and other android library project.

<!--
  Required: Write your motivation here.
  If this PR fixes an issue, type "Fixes #issueNumber" to automatically close the issue when the PR is merged.
-->

Use RNTester to build the release flavor (now it has bugs facebook#18460, I keep my change in local for now), after build success, run to check if crash.

In the process, I also fix facebook#12994 and facebook#6624 by adding the following to proguard rules
```proguard
-keep,includedescriptorclasses class com.facebook.react.bridge.** { *; }
```

<!--
  Does this PR require a documentation change?
  Create a PR at https://github.com/facebook/react-native-website and add a link to it here.
-->

[ANDROID] [ENHANCEMENT and BUGFIX] [Proguard rules] - inline and fix proguard rules .

<!--
  **INTERNAL and MINOR tagged notes will not be included in the next version's final release notes.**

    CATEGORY
  [----------]      TYPE
  [ CLI      ] [-------------]    LOCATION
  [ DOCS     ] [ BREAKING    ] [-------------]
  [ GENERAL  ] [ BUGFIX      ] [ {Component} ]
  [ INTERNAL ] [ ENHANCEMENT ] [ {Filename}  ]
  [ IOS      ] [ FEATURE     ] [ {Directory} ]   |-----------|
  [ ANDROID  ] [ MINOR       ] [ {Framework} ] - | {Message} |
  [----------] [-------------] [-------------]   |-----------|

 EXAMPLES:

 [IOS] [BREAKING] [FlatList] - Change a thing that breaks other things
 [ANDROID] [BUGFIX] [TextInput] - Did a thing to TextInput
 [CLI] [FEATURE] [local-cli/info/info.js] - CLI easier to do things with
 [DOCS] [BUGFIX] [GettingStarted.md] - Accidentally a thing/word
 [GENERAL] [ENHANCEMENT] [Yoga] - Added new yoga thing/position
 [INTERNAL] [FEATURE] [./scripts] - Added thing to script that nobody will see
-->
Closes facebook#18461

Differential Revision: D7527533

Pulled By: hramos

fbshipit-source-id: 447dbc16983bcfb597187b40c1be3987a8c5a832
@facebook facebook locked as resolved and limited conversation to collaborators May 24, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 20, 2018
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

9 participants