Search code examples
androidionic-frameworkcapacitor

Android project is not resolving any static assets


For some reason my android project is not resolving any static paths to js / css / images while it works fine on web and ios. I am not using ionic, so maybe I am missing something specific? However all these files are available in android project.

Here is an image highlighting this issue, you can see that android app appears completely broken and only shows images that are base64 encoded. It has no styles applied not any js is working, it's just showing some html that was pre-rendered.

Arrow highlight that all these files are indeed being requested and are inside android folder

enter image description here


Solution

  • This is really an Android "feature".

    By default it doesn't copy assets folders starting with _ to the resulting apk (see https://android.googlesource.com/platform/frameworks/base/+/b41af58f49d371cedf041443d20a1893f7f6c840/tools/aapt/AaptAssets.cpp#60).

    You can workaround it by adding custom aaptOptions with the pattern to ignore, removing the _* so they get copied. Something like this:

    aaptOptions {
        ignoreAssetsPattern '!.svn:!.git:!.ds_store:!*.scc:!CVS:!thumbs.db:!picasa.ini:!*~'
    }
    

    It should go in the app's build.gradle inside android -> defaultConfig

    android {
        ...
        defaultConfig {
            ...
            aaptOptions {
                ignoreAssetsPattern '!.svn:!.git:!.ds_store:!*.scc:!CVS:!thumbs.db:!picasa.ini:!*~'
            }
        }
    }