gradle ignore all but one folder

235 views
Skip to first unread message

Phil Dougherty

unread,
Sep 11, 2020, 6:22:54 PM9/11/20
to android-ndk
In my build.gradle, I have the following snippet:
  
sourceSets {
    main {
      manifest.srcFile 'AndroidManifest.xml'
      assets.srcDirs 'C:\\Users\\phildo\\Desktop\\projects\\gnometower\\build\\resources'
    }
  }

With this snippet, in order to access `C:\Users\phildo\Desktop\projects\gnometower\build\resources\my_asset.png`, I reference `"my_asset.png"` (via AAssetManager). This works fine.

However, in the PC version of my codebase, all my asset filepaths would access the above via `"resources\my_asset.png"`. So, in order to keep it consistent, I could simply remove the `resources` appendation from the assets.srcDirs gradle build snippet. The issue there is that the `build` folder contains a bunch of other noise I would not want to include in my APK.

So: how can I include the resources folder, while keeping the root as the folder ABOVE that, and without including anything else?

I assume there is something like

      assets.srcDirs 'C:\\Users\\phildo\\Desktop\\projects\\gnometower\\build'
      assets.ignore '*'
      assets.add 'resources'

or something?

though I can't find the syntax for any such thing.

Alex Cohn

unread,
Oct 14, 2020, 8:01:53 AM10/14/20
to android-ndk
You can do that, but not in the sourceSets section. In your build.gradle, you can have 

android {
  packagingOptions {
    exclude 'assets/unused1'
    exclude 'assets/unused2'
  }
}

Unfortunately, with PackagingOptions you cannot exclude everything, and on top of that add only resources. But if you can find a pattern, e.g. assets/unused*, then it will probably help to make your script shorter.

BR,
Alex Cohn
Reply all
Reply to author
Forward
0 new messages