m0dch3n / vue-cli-plugin-cordova

Vue Cli 3 Cordova Plugin
MIT License
417 stars 63 forks source link

android production build doesn't contain public files #44

Closed syonip closed 5 years ago

syonip commented 5 years ago

When running cordova-serve-android, I can access a static CSV file in the public folder, but when running cordova-build-android and deploying with cordova run android, the file doesn't exist or isn't accessible in the built app.

android_error

I made a repo to help reproduce: https://github.com/syonip/cordova-android-error

BTW cordova-serve-browser and cordova-build-browser both work fine.

m0dch3n commented 5 years ago

$ unzip Test.apk Archive: Test.apk inflating: META-INF/MANIFEST.MF inflating: META-INF/SHIFTSHA.SF inflating: META-INF/SHIFTSHA.RSA inflating: AndroidManifest.xml inflating: assets/www/cordova-js-src/android/nativeapiprovider.js inflating: assets/www/cordova-js-src/android/promptbasednativeapi.js inflating: assets/www/cordova-js-src/exec.js inflating: assets/www/cordova-js-src/platform.js inflating: assets/www/cordova-js-src/plugin/android/app.js inflating: assets/www/cordova.js inflating: assets/www/cordova_plugins.js inflating: assets/www/css/app.326784ad.css inflating: assets/www/favicon.ico extracting: assets/www/img/logo.82b9c7a5.png inflating: assets/www/index.html inflating: assets/www/js/app.7559e38f.js inflating: assets/www/js/app.7559e38f.js.map inflating: assets/www/js/chunk-vendors.705a545f.js inflating: assets/www/js/chunk-vendors.705a545f.js.map extracting: assets/www/test.csv inflating: classes.dex extracting: res/drawable-land-hdpi-v4/screen.png extracting: res/drawable-land-ldpi-v4/screen.png extracting: res/drawable-land-mdpi-v4/screen.png extracting: res/drawable-land-xhdpi-v4/screen.png extracting: res/drawable-land-xxhdpi-v4/screen.png extracting: res/drawable-land-xxxhdpi-v4/screen.png extracting: res/drawable-port-hdpi-v4/screen.png extracting: res/drawable-port-ldpi-v4/screen.png extracting: res/drawable-port-mdpi-v4/screen.png extracting: res/drawable-port-xhdpi-v4/screen.png extracting: res/drawable-port-xxhdpi-v4/screen.png extracting: res/drawable-port-xxxhdpi-v4/screen.png extracting: res/mipmap-hdpi-v4/icon.png extracting: res/mipmap-ldpi-v4/icon.png extracting: res/mipmap-mdpi-v4/icon.png extracting: res/mipmap-xhdpi-v4/icon.png extracting: res/mipmap-xxhdpi-v4/icon.png extracting: res/mipmap-xxxhdpi-v4/icon.png inflating: res/xml/config.xml extracting: resources.arsc $

The file exists, please simply change

https://github.com/syonip/cordova-android-error/blob/8488ebc9dfa1d041c6af21cc57901d8ee426a6e5/src/components/HelloWorld.vue#L25

to

.get("test.csv")

This is also explained in the README

Assets and Scripts in vue's public folder need to have a dynamic path, because depending on dev or production build, you have different bases. In dev it's normally '/' and in production it's 'file:///android_asset/www/'. In other words, if you have i.e. an image under 'public/images/me.jpg', the relative url would be img='images/me.jpg'

syonip commented 5 years ago

thanks! I got confused with the slashes...