React-native-code-push: [Android_6.x or higher]An error occurred while executing doInBackground()

Created on 7 Jun 2017  路  7Comments  路  Source: microsoft/react-native-code-push

Description

I've push a new bundle with CodePush for my App then my App crashed.

06-07 08:58:52.228 32134-32283/com.awesomeproject E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
                                                                    Process: com.awesomeproject, PID: 32134
                                                                    java.lang.RuntimeException: An error occurred while executing doInBackground()
                                                                        at android.os.AsyncTask$3.done(AsyncTask.java:330)
                                                                        at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
                                                                        at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
                                                                        at java.util.concurrent.FutureTask.run(FutureTask.java:242)
                                                                        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
                                                                        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
                                                                        at java.lang.Thread.run(Thread.java:776)
                                                                     Caused by: com.microsoft.codepush.react.CodePushUnknownException: Error in getting binary resources modified time
                                                                        at com.microsoft.codepush.react.CodePush.getBinaryResourcesModifiedTime(CodePush.java:113)
                                                                        at com.microsoft.codepush.react.CodePushNativeModule$3.doInBackground(CodePushNativeModule.java:233)
                                                                        at com.microsoft.codepush.react.CodePushNativeModule$3.doInBackground(CodePushNativeModule.java:228)
                                                                        at android.os.AsyncTask$2.call(AsyncTask.java:316)
                                                                        at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                                                                        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)聽
                                                                        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)聽
                                                                        at java.lang.Thread.run(Thread.java:776)聽
                                                                     Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x0
                                                                        at android.content.res.HwResources.getText(HwResources.java:442)
                                                                        at android.content.res.Resources.getString(Resources.java:444)
                                                                        at com.microsoft.codepush.react.CodePush.getBinaryResourcesModifiedTime(CodePush.java:110)

In Android 5.x, everything works fine.iOS works fine in all version too.

Reproduction

I've made a new Project to reproduce this issue.Please run it in Android 6.x ~ 7.x.
https://github.com/youngcube/AwesomeProject

Additional Information

  • react-native-code-push version:2.0.3-beta
  • react-native version:0.44.0
  • iOS/Android/Windows version:Android 6.0.1
  • Does this reproduce on a debug build or release build?Debug & Release
  • Does this reproduce on a simulator, or only on a physical device?Google Nexus 5 & simulator

Other dependency :
"react": "16.0.0-alpha.6",
"react-native": "0.44.0",
"react-native-code-push": "^2.0.3-beta",
"react-native-sqlite-storage": "^3.3.1",
"react-native-macos": "0.12.0"

(The more info the faster we will be able to address it!)

question

Most helpful comment

Hi @youngcube, thanks for reaching us.
I believe I've found the root cause of the issue - you need to add this line:
apply from: "../../node_modules/react-native-code-push/android/codepush.gradle" to your build.gradle file , because as of now codepush.gradle script does not executed.
Please also double check if you have completed all Android installation steps

Please let me know if it helps

All 7 comments

Hi @youngcube, thanks for reaching us.
I believe I've found the root cause of the issue - you need to add this line:
apply from: "../../node_modules/react-native-code-push/android/codepush.gradle" to your build.gradle file , because as of now codepush.gradle script does not executed.
Please also double check if you have completed all Android installation steps

Please let me know if it helps

@sergey-akhalkov Thanks for reply !
I've add the line I've missed. But no luck. It's crash again in Android 6.x. I've also checked these steps again.But nothing more found to append = =

@youngcube, the issue with resources build time is fixed, but I can confirm that the app is still crashes, I've investigated your MainActivity.java file and I can see that it has very specific structure, so I've changed it to this one

package com.awesomeproject;

import com.facebook.react.ReactActivity;

public class MainActivity extends ReactActivity {

    /**
     * Returns the name of the main component registered from JavaScript.
     * This is used to schedule rendering of the component.
     */
    @Override
    protected String getMainComponentName() {
        return "AwesomeProject";
    }
}

and I've successfully launched your app. Could you please try the code above and let me know if it works for you?

@sergey-akhalkov Sorry for late reply. I've changed my Project like you said. When I change getMainComponentName () to the real ComponentName in my bundle(In this Project it's TingBadgeManager) file it crashed again with same error log.. I've just commit it. Please check.

@youngcube, please try add CodePush.getJSBundleFile(); line before setContentView(mReactRootView); like this:

public class MainActivity extends ReactActivity implements DefaultHardwareBackBtnHandler {
    private ReactRootView mReactRootView;
    private ReactInstanceManager mReactInstanceManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mReactRootView = new ReactRootView(this);
        mReactInstanceManager = ReactInstanceManager.builder()
                .setApplication(getApplication())
                .setBundleAssetName("main.bundle")
                .setJSMainModuleName("TingBadgeManager")
                .addPackage(new SQLitePluginPackage())
                .addPackage(new CodePush("dGwE7TupBMiZyAxCAPABUpAg-FjL8157884c-07f4-462d-87f8-bfa0f5f1d9e6", getApplicationContext(), BuildConfig.DEBUG))       // register CodePush Plugin here
                .addPackage(new MainReactPackage())
                .setUseDeveloperSupport(com.facebook.react.BuildConfig.DEBUG)
                .setInitialLifecycleState(LifecycleState.RESUMED)
                .build();
        mReactRootView.startReactApplication(mReactInstanceManager, "TingBadgeManager", null);
        CodePush.getJSBundleFile();
        setContentView(mReactRootView);
    }

You also probably will need to specify your bundle filename CodePush.getJSBundleFile("main.bundle");
Please let me know if it helps.

@sergey-akhalkov Thank you ! I've just add CodePush.getJSBundleFile("main.bundle"); It works !

    productFlavors {
        staging {
            ...
            resValue 'string', "CODE_PUSH_APK_BUILD_TIME", String.format("\"%d\"", System.currentTimeMillis())
            ...
        }
        production {
            ...
            resValue 'string', "CODE_PUSH_APK_BUILD_TIME", String.format("\"%d\"", System.currentTimeMillis())
            ...
        }
    }

In /android/app/build.gradle, I added this line resValue 'string', "CODE_PUSH_APK_BUILD_TIME", String.format("\"%d\"", System.currentTimeMillis())

Was this page helpful?
1 / 5 - 1 ratings

Related issues

EdmundMai picture EdmundMai  路  4Comments

Adr1ann picture Adr1ann  路  3Comments

djw27 picture djw27  路  3Comments

fanzhiri picture fanzhiri  路  3Comments

Phredward picture Phredward  路  3Comments