I am trying to display a local html file with JS and CSS and PNG images referenced by it. I put the files into my assets folder of a NativeScript x Angular app for Android. When I run tns run android --bundle and the app gets built - the assets folder does not include the html. Folder structure goes from assets > index.html (and index.html references the other files).
Is there a certain place or way I need to include html files so they get included in the build?
You must update CopyWebpackPlugin in your webpack.config.js to include the asset folder
// Copy assets to out dir. Add your own globs as needed.
new CopyWebpackPlugin([
{ from: "fonts/**" },
{ from: "**/*.jpg" },
{ from: "**/*.png" },
{ from: "assets/**" }, // Add your asset folder path like this
], { ignore: [`${relative(appPath, appResourcesFullPath)}/**`] }),
Related
I followed this guide Integrate asset delivery (Kotlin & Java) from step 1-8, to integrate install-time asset delivery. I added folders with drawables to my \asset_pack1\src\main\assets folder, but i can't access them with code or open the folder in android studio. When i build my bundle with gradle, the manifest appers in asset_pack1\build\intermediates\asset_pack_manifest, but the drawable folders don't.
it doesn't show the content of asset_pack1
I've create the build.gradle in my asset_pack1 folder:
plugins {
id 'com.android.asset-pack'
}
assetPack {
packName = "asset_pack1"
dynamicDelivery {
deliveryType = "install-time"
}
}
Setuo the asset pack in my app build.gradle:
android {
..
assetPacks = [":asset_pack1"]
..
}
Included the pack in my settings.gradle:
include ':app'
include ':asset_pack1'
Added my asset directories:
Content of \asset_pack1\src\main\assets
And built the bundle with gradle:
over the menu
Also tried it over the terminal with: ./gradlew bundle
Does anyone know what i did wrong?
I followed the guide multiple times but always with the same result. Could't find any thread describing the same problem.
I am using a react-native project in which,I want to copy the contents of a certain folder in assets inside android to RNFS.DocumentDirectoryPath. How can this be performed?
I have used the attribute copyFileAssets().
copyfile() {
RNFS.copyFileAssets('/ICF-Package', RNFS.DocumentDirectoryPath + '/ICFPackage').then((result) => console.log('DONE')).catch((error) => console.log(error, 'ERROR'));
};
I'm getting the following error:
Error: Asset '/ICF-Package' could not be opened
Your code is correct. However, it looks like /ICF-Package is a folder or something, but not a file. copyFileAssets can only copy files, but no folders (and its content)
I'm trying to build an application on Sencha Touch for android, so I use Cordova to put it on my device.
The problem I'm facing is that everything works fine on my computer, but on android, the device can not find and read the locales files for each stores (I've already test on other Android device).
Here is the error on logcat:
E/AndroidProtocolHandler: Unable to open asset URL: file:///android_asset/www/app/store/recipes/list.json?_dc=1481398604306&node=ext-data-treestore-1-root&page=1&start=0&limit=25
E/AndroidProtocolHandler: Unable to open asset URL: file:///android_asset/www/app/store/recipes/pates.json
And here is the store that I use to read "pates.json":
var ingredientsData = Ext.create('Ext.data.Store', {
model: 'fr.ESIR.GreenVentory.model.IngredientListModel',
autoLoad: true,
proxy: {
type: 'ajax',
noCache: false,
enablePagingParams: false,
limitParam: null,
url: "./app/store/recipes/pates.json",
reader: {
rootProperty: 'ingredients',
totalProperty: 'totalCount'
}
}
});
And the files that I try to load are locally stored in "app/store/recipes/"
If someone have a solution, it would be cool for me to know it
I resolve my own problem:
All the data was stored on app/store of the sencha application, and when I build the Android application with Cordova, it doesn't take the json file because I haven't specify the file location.
So I create a data folder on the project root, put my json file and the folders that contain them on the data folder.
Don't forget to update the differents references of your json files
After that, it still working on the web version, but not on Android, because cordova don't integrate your files. Cordova reads the app.json file that you have on the root of your project. Go to the "resources" section of the file. Normally you have something like this:
/**
* Extra resources to be copied along when build
*/
"resources": [
"resources/images",
"resources/icons",
"resources/startup",
"data/*",
"data/recipes"
]
Just add the location of the folder that contains your file and cordova should integrate them when it compiles
I'm trying to unzip files from www folder to external location using zip plugin.
I assign external data directory to a variable folder when application start.
window.resolveLocalFileSystemURL(cordova.file.externalDataDirectory, function (folder) {
$filex.folder= folder;
});
then i call dataUnzip.
dataUnzip:function(){
var wwwPath = window.location.pathname;
var basePath = 'file://'+ wwwPath.substring(0,wwwPath.length-10);
window.resolveLocalFileSystemURL(basePath+'ex.zip',
function(fileDB){
alert('success! database was found')
unzipFiles(fileDB);
},
function(){
alert('failure! database was not found')
});
function unzipFiles(fileDB){
zip.unzip(fileDB,$filex.folder.nativeURL + "",
function (a) {
alert('Zip decompressed successfully' + a);
}
);
}
}
but i always get output as Zip decompressed successfully -1.-1 means unzip has failed.it works if i unzip .zip from external location like externalDataDirectory .but i want to unzip a file exist in www directory.
is there any way to get descriptive error ?instead of -1.and what could be the reason for unzip failure ?
here is a screenshot of www folder
Read here for documentation about file permissions etc
External Data Directory is not available on all platforms, what platform are you testing on?
Can you not just store the files unzipped in your application directory?
Otherwise, you may need to use different locations for each platform and use the merges folder.
When compiling a cordova application every single file in my /www folder gets copied to the assets/www folder(android) but I'd like to customize what files are copied. I use several pseudo languages like CoffeeScript, Jade or Stylus which are auto-compiled by my IDE and they shouldn't be shipped into the final application.
With the help of this article, I found that you can create/edit the platform/android/ant.properties, and add the following line to it:
aapt.ignore.assets=!*.map:!thumbs.db:!.git:.*:*~
With this line, any file or directory that matches one of these patterns will not be included in the .apk file:
*.map
thumbs.db
.git
.*
*~
I found that editing the platforms/android/build.xml won't work because it's overwritten each time the build is invoked; also, creating a build.xml file in the root of the project didn't work.
The rules for this property are the following, taken from $ANDROID_HOME/tools/ant/build.xml:
<!-- 'aapt.ignore.assets' is the list of file patterns to ignore under /res and /assets.
Default is "!.svn:!.git:.*:<dir>_*:!CVS:!thumbs.db:!picasa.ini:!*.scc:*~"
Overall patterns syntax is:
[!][<dir>|<file>][*suffix-match|prefix-match*|full-match]:more:patterns...
- The first character flag ! avoids printing a warning.
- Pattern can have the flag "<dir>" to match only directories
or "<file>" to match only files. Default is to match both.
- Match is not case-sensitive.
-->
<property name="aapt.ignore.assets" value="" />
Hidden (.*) folder & files will be ignored by default
All hidden files and folders will be ignored while build for example .git/ & .gitignore
To hide : Rename the folder by a . (dot) prepended to the folder/file name.
Use Terminal in Linux/Mac to rename the folder.
mv dev .dev
Use cmd in Windows
ren dev .dev
I do not know any way how to filter files for cordova, but I can describe you approach that we use in our projects.
We are using gruntjs with phonegap plugin. We configure it to use prebuilt folder (which contains only necessary files and folders) and it:
creates cordova/phonegap project
adds plugins,platforms
builds native applicaiton
launches native application on emulator
Main thing in this approach is that cordova/phonegap project (directory with .cordova, platforms and www folders) is just a build artefact.
Here is relevant part of our Gruntfile.js as an example:
phonegap : {
config : {
root : './out/dist',
config : {
template : './config.tpl.xml',
data: {
id: pkg.id,
version: pkg.version,
name: pkg.name,
author : pkg.author
}
},
path : 'out/phonegap',
plugins : [
// PHONEGAP OFFICIAL PLUGINS
'org.apache.cordova.globalization',
'org.apache.cordova.network-information',
'org.apache.cordova.splashscreen',
//THIRD-PARTY PLUGINS
'de.appplant.cordova.plugin.local-notification'
],
platforms : [
'android'
],
maxBuffer : 200, // You may need to raise this for iOS.
verbose : false,
releases : 'out/releases',
releaseName : function() {
return pkg.name + '-v' + pkg.version;
},
// Android-only integer version to increase with each release.
// See http://developer.android.com/tools/publishing/versioning.html
versionCode : function() {
return 1;
}
}
}
Note, out/dist is generated by previous build step and contains concatenated and minified version of code.
I've created a custom script to ignore files/folders which works not just for android:
Add this to your config.xml:
<ignore entries="lang,foo/bar,ignore/asdf.html" />
And you need two more files located in hooks/before_build and hooks/after_build folders.
I highly recommend cordova-plugin-exclude-files. You simply specify files to exclude as pattern attributes of exclude-files tags in your config.xml file.
For example, to exclude all .scss files:
<exclude-files pattern="**/*.scss" />
And to exclude all files with the string "ios-only" on the Android platform only:
<platform name="android">
<exclude-files pattern="ios-only" /> </platform>
This is what I'm doing. I've moved the src files for the app that was in www folder to another folder created in root - web-app. Next, the following script was added in package.json :
This surely needs to be refined, but am working with it as makeshift arrangement.
Good Luck...