angularionic-frameworkcapacitorandroid-obfuscation

Ionic JavaScript Obfuscation


I have a problem with JavaScript obfuscation in my Ionic 6 - Capacitor 6 - Angular 14 project, I followed the official guide using javascript-obfuscator and I can see the obfuscated files correctly inside the www folder but when I enter the apk the assets\public\main.js file is not obfuscated as well as the others.

I have also tried removing the android platform ionic cap remove android and adding it back ionic cap add android.


Solution

  • I found the solution, you need to change the line to the scripts section of package.json from:

    ...
      "scripts": {     
        "capacitor:copy:after": "npx javascript-obfuscator www --output www --self-defending true"
      }
    

    To

        ...
      "scripts": {     
        "ionic:build:after": "npx javascript-obfuscator www --output www --self-defending true"
      }