How to modify "/android/app/build.gradle" with app.json?

Please provide the following:

  1. SDK Version: 49
  2. Platforms(Android/iOS/web/all): Android

I need to modify the file /android/app/build.gradle and add the following lines into the android{} object:

android {
    aaptOptions {
        ignoreAssetsPattern '!._'

    sourceSets {
      main {
        assets.srcDirs = ['../../assets']

How can I do that (persistently) with app.json, so that I can do expo prebuild --clean?

Hi @changeowu

I’m not sure if this will do what you want:

If not, you will have to write a Config Plugin to do it.

If I understand this correctly, I need to create a app.config.js and add the following:

module.exports = {
    name: 'my-app',
    mods: {
        ios: {
            /* iOS mods... */
        android: {
            /* Android mods... */
            appBuildGradle: {
                aaptOptions: {
                    ignoreAssetsPattern: '!._'
                sourceSets: {
                    main: {
                        assets: {
                            srcDirs: ['../../assets']

Would that work?

Unfortunately I don’t believe that’s enough. For things like android/app/build.gradle there’s no nice parser/serializer to make updates, so you have to basically do a search and replace to make the changes. That’s why it’s classified as a “dangerous” mod.

I haven’t written any config plugins in quite a while and I never considered myself an expert, but what I found helpful in the past was searching Expo’s repos on GitHub for references to e.g. appBuildGradle

In order to use your own plugin, you can just dump it in a file in your app (it can be called anything), and then reference it in the plugins section of app.json like this:

"plugins": [

Or if you want to pass in some arguments:

"plugins": [
      "arg1": "value1",
      "arg2": 42

Some old plugins I wrote:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.