React-native-code-push: Android: com.microsoft.codepush.react.CodePushUnknownException: Error in getting binary resources modified time

Created on 17 Oct 2020  Â·  13Comments  Â·  Source: microsoft/react-native-code-push

Steps to Reproduce

  1. Add codepush 6.3.0 to a RN 0.63.3 project
  2. Attempt a codepush
  3. Observe following crash in emulator

Expected Behavior

Codepush was working until recently. Seems it was likely the update to RN 0.63.3 or Android Gradle plugin 4.1+.

Actual Behavior

What actually happens?

2020-10-16 18:10:51.465 21369-21437/com.whetware.taskhero E/ReactNative: [CodePush] Exception
    com.microsoft.codepush.react.CodePushUnknownException: Error in getting binary resources modified time
        at com.microsoft.codepush.react.CodePush.getBinaryResourcesModifiedTime(CodePush.java:207)
        at com.microsoft.codepush.react.CodePushNativeModule$3.doInBackground(CodePushNativeModule.java:289)
        at com.microsoft.codepush.react.CodePushNativeModule$3.doInBackground(CodePushNativeModule.java:284)
        at android.os.AsyncTask$3.call(AsyncTask.java:394)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:923)
     Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x0
        at android.content.res.Resources.getText(Resources.java:444)
        at android.content.res.Resources.getString(Resources.java:537)
        at com.microsoft.codepush.react.CodePush.getBinaryResourcesModifiedTime(CodePush.java:204)
        at com.microsoft.codepush.react.CodePushNativeModule$3.doInBackground(CodePushNativeModule.java:289) 
        at com.microsoft.codepush.react.CodePushNativeModule$3.doInBackground(CodePushNativeModule.java:284) 
        at android.os.AsyncTask$3.call(AsyncTask.java:394) 
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
        at java.lang.Thread.run(Thread.java:923) 

Reproducible Demo

Will update with repro when available

Environment

  • react-native-code-push version: 6.3.0
  • react-native version: 0.63.3
  • iOS/Android/Windows version: Android emulator API 30
  • Does this reproduce on a debug build or release build? release
  • Does this reproduce on a simulator, or only on a physical device? Simulator, have not tested physical device yet
investigating waiting-for-clarification

Most helpful comment

I added the following to my android/app/build.gradle and it work as a workaround. I'm guessing this is likely an android gradle plugin issue. There seem to be a bunch of undocumented breaking changes in AGP 4.1+ that affect React Native.

under android { defaultConfig { I added

resValue 'string', "CODE_PUSH_APK_BUILD_TIME", String.format("\"%d\"", System.currentTimeMillis())

All 13 comments

I added the following to my android/app/build.gradle and it work as a workaround. I'm guessing this is likely an android gradle plugin issue. There seem to be a bunch of undocumented breaking changes in AGP 4.1+ that affect React Native.

under android { defaultConfig { I added

resValue 'string', "CODE_PUSH_APK_BUILD_TIME", String.format("\"%d\"", System.currentTimeMillis())

Hi @AndrewMorsillo ,
Thanks for reporting!

Could you please provide a demo project?

Sorry but I likely won't have time to make a reproduction anytime soon.

I think this is probably reproducible by upgrading any react native project with codepush to android gradle plugin 4.1+.

Hi @AndrewMorsillo could you please double-check that the following step is performed in your app:

  1. In your android/app/build.gradle file, add the codepush.gradle file as an additional build task definition underneath react.gradle:
...
apply from: "../../node_modules/react-native/react.gradle"
apply from: "../../node_modules/react-native-code-push/android/codepush.gradle"
...

?
Also please take a look at this issue: #1046

@ruslan-bikkinin Yes, I have the gradle plugin applied correctly. I had been using code push without issue for many months in my app. This suddenly broke when I updated to Android gradle plugin 4.1+. I did not change anything related to my code push configuration. I suspect you can reproduce this issue by upgrading any react native app to android gradle plugin 4.1+.

I found the workaround in this old issue: https://github.com/microsoft/react-native-code-push/issues/771

@AndrewMorsillo got it. Thanks for the info, we'll check it out.

Hi @AndrewMorsillo unfortunately, I couldn’t reproduce your issue on my side.
What I did:

buildscript {
    ext {
    // ...
    dependencies {
        classpath(‘com.android.tools.build:gradle:4.1.0’)
    }
}
  • Updated distributionUrl in gradle/wrapper/gradle-wrapper.properties to use Gradle 6.5 (as it is minimum supported version for gradle plugin 4.1.0 as said in Android Plugin documentation page):
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
  • Tried to build and run application via react-native run-android
  • App was built and run without any errors
    Here's the sample demo project that I used: rn63.zip

Did you do any extra steps aside mine to migrate to Android Gradle plugin 4.1.0?

Also, you can try to reinstall and reconfigure react-native-code-push plugin.

I have the same issue after updating to com.android.tools.build:gradle:4.1.0 and gradle-6.5-all.zip.

Reverted to com.android.tools.build:gradle:3.6.3 and gradle-6.3-all.zip and will get back here after I'm sure this was the issue.

It work for me by reverting the gradle version.gradle-6.2-all.zip & com.android.tools.build:gradle:3.5.3

I confirm that the downgrade solved the issue.

@ruslan-bikkinin - in order for this to reproduce, I believe, you need to follow these steps:

  • Set the app version to 1.0. Create an apk and install it
  • Create a codepush for this version (1.0), then run the app to install (and run) the codepush
  • Update the version to 1.1 and create a new apk, then update the app on the device with this new apk

What happened in our case is that we had version 1.1.6 live on the store (with the old gradle version plugin), which also had a codepush.

Then we released a new version (1.1.7), which included an update of the gradle plugin.

After the update, the app crashed immediately on pressing the app icon. We submitted a new 1.1.7 build, with the old gradle version, and this fixed the issue.

Hi @andiradulescu ,

It depends on target binary version of your update. If you have as 1.1 then it will be installed for all binary versions like 1.1.X. Could you please share your target binary version for your update?

Hi, we are planning to release a new version of our app and upgraded all the dependencies.
Gradle: 4.1.0
Codepush: 6.4.0
RN: 0.63.4

We decided to test the codepush before the release and getting the same error:
ReactNative: [CodePush] Unable to get the hash of the binary's bundled resources - "codepush.gradle" may have not been added to the build definition.
ReactNative: com.microsoft.codepush.react.CodePushUnknownException: Error in getting binary resources modified time
ReactNative: at com.microsoft.codepush.react.CodePush.getBinaryResourcesModifiedTime(CodePush.java:207)
ReactNative: at com.microsoft.codepush.react.CodePushNativeModule$3.doInBackground(CodePushNativeModule.java:289)
ReactNative: at com.microsoft.codepush.react.CodePushNativeModule$3.doInBackground(CodePushNativeModule.java:284)
ReactNative: at com.microsoft.codepush.react.CodePush.getBinaryResourcesModifiedTime(CodePush.java:204)

Our version of the app: 2.0.0 and the target version is 2.0.0.

I can confirm that this works:

I added the following to my android/app/build.gradle and it work as a workaround. I'm guessing this is likely an android gradle plugin issue. There seem to be a bunch of undocumented breaking changes in AGP 4.1+ that affect React Native.

under android { defaultConfig { I added

resValue 'string', "CODE_PUSH_APK_BUILD_TIME", String.format("\"%d\"", System.currentTimeMillis())

e.g.

    defaultConfig {
       .....
        resValue 'string', "CODE_PUSH_APK_BUILD_TIME", String.format("\"%d\"", System.currentTimeMillis())
    }
Was this page helpful?
0 / 5 - 0 ratings