Been working on an Android Webview app and I've only just now started to use a node_modules folder in there, so naturally I did some research on how to exclude it and I ended up at this question here
Tried some of the answers and the one that actually worked the best for me was the one about aaptOptions
So of course naturally I'm playing around with it, trying to figure out what works, and I succeed at excluding a few folders from the debug apk.
aaptOptions {
ignoreAssetsPattern '!node_modules:!jsunmin:!.idea:!jade:!css-scss:'
}
And I can indeed confirm that those folders aren't included in the final APK in Android studio! Success!
So then I realize that I can do something a bit clever: when I'm running my app, testing it on my end, debugging it, I like to have certain credentials in certain places automatically put in - I do this with javascript - but obviously I don't want these credentials included in the APKs I might send out into the world -- even though I've already coded it to not input the credentials automatically unless I'm debugging, the credentials are still actually in the javascript files, and presumably someone could look in there and see them!
So my idea was to create a file, 'example-creds.js', and use aaptOptions to not include that file, ONLY on release builds, so I came up with something that looks approximately like this (extra details stripped out):
android {
buildTypes {
release {
aaptOptions {
ignoreAssetsPattern '!node_modules:!jsunmin:!.idea:!jade:!css-scss:!example-creds.js:'
}
}
debug {
aaptOptions {
ignoreAssetsPattern '!node_modules:!jsunmin:!.idea:!jade:!css-scss:'
}
}
}
}
BUT IT DOESN'T WORK! I've tested it and it seems to run whatever the last-defined aaptOptions is, regardless of the build type. If I put release after debug, I get no example-creds in either build. If I put debug after release, I get example-creds in both.
How can I get what I'm looking for?