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: com.microsoft.codepush.react.CodePushUnknownException: Error in getting binary resources modified time #1961

Closed
evelant opened this issue Oct 16, 2020 · 57 comments

Comments

@evelant
Copy link

evelant commented Oct 16, 2020

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
@evelant
Copy link
Author

evelant commented Oct 16, 2020

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())

@evelant
Copy link
Author

evelant commented Oct 19, 2020

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+.

@ruslan-bikkinin
Copy link
Contributor

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

@evelant
Copy link
Author

evelant commented Oct 28, 2020

@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: #771

@ruslan-bikkinin
Copy link
Contributor

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

@ruslan-bikkinin
Copy link
Contributor

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

  • created demo project that includes react-native-code-push version@6.3.0, react-native version@0.63.3
  • Updated build.gradle to enable 4.1.0 Android plugin
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.

@andiradulescu
Copy link

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.

@452MJ
Copy link

452MJ commented Nov 5, 2020

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

@andiradulescu
Copy link

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.

@alexandergoncharov-zz
Copy link
Contributor

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?

@defigor
Copy link

defigor commented Dec 17, 2020

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.

@alexfoxy
Copy link

alexfoxy commented Jan 8, 2021

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())
    }

@ivanzhang2
Copy link

@ruslan-bikkinin can you again in rn 0.64 with hermes enable, code-push 6.4.1( my version), still reproduce this issue, and
resValue 'string', "CODE_PUSH_APK_BUILD_TIME", String.format("\"%d\"", System.currentTimeMillis()) still did the fix

@amingsc
Copy link

amingsc commented Apr 16, 2021

In my case,"org.gradle.configureondemand=true" in file "gradle.property" will produce this error, remove this line will be ok.(last rn0.61 dont lead to this error, after upgrade to rn0.64 the error come out)

@savv
Copy link

savv commented May 1, 2021

I can confirm that we had a crashing build, following an upgrade to the android gradle plugin to 4.1; and applying the fix above (resValue 'string', "CODE_PUSH_APK_BUILD_TIME...) fixed the crash.

@ChristianDigitalPlankton

(resValue 'string', "CODE_PUSH_APK_BUILD_TIME...) fixed it for me

@nguyenthanhtruongntt85
Copy link

nguyenthanhtruongntt85 commented Jul 7, 2021

The same when i use react-native-config
when i add below for react-native-config in build.gradle then bug the same @AndrewMorsillo
project.ext.envConfigFiles = [
develop : ".env.develop",
staging : ".env.staging",
production : ".env.production",
]
apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle"

I can confirm that that works.

defaultConfig {
.....
resValue 'string', "CODE_PUSH_APK_BUILD_TIME", String.format(""%d"", System.currentTimeMillis())
}
flavorDimensions ""
productFlavors {
develop {
resValue "string", "CodePushDeploymentKey", "key deverlop"
}
staging {
resValue "string", "CodePushDeploymentKey", "key staging"
}
production {
resValue "string", "CodePushDeploymentKey", "key product"
}
}

but this is the best solution, right?
i use version
"react-native": "0.64.2",
"react-native-code-push": "7.0.1",
"react-native-config": "1.4.2"

@papa-jake
Copy link

I was experiencing this issue as well. I noticed that in the codepush.gradle file the value for CODE_PUSH_APK_BUILD_TIME is applied using buildTypes.each. However, in my app level build.gradle I have:

buildTypes {
        debug {
            signingConfig signingConfigs.debug
        }
        // release {
        //     // Caution! In production, you need to generate your own keystore file.
        //     // see https://facebook.github.io/react-native/docs/signed-apk-android.
        //     signingConfig signingConfigs.release
        //     minifyEnabled enableProguardInReleaseBuilds
        //     proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        // }
    }

notice that release is commented out. So, the apk build time value was only being applied to the debug buildType (via buildTypes.each). This would explain why adding it to defaultConfig seems to fix this issue.

Is anyone else here able to confirm that this error occurs when there is no release buildType configured?

@Jonathan3209
Copy link

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())

You're a light in darkness!
Thank you sir, that worked for me.

@appfr3d
Copy link

appfr3d commented Aug 14, 2021

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())

Thank you, this worked for me too 🙌 However, I already had one resValue 'string' ... in my android { defaultConfig {.
If you also have that, you should add the the new resValue ... line, and not append the strings to the existing resValue ... line.

@Kailash23
Copy link

@alexandergoncharov

08-30 19:46:59.723 32632  2136 I ReactNativeJS: Running "CwingsDeliveryApp" with {"rootTag":1}
08-30 19:46:59.742 32632  2136 I ReactNativeJS: [CodePush] Checking for update.
08-30 19:46:59.861 32632 32632 I ReactNative: [GESTURE HANDLER] Gesture handler is already enabled for a parent view
08-30 19:46:59.862 32632 32632 I ReactNative: [GESTURE HANDLER] Initialize gesture handler for root view com.swmansion.gesturehandler.react.RNGestureHandlerEnabledRootView{f973df2 V.E...... .......D 0,0-1080,2218 #1}
08-30 19:47:01.293 32632  2136 I ReactNativeJS: [CodePush] Downloading package.
08-30 19:47:01.296 32632  2148 E ReactNative: [CodePush] Exception
08-30 19:47:01.296 32632  2148 E ReactNative: com.microsoft.codepush.react.CodePushUnknownException: Error in getting binary resources modified time
08-30 19:47:01.296 32632  2148 E ReactNative:   at com.microsoft.codepush.react.CodePush.getBinaryResourcesModifiedTime(CodePush.java:207)
08-30 19:47:01.296 32632  2148 E ReactNative:   at com.microsoft.codepush.react.CodePushNativeModule$3.doInBackground(CodePushNativeModule.java:289)
08-30 19:47:01.296 32632  2148 E ReactNative:   at com.microsoft.codepush.react.CodePushNativeModule$3.doInBackground(CodePushNativeModule.java:284)
08-30 19:47:01.296 32632  2148 E ReactNative:   at android.os.AsyncTask$3.call(AsyncTask.java:394)
08-30 19:47:01.296 32632  2148 E ReactNative:   at java.util.concurrent.FutureTask.run(FutureTask.java:266)
08-30 19:47:01.296 32632  2148 E ReactNative:   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
08-30 19:47:01.296 32632  2148 E ReactNative:   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
08-30 19:47:01.296 32632  2148 E ReactNative:   at java.lang.Thread.run(Thread.java:923)
08-30 19:47:01.296 32632  2148 E ReactNative: Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x0
08-30 19:47:01.296 32632  2148 E ReactNative:   at android.content.res.Resources.getText(Resources.java:507)
08-30 19:47:01.296 32632  2148 E ReactNative:   at android.content.res.Resources.getString(Resources.java:600)
08-30 19:47:01.296 32632  2148 E ReactNative:   at com.microsoft.codepush.react.CodePush.getBinaryResourcesModifiedTime(CodePush.java:204)
08-30 19:47:01.296 32632  2148 E ReactNative:   ... 7 more
08-30 19:47:01.298 32632  2136 I ReactNativeJS: [CodePush] An unknown error occurred.
08-30 19:47:01.304 32632  2136 I ReactNativeJS: [CodePush] Error in getting binary resources modified time

I am also getting the same error. Maybe it's a compatibility issue with react native config.

project.ext.react = [
    enableHermes: true,  // clean and rebuild if changing
]
// Since codepush support hermes now we can enable this

// Codepush
apply from: "../../node_modules/react-native/react.gradle"
apply from: "../../node_modules/react-native-code-push/android/codepush.gradle"
// React Native Config
apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle"
// Background Geolocation
Project background_geolocation = project(':react-native-background-geolocation-android')
apply from: "${background_geolocation.projectDir}/app.gradle"

@gabrielbezerra81
Copy link

gabrielbezerra81 commented Sep 2, 2021

@alexandergoncharov

08-30 19:46:59.723 32632  2136 I ReactNativeJS: Running "CwingsDeliveryApp" with {"rootTag":1}
08-30 19:46:59.742 32632  2136 I ReactNativeJS: [CodePush] Checking for update.
08-30 19:46:59.861 32632 32632 I ReactNative: [GESTURE HANDLER] Gesture handler is already enabled for a parent view
08-30 19:46:59.862 32632 32632 I ReactNative: [GESTURE HANDLER] Initialize gesture handler for root view com.swmansion.gesturehandler.react.RNGestureHandlerEnabledRootView{f973df2 V.E...... .......D 0,0-1080,2218 #1}
08-30 19:47:01.293 32632  2136 I ReactNativeJS: [CodePush] Downloading package.
08-30 19:47:01.296 32632  2148 E ReactNative: [CodePush] Exception
08-30 19:47:01.296 32632  2148 E ReactNative: com.microsoft.codepush.react.CodePushUnknownException: Error in getting binary resources modified time
08-30 19:47:01.296 32632  2148 E ReactNative:   at com.microsoft.codepush.react.CodePush.getBinaryResourcesModifiedTime(CodePush.java:207)
08-30 19:47:01.296 32632  2148 E ReactNative:   at com.microsoft.codepush.react.CodePushNativeModule$3.doInBackground(CodePushNativeModule.java:289)
08-30 19:47:01.296 32632  2148 E ReactNative:   at com.microsoft.codepush.react.CodePushNativeModule$3.doInBackground(CodePushNativeModule.java:284)
08-30 19:47:01.296 32632  2148 E ReactNative:   at android.os.AsyncTask$3.call(AsyncTask.java:394)
08-30 19:47:01.296 32632  2148 E ReactNative:   at java.util.concurrent.FutureTask.run(FutureTask.java:266)
08-30 19:47:01.296 32632  2148 E ReactNative:   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
08-30 19:47:01.296 32632  2148 E ReactNative:   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
08-30 19:47:01.296 32632  2148 E ReactNative:   at java.lang.Thread.run(Thread.java:923)
08-30 19:47:01.296 32632  2148 E ReactNative: Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x0
08-30 19:47:01.296 32632  2148 E ReactNative:   at android.content.res.Resources.getText(Resources.java:507)
08-30 19:47:01.296 32632  2148 E ReactNative:   at android.content.res.Resources.getString(Resources.java:600)
08-30 19:47:01.296 32632  2148 E ReactNative:   at com.microsoft.codepush.react.CodePush.getBinaryResourcesModifiedTime(CodePush.java:204)
08-30 19:47:01.296 32632  2148 E ReactNative:   ... 7 more
08-30 19:47:01.298 32632  2136 I ReactNativeJS: [CodePush] An unknown error occurred.
08-30 19:47:01.304 32632  2136 I ReactNativeJS: [CodePush] Error in getting binary resources modified time

I am also getting the same error. Maybe it's a compatibility issue with react native config.

project.ext.react = [
    enableHermes: true,  // clean and rebuild if changing
]
// Since codepush support hermes now we can enable this

// Codepush
apply from: "../../node_modules/react-native/react.gradle"
apply from: "../../node_modules/react-native-code-push/android/codepush.gradle"
// React Native Config
apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle"
// Background Geolocation
Project background_geolocation = project(':react-native-background-geolocation-android')
apply from: "${background_geolocation.projectDir}/app.gradle"

I'm having issues too. Adding CODE_PUSH_APK_BUILD_TIME does allow to receive the first update, but subsequent updates gets stuck in a infinite loop. Removing react-native-config from app/build.gradle apparently makes it work again, without needing CODE_PUSH_APK_BUILD_TIME.

@ghost
Copy link

ghost commented Jan 10, 2022

This issue has been automatically marked as stale because it has not had any activity for 60 days. It will be closed if no further activity occurs within 15 days of this comment.

@ghost
Copy link

ghost commented Jan 26, 2022

This issue will now be closed because it hasn't had any activity for 15 days after stale. Please feel free to open a new issue if you still have a question/issue or suggestion.

@ghost ghost closed this as completed Jan 26, 2022
@Desintegrator
Copy link

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())

That worked for me!

thats worked for me too

@ghost ghost removed the stale label Jan 26, 2022
@vgvishal538
Copy link

The issue is still present in version 7.0.4 apart from above workaround does anyone have permanent fix

@adrach
Copy link

adrach commented Feb 19, 2022

both solutions seem to work for me (either gradle downgrade or patch)
#1961 (comment)
#2085 (comment)

@marcpope
Copy link

marcpope commented Feb 22, 2022

#1961 (comment) also worked for me.


System:
    OS: macOS 12.0.1
    CPU: (8) x64 Apple M1
    Memory: 59.50 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 17.0.1 - /usr/local/bin/node
    Yarn: 1.22.17 - /usr/local/bin/yarn
    npm: 6.14.8 - /usr/local/bin/npm
    Watchman: 2021.11.08.00 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.11.2 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 21.0.1, iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0
    Android SDK:
      API Levels: 29, 30, 31
      Build Tools: 30.0.2, 32.0.0, 32.1.0
      System Images: android-29 | ARM 64 v8a, android-29 | Intel x86 Atom_64, android-29 | Google APIs ARM 64 v8a, android-29 | Google Play ARM 64 v8a, android-30 | Google APIs ARM 64 v8a, android-31 | Google APIs Intel x86 Atom_64
      Android NDK: Not Found
  IDEs:
    Android Studio: 2021.1 AI-211.7628.21.2111.8139111
    Xcode: 13.1/13A1030d - /usr/bin/xcodebuild
  Languages:
    Java: 17.0.2 - /usr/bin/javac
  npmPackages:
    react: 17.0.2 => 17.0.2 
    react-native: 0.66.4 => 0.66.4 


@hungvu193
Copy link

I tried all the solutions above and nothing works at all.
I'm using React Native 0.67.4 and codepush 7.0.4

@jamninetyfive
Copy link

same here

@kirgy
Copy link

kirgy commented Aug 19, 2022

Same issue using react-native@0.69.1 and react-native-code-push@7.0.4. The change recommended in the comments solved the problem for me.

@dwidc
Copy link

dwidc commented Sep 6, 2022

In my case I fixed this error by adding these lines:

afterEvaluate {
    android.buildTypes.each {
        it.resValue 'string', "CODE_PUSH_APK_BUILD_TIME", String.format("\"%d\"", System.currentTimeMillis())
    }
}

to the bottom of my android/app/build.gradle

 

It's copied directly from /node_modules/react-native-code-push/android/codepush.gradle :

gradle.projectsEvaluated {
android.buildTypes.each {
// to prevent incorrect long value restoration from strings.xml we need to wrap it with double quotes
// https://github.com/microsoft/cordova-plugin-code-push/issues/264
it.resValue 'string', "CODE_PUSH_APK_BUILD_TIME", String.format("\"%d\"", System.currentTimeMillis())
}

 

Environment:

  • react-native: 0.65.1
  • react-native-code-push: 7.0.5
  • appcenter-cli: 2.11.0
  • gradle-6.9-all
  • com.android.tools.build:gradle: 4.2.1
  • buildToolsVersion: 30.0.2
  • minSdkVersion: 21
  • compileSdkVersion: 30
  • targetSdkVersion: 30
  • Emulator: Android 12 API 31 | Google Play | x86_64

 

I think the problem lies with gradle.projectsEvaluated block on /node_modules/react-native-code-push/android/codepush.gradle .
It's able to modify resValue field in config, as I see from gradle output it's replacing my previously set resValue from afterEvaluate block:

WARNING:: BuildType(debug): resValue 'CODE_PUSH_APK_BUILD_TIME' value is being replaced: "1662110284290" -> "1662110284761"

However it didn't make it to final gradleResValues.xml.
I'm not too familiar with gradle lifecycle, but I think it's run too late in the build process.

 

You can check yourself if the CODE_PUSH_APK_BUILD_TIME managed to be included as android resource, by checking android/app/build/generated/res/resValues/<buildTypes>/values/gradleResValues.xml

A successful inclusion will look like this gradleResValues.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <!-- Automatically generated file. DO NOT MODIFY -->

    <!-- Value from build type: debug -->
    <string name="CODE_PUSH_APK_BUILD_TIME" translatable="false">"1662439557897"</string>
    <!-- Value from build type: debug -->
    <integer name="react_native_dev_server_port">8081</integer>
    <!-- Value from build type: debug -->
    <integer name="react_native_inspector_proxy_port">8081</integer>

</resources>

If gradleResValues.xml didn't contain CODE_PUSH_APK_BUILD_TIME, it will cause error when trying to fetch codepush update.

@Mafooch
Copy link

Mafooch commented Nov 1, 2022

Following for a proper fix. using #1961 (comment) for now.

@mateusdegobi
Copy link

mateusdegobi commented Nov 8, 2022

Quote:
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())

image

This is worked for me. 🚀
I got the error by creating "another" application and used the same CodePush key in the "new" application. (They have the same src/)

Old app: RN 0.66.1
New app: RN 0.70.5
On both: react-native-code-push@^7.0.4

I use CodePush CLI and it's at v3.0.0.

@ducdetronquito
Copy link

Hi !

The same error happened to me while trying to experiment with React-Native and CodePush for the first time.
I just created an bare minimal app following the tutorial command for a typescript project:

npx react-native init AwesomeTSProject --template react-native-template-typescript

Then the app is built on debug mode and deployed manually on a real Android 10 device with the following steps:

mkdir -p android/app/src/main/assets/
touch android/app/src/main/assets/index.android.bundle

# Bundle the app
npx react-native bundle \
    --platform android \
    --dev false \
    --entry-file index.js \
    --bundle-output android/app/src/main/assets/index.android.bundle \
    --assets-dest android/app/src/main/res/

# Build a debug APK
cd android && gradlew assembleDebug

# Deploy on a real device
adb install android/app/build/outputs/apk/debug/app-debug.apk

When running the app, the CodePush update is detected on the server and downloaded but not installed because the sync fail with the following error:

11-10 16:15:08.456 26542 26591 I ReactNativeJS: [CodePush] Checking for update.
11-10 16:15:08.471 26542 26591 I ReactNativeJS: [CodePush] Reporting binary update (1.0)
11-10 16:15:09.864 26542 26591 I ReactNativeJS: [CodePush] Downloading package.
11-10 16:15:09.874 26542 26568 E ReactNative: [CodePush] Exception
11-10 16:15:09.874 26542 26568 E ReactNative: com.microsoft.codepush.react.CodePushUnknownException: Error in getting binary resources modified time
11-10 16:15:09.874 26542 26568 E ReactNative:   at com.microsoft.codepush.react.CodePush.getBinaryResourcesModifiedTime(CodePush.java:207)
11-10 16:15:09.874 26542 26568 E ReactNative:   at com.microsoft.codepush.react.CodePushNativeModule$3.doInBackground(CodePushNativeModule.java:289)
11-10 16:15:09.874 26542 26568 E ReactNative:   at com.microsoft.codepush.react.CodePushNativeModule$3.doInBackground(CodePushNativeModule.java:284)
11-10 16:15:09.874 26542 26568 E ReactNative:   at android.os.AsyncTask$3.call(AsyncTask.java:378)
11-10 16:15:09.874 26542 26568 E ReactNative:   at java.util.concurrent.FutureTask.run(FutureTask.java:266)
11-10 16:15:09.874 26542 26568 E ReactNative:   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
11-10 16:15:09.874 26542 26568 E ReactNative:   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
11-10 16:15:09.874 26542 26568 E ReactNative:   at java.lang.Thread.run(Thread.java:919)
11-10 16:15:09.874 26542 26568 E ReactNative: Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x0
11-10 16:15:09.874 26542 26568 E ReactNative:   at android.content.res.Resources.getText(Resources.java:369)
11-10 16:15:09.874 26542 26568 E ReactNative:   at android.content.res.Resources.getString(Resources.java:462)
11-10 16:15:09.874 26542 26568 E ReactNative:   at com.microsoft.codepush.react.CodePush.getBinaryResourcesModifiedTime(CodePush.java:204)
11-10 16:15:09.874 26542 26568 E ReactNative:   ... 7 more
11-10 16:15:09.884 26542 26591 I ReactNativeJS: [CodePush] An unknown error occurred.
11-10 16:15:09.884 26542 26591 I ReactNativeJS: [CodePush] Error in getting binary resources modified time

On the positive side, @evelant fix is working
Cf: #1961 (comment)

Environment:

  • Windows 10
  • react-native: 0.70.5
  • react-native-code-push: 7.0.5
  • appcenter-cli: 2.11.0
  • react-native-gradle-plugin: 0.70.3
  • gradle-7.5.1-all
  • com.android.tools.build:gradle:7.2.1

I hope this old bug gets more attention :)
Thanks again for this great piece of software anyway !

@nicolascavallin
Copy link

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())

Solved, thanks!

@longnc100500
Copy link

@evelant you save my life

@yepMad
Copy link

yepMad commented Jan 21, 2023

Apparently this only affects buildType "releaseStaging", in "release" everything runs fine. That's it?

@svmurvi
Copy link

svmurvi commented Feb 2, 2023

Unfortunately was same problem "CodePushUnknownException; Error in getting binary resources modified time"
App crashed when trying to open it, recently there was a release and certificates .pem for error monitoring were changed
Some project info:

RN 0.67.5
RN Code Push 6.4.1
Gradle 7.2
buildscript.ext {
buildToolsVersion = "31.0.0"
minSdkVersion = 21
compileSdkVersion = 31
targetSdkVersion = 31
ndkVersion = "21.4.7075529"
kotlinVersion = "1.6.10"
}

Adding at defaultConfig this line an upgrade RN Code Push to 7.1.0 solved my problem

defaultConfig { ... resValue 'string', "CODE_PUSH_APK_BUILD_TIME", String.format("\"%d\"", System.currentTimeMillis()) }
Not sure which of these methods works, but thanks

@Dror-Bar
Copy link

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())

With latest version 7.1.0 I still had to add this to get it working in releaseStaging...

@sheikhazazkhalid
Copy link

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())

With latest version 7.1.0 I still had to add this to get it working in releaseStaging...

I can confirm this issue is still there on version 7.4.2. But above solution works well.

@MikhailSuendukov
Copy link
Contributor

Hello @sheikhazazkhalid , could you please clarify which version of the Android Gradle Plugin (AGP) you are using? If you are currently on version 4.1, have you considered upgrading to a newer version to see if that resolves your issue?

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests