Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to trace JavascriptException index.android.bundle:424:4194 to line number in JS source?

Google Play stack trace points the cause of crash at:

com.facebook.react.modules.core.JavascriptException: addWaypointDone
    index.android.bundle:424:4194

I extracted index.android.bundle from the apk.

How do I get a JS source code line number from 424:4194 ?

Thanks Daniel. Your approach worked for me from the command-line!

I tried adding this to android/app/react.gradle but I could not find and source.map file under the ./android directory.

commandLine "react-native", "bundle", "--platform", "android", "--dev", "${devEnabled}”,
"--sourcemap-output", "source.map",
"--entry-file", entryFile, "--bundle-output", jsBundleFile, "--assets dest", resourcesDir

Is there a way to auto-build source.map file very time?

Thanks in advance,

like image 338
Ed of the Mountain Avatar asked Jun 14 '16 22:06

Ed of the Mountain


2 Answers

To get an exact position you need a source map. If you don't keep those for your deploys you can regenerate it.

  • Check out the exact version you deployed from your VCS
  • Bundle it with source map output: react-native bundle --entry-file index.android.js --platform android --dev false --sourcemap-output source.map --bundle-output main.jsbundle (make sure you use the exact same dependency versions you used in your release)
  • Create a file findpos.js containing the following code:

findpos.js

var sourceMap = require('source-map');
var fs = require('fs');

var sourcemap = JSON.parse(fs.readFileSync('source.map', 'utf8'));

var smc = new sourceMap.SourceMapConsumer(sourcemap);

console.log(smc.originalPositionFor({
  line: 424,
  column: 4194
}));
  • Execute the script node findpos.js

You should get the exact location of the error (file, line and column).

like image 174
Daniel Basedow Avatar answered Nov 05 '22 16:11

Daniel Basedow


How to use Atom to find the exception source code in the index.android.bundle

  1. Get stack trace from Google Play
  2. Rename the apk file with a zip extension and extract apk
  3. Using Atom or other editor, open up the extracted '''assets/index.android.bundle''
  4. Edit > Go to Line , from stack trace, 424:4194

All white-space is removed from the index.android.bundle and lines are concatenated to a single line. But it identifies the culprit.

like image 20
Ed of the Mountain Avatar answered Nov 05 '22 14:11

Ed of the Mountain