问题描述
由于某种原因,我的android项目无法解析到js/css/images的任何静态路径,而在Web和ios上都能正常工作.我没有使用离子技术,所以也许我缺少一些特定的东西?但是,所有这些文件都可以在android项目中使用.
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.
这里是突出显示此问题的图像,您可以看到android应用程序看起来完全坏了,并且只显示了base64编码的图像.它没有应用样式,也没有任何js在起作用,它只是显示一些预先渲染的html.
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.
箭头突出显示所有这些文件确实已被请求并且位于android文件夹中
Arrow highlight that all these files are indeed being requested and are inside android folder
推荐答案
这确实是Android的功能".
This is really an Android "feature".
默认情况下,它不会将以_
开头的资产文件夹复制到生成的apk中(请参阅 https://android.googlesource.com/platform/frameworks/base/+/b41af58f49d371cedf041443d20a1893f7f6c840/tools/aapt/AaptAssets.cpp#60 ).
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).
您可以通过以下方法解决此问题:添加带有样式的自定义aaptOptions
并忽略_ *,以便将其复制.像这样:
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:!*~'
}
它应该进入android-> defaultConfig
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:!*~'
}
}
}
这篇关于Android专案无法解决任何静态资产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!