Android project is not resolving any static assets

倾然丶 夕夏残阳落幕 提交于 2019-12-14 02:19:32

问题


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


回答1:


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:!*~'
        }
    }
}


来源:https://stackoverflow.com/questions/59156104/android-project-is-not-resolving-any-static-assets

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!