APK stopped working after minify, uglify - Code runs on : 'ionic serve --lab' and and 'ionic run android' but not on 'ionic build android'

I was following the [tutorial to make a production ready ionic app][1]. I wanted to uglify my js.
All works great except for ‘ionic build android’ generates an apk, installing which the app doesn’t run. The same code runs with ‘ionic serve --lab’ and ‘ionic run android’. Please help.

Code runs on : ‘ionic serve –lab’ and and 'ionic run android’ but not on 'ionic build android’

I added the following code for exception handling, is there a better way to know what run-time exception might cause something like this?

    // catch exceptions out of angular
    window.onerror = function(message, url, line, col, error) {
      var debug = true;
      var stopPropagation = debug ? false : true;
      var data = {
        type: 'javascript',
        url: window.location.hash,
        localtime: Date.now()
      };
      if (message) {
        data.message = message;
      }
      if (url) {
        data.fileName = url;
      }
      if (line) {
        data.lineNumber = line;
      }
      if (col) {
        data.columnNumber = col;
      }
      if (error) {
        if (error.name) {
          data.name = error.name;
        }
        if (error.stack) {
          data.stack = error.stack;
        }
      }

      if (debug) {
        console.log('exception', data);
        window.alert('Error: ' + data.message);
      } else {
        track('exception', data);
      }
      return stopPropagation;
    };

I got the following error after runnig adb logcat

E/AndroidProtocolHandler( 3622): Unable to open asset URL: file:///android_asset
/www/css/social-icons.css
E/AndroidProtocolHandler( 3622): Unable to open asset URL: file:///android_asset
/www/css/font-awesome.css
E/AndroidProtocolHandler( 3622): Unable to open asset URL: file:///android_asset
/www/css/style-chetan.css
E/AndroidProtocolHandler( 3622): Unable to open asset URL: file:///android_asset
/www/css/tabSlideBox.css
E/AndroidProtocolHandler( 3622): Unable to open asset URL: file:///android_asset
/www/dist/dist_js/app/app.js
E/AndroidProtocolHandler( 3622): Unable to open asset URL: file:///android_asset
/www/dist/dist_js/app/controllers.js
E/AndroidProtocolHandler( 3622): Unable to open asset URL: file:///android_asset
/www/dist/dist_js/app/services.js
E/AndroidProtocolHandler( 3622): Unable to open asset URL: file:///android_asset
/www/dist/dist_js/app/openfb.js
E/AndroidProtocolHandler( 3622): Unable to open asset URL: file:///android_asset
/www/dist/dist_js/app/ngopenfb.js
E/AndroidProtocolHandler( 3622): Unable to open asset URL: file:///android_asset
/www/dist/dist_js/app/collide.js
E/AndroidProtocolHandler( 3622): Unable to open asset URL: file:///android_asset
/www/dist/dist_js/app/ionic.tdcards.js
E/AndroidProtocolHandler( 3622): Unable to open asset URL: file:///android_asset
/www/dist/dist_js/app/mfb-directive.js
E/AndroidProtocolHandler( 3622): Unable to open asset URL: file:///android_asset
/www/dist/dist_js/app/ng-cordova-oauth.min.js
E/AndroidProtocolHandler( 3622): Unable to open asset URL: file:///android_asset
/www/dist/dist_js/app/ng-cordova.min.js
E/AndroidProtocolHandler( 3622): Unable to open asset URL: file:///android_asset
/www/dist/dist_js/app/facebookConnectPlugin.js
E/AndroidProtocolHandler( 3622): Unable to open asset URL: file:///android_asset
/www/dist/dist_js/app/tabSlideBox.js
E/AndroidProtocolHandler( 3622): Unable to open asset URL: file:///android_asset
/www/dist/dist_js/app/templates.js
E/AndroidProtocolHandler( 3622): Unable to open asset URL: file:///android_asset
/www/dist/dist_js/app/ng-tags-input.js
E/AndroidProtocolHandler( 3622): Unable to open asset URL: file:///android_asset
/www/css/ng-tags-input.bootstrap.css
E/AndroidProtocolHandler( 3622): Unable to open asset URL: file:///android_asset
/www/css/ng-tags-input.css

My apk doesn’t have these files, as I have installed npm install gulp-useref --save-dev as mentioned in the tutorial. This builds all css and js to one single file.
Also inside the apk in assets/ww now I have only two folders dist_js and dist_css
[1]: https://www.airpair.com/ionic-framework/posts/production-ready-apps-with-ionic-framework

Hi.
See the log error running the command: “ionic run android -l -s”.
Some commands not working in the device but working in the server.
Example: Number.parseInt.

I noticed that -l works which means livereload. But apk fails to start, exception handling also works in ionic run android -l mode. I followed all the steps in the link to uglify my code, but didn’t make any changes in the code itself. How to debug something on the device?

What does the Android Debug monitor log?

If you don’t use it, start doing it :stuck_out_tongue: It will make life easier

1 Like

Thank you this step helped me in solving the problem. Had to make some changes in setting paths in my gulp tasks :slight_smile:

Would’ve been really nice if you put down details on how you solved this to help others.