ionic-team/trapeze

How to delete a resource file for Android?

ndrake opened this issue · 1 comments

ndrake commented

Does Trapeze have a built-in way to delete resource files from an Android project? I only see a way to add files.

Some background

We're in the process of migrating from Cordova to Capacitor, and are using Trapeze to allow us to tweak the native projects for different environments. When building a local development version of our Android against a developer's local backend services, we add a network_security_config.xml and custom CA so that our non-prod SSL certs are accepted by Android. This is working fine. The problem is, when we want to run Trapeze to reconfigure things to point to prod/qa (anything non-local) we need to remove the network_security_config.xml and custom CA file.

So, in our local development Trapeze configuration we have this to add the required files:

    manifest:
      - file: AndroidManifest.xml
        target: manifest/application
        attrs:
          android:networkSecurityConfig: "@xml/network_security_config"
    res:
      - path: raw
        file: local_dev_ca
        source: path/to/local_dev_ca
      - path: xml
        file: network_security_config.xml
        source: path/to/network_security_config.xml

In our prod Trapeze config we are able to delete the AndroidManifest.xml changes with:

    manifest:
      - file: AndroidManifest.xml
        target: manifest/application
        deleteAttributes:
          - android:networkSecurityConfig

But how do we delete the two files from under android/app/src/main/res using Trapeze? It would be nice to have Trapeze handle this, but I suppose it would be easy enough to just run rm android/app/src/main/res/... as a separate step.

need support delete option but is no implement yet, workaround is run before trapeze sh script

rm android/app/src/main/res/xml/network_security_config.xml && trapeze run

or better create script file and move logic too.

or remove file, add to .gitignore:

frontend/android/app/src/main/res/xml/network_security_config.xml

and then generate before running dev:

# create network security config

NETWORK_SECURITY_CONFIG_PATH="android/app/src/main/res/xml/network_security_config.xml"

if [ ! -f "$NETWORK_SECURITY_CONFIG_PATH" ]; then
  echo "<network-security-config>
    <base-config cleartextTrafficPermitted="false">
        <trust-anchors>
            <certificates src="@raw/ca"/>
            <certificates src="system"/>
        </trust-anchors>
    </base-config>
    <debug-overrides>
        <trust-anchors cleartextTrafficPermitted="false">
            <certificates src="@raw/ca"/>
            <certificates src="system"/>
        </trust-anchors>
    </debug-overrides>
</network-security-config>" > "$NETWORK_SECURITY_CONFIG_PATH"
fi