Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to delete a resource file for Android? #207

Open
ndrake opened this issue Dec 6, 2023 · 1 comment
Open

How to delete a resource file for Android? #207

ndrake opened this issue Dec 6, 2023 · 1 comment

Comments

@ndrake
Copy link

ndrake commented Dec 6, 2023

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.

@reslear
Copy link

reslear commented Apr 20, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants