Title: Adding file to Android build at app/src/main/assets for `getAssets()` · Issue #700 · NativeScript/android · GitHub
Open Graph Title: Adding file to Android build at app/src/main/assets for `getAssets()` · Issue #700 · NativeScript/android
X Title: Adding file to Android build at app/src/main/assets for `getAssets()` · Issue #700 · NativeScript/android
Description: @bradmartin commented on Thu Feb 02 2017 Please, provide the details below: Trying to build a plugin which is calling the following code: public static Cancellable fromAssetFileName(Context context, String fileName, OnCompositionLoadedLi...
Open Graph Description: @bradmartin commented on Thu Feb 02 2017 Please, provide the details below: Trying to build a plugin which is calling the following code: public static Cancellable fromAssetFileName(Context context...
X Description: @bradmartin commented on Thu Feb 02 2017 Please, provide the details below: Trying to build a plugin which is calling the following code: public static Cancellable fromAssetFileName(Context context...
Opengraph URL: https://github.com/NativeScript/android/issues/700
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Adding file to Android build at app/src/main/assets for `getAssets()`","articleBody":"@bradmartin commented on [Thu Feb 02 2017](https://github.com/NativeScript/NativeScript/issues/3560)\r\n\r\n## Please, provide the details below:\r\n\r\nTrying to build a plugin which is calling the following code:\r\n\r\n```\r\n public static Cancellable fromAssetFileName(Context context, String fileName, OnCompositionLoadedListener loadedListener) {\r\n InputStream stream;\r\n try {\r\n stream = context.getAssets().open(fileName);\r\n } catch (IOException e) {\r\n throw new IllegalStateException(\"Unable to find file \" + fileName, e);\r\n }\r\n return fromInputStream(context, stream, loadedListener);\r\n }\r\n```\r\n\r\nThe public method to get to that ^^^ is just accepting a string for the `fileName` argument. The README for the android lib says to put the file at `app/src/main/assets`. I've tried creating an `assets` folder in app_resources which obviously doesn't package up there. I've tried at the root of the `app` folder and no good. So is there some way to add files (this is a .json file) to that location for an android build with NS. The android code calling `getAssets()` returns the [AssetManager](https://developer.android.com/reference/android/content/res/AssetManager.html) and is calling `open()` with the given file name. So how do we get files to be accessible with this in a NS app is the question now that I think about it 😄 \r\n\r\n\r\n### Did you verify this is a real problem by searching [Stack Overflow](http://stackoverflow.com/questions/tagged/nativescript) and the [other open issues in this repo](https://github.com/NativeScript/nativescript/issues)?\r\n\r\nYes.\r\n\r\n### Which platform(s) does your issue occur on?\r\n\r\nAndroid\r\n\r\n### Please provide the following version numbers that your issue occurs with:\r\n\r\nNS 2.5 everything - just updated.\r\n\r\n### Please tell us how to recreate the issue in as much detail as possible.\r\n\r\nCreate an app, try to create an .apk with a file located in `app/src/main/assets` at the output I suppose.\r\n\r\n### Is there code involved? If so, please share the minimal amount of code needed to recreate the problem.\r\n\r\nNo, just wrapping a lib.\r\n\r\n\r\n\r\n---\r\n\r\n@bradmartin commented on [Thu Feb 02 2017](https://github.com/NativeScript/NativeScript/issues/3560#issuecomment-276881009)\r\n\r\nThere is another method to go about, but was hoping to access the simplest of them with just passing the file name 👍 \r\n\r\n---\r\n\r\n@bradmartin commented on [Thu Feb 02 2017](https://github.com/NativeScript/NativeScript/issues/3560#issuecomment-276883655)\r\n\r\nAnd opening up `platforms/android/src/main/assets` and placing the .json file isn't really a good solution for new NS devs or anyone since it'll be blasted during a build/platform clean. Doing this does work, so the native lib is expecting the file to be located in the `assets` folder.\r\n\r\n","author":{"url":"https://github.com/petekanev","@type":"Person","name":"petekanev"},"datePublished":"2017-02-02T08:34:58Z","url":"https://github.com/NativeScript/android/issues/700"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:38d0c72f-e99e-3744-8966-7519f278afe4 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9476:14700E:12D2AF9:17E5197:6B012017 |
| html-safe-nonce | b253d84ed19c6e0a3995eb201256c82890dfefcb60a030eee4e814225e9478cd |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NDc2OjE0NzAwRToxMkQyQUY5OjE3RTUxOTc6NkIwMTIwMTciLCJ2aXNpdG9yX2lkIjoiMjA3MTE3MDI5NzIxNzc1MzExMSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | debd72ea3b991e5332c059b37ac367fbd956e7d734be67da8bc1e379bd18d51c |
| hovercard-subject-tag | issue:204810956 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/NativeScript/android/700/issue_layout |
| twitter:image | https://opengraph.githubassets.com/6af320bca2e9ebe2ea375ec0797b2d7d1e3a139394809f6c965c5a40d03945e0/NativeScript/android/issues/700 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/6af320bca2e9ebe2ea375ec0797b2d7d1e3a139394809f6c965c5a40d03945e0/NativeScript/android/issues/700 |
| og:image:alt | @bradmartin commented on Thu Feb 02 2017 Please, provide the details below: Trying to build a plugin which is calling the following code: public static Cancellable fromAssetFileName(Context context... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | petekanev |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/NativeScript/android git https://github.com/NativeScript/android.git |
| octolytics-dimension-user_id | 7392261 |
| octolytics-dimension-user_login | NativeScript |
| octolytics-dimension-repository_id | 29137950 |
| octolytics-dimension-repository_nwo | NativeScript/android |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 29137950 |
| octolytics-dimension-repository_network_root_nwo | NativeScript/android |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width