If I have a .txt file in a project folder of an Android project and I build this project as .apk. This file is accessible for the user from the Device Explorer or in hidden into the .apk?
(I apologize for my english)
You can also access the streamingAssetsPath (read only):
https://docs.unity3d.com/ScriptReference/Application-streamingAssetsPath.html
and the persistentDataPath (this is a folder where you can read/write data, accessible to your users... but you can access this folder only after the installation):
https://docs.unity3d.com/ScriptReference/Application-persistentDataPath.html
To read files in the streamingAssets on Android you need to use WWW class but everything is explained in the docs (with an example).
Read this to understand if you really need to use Resources folder or it's better to use streamingAssetsPath:
https://unity3d.com/learn/tutorials/topics/best-practices/resources-folder
if you want to undestand the difference I suggest to read this:
https://forum.unity.com/threads/resources-vs-streamingassets-for-mobile.494804/
Unity will produce a .apk-file.
Your .txt-file will be baked in if:
Its referenced by something in the scene
Its in the Resources folder
Related
I was asked this recently, and searched a broad range of sites, but none were useful to provide a direct answer to this issue.
I want to deploy a file alongside my app directly into the shared folders, specifically the documents folder /storage/emulated/0/Documents.
In order to deploy a file inside my app's private directory, we use .\assets\internal to provide the file that we will use, and inside the app we use TPath.GetDocumentsPath to read this file inside the internal folder of our app's private folder.
But how can I deploy a file alongside my app that, from Delphi, I would read from TPath.GetSharedDocumentsPath? What is the path that I have to set in the "Project > Deployment" tab for that file?
I am trying to link to an external file from a shared repository between my iOS and Android apps. This does not present a problem for iOS, but it does for Android. My current solution is to create a copy of the file from the external repository and place it in my projects Assets folder. This solution works, but is not much of a good one in my opinion and involves too many extra steps.
Using Eclipse, I am able to link to a resource. It's as simple as copying a file into my Assets folder and being prompted to either copy the file or link to the resource. If I link to the resource and try to run my app, I get a FileNotFoundException. If I copy the file instead, the app file is found just fine.
Ideally, I'd like to link to the file so that when I pull a new update from git then I don't need to copy the file over every single time. I'd prefer to link to the file.
I don't know what Eclipse uses "under the covers" for "Link here" drag-and-drop stuff. However, it is an Eclipse-ism. Android's build tools are fairly isolated from Eclipse proper, and so they won't know about those links.
Using a hardlink, or perhaps a symlink, at the OS X filesystem level should work, as both Eclipse and Android's build tools should treat it like a local file.
I have some files that I want to read from my app.Currently, I have to do the following:
Check if the file exists in the files directory.
If it doesnt, then copy the files from assets to the files directory
If it does, then, skip step 2
So, is it possible to not copy the files ? This increases the size of my app (uselessly) as there is an extra copy of all the files.
Note, that I have to access the file using getfiles(). I am using a library that doesnt work if I give the uri of my assets folder.
So, it it somehow possible to compile the app with some files already in the files directory ?
Internal storage for you app is created when application is installed so there is no way to provide files there during compile time, that would be magic.
You could try creating ContentProvider for sharing your files stored inside assets folder.
Besides, you should tell which library you are using. Then I may be able to suggest something more precise.
I think I may know the answer to this question already, but I just wanna be 100% sure. Anyways, I am writing an Android app using Eclipse 4.2 ("Juno"). I want to create my SQLite database by using external files and reading/parsing these files by my code. Hence, I created my own directory called /database and placed it in my project's root directory. Then, Eclipse starts complaining, reports a problem and says:
Invalid recourse directory name.
I even tried placing my database directory in the existing /res directory, but that caused the same Eclipse problem. Just want to confirm what my initial thoughts are: Is it not allowed for me to define my own directories in the project and bundle it in with my release?
If so, then I guess I'll have to follow along with what was posted in this stackoverflow question.
put it in /assets not in /res and it should work.
You should be able to create arbitrary directories in the root of your Android project, however your application won't be able to access these files. This is useful for development purposes like storing test data, documentation, or jar files. However, you cannot create non-standard directories in places like gen and res.
In a class belonging to a Library project I call:
webview.loadUrl("file:///android_asset/info.html", null);
Unfortunately, this only works if I duplicate the file info.html into the Application's project asset folder as well.
Is there a way to tell an Android library code: "look for this file in the library's assets folder, not in the application's assets folder" ?
This answer is out of date, the gradle build system and AAR files support assets.
From the Android Docs:
Library projects cannot include raw assets
The tools do not support the use of raw asset files (saved in the assets/ directory) in a library project. Any asset resources used by an application must be stored in the assets/ directory of the application project itself. However, resource files saved in the res/ directory are supported.
If you want to include files from a Library project, you'll need to put it in the resources instead of the assets. If you're trying to load HTML files from your library project into a WebView, this means that you'll have to go a more roundabout method than the usual asset URL. Instead you'll have to read the resource data and use something like loadData.
This is now possible using the Gradle build system.
Testing with Android Studio 0.5.0 and v0.9 of the Android Gradle plugin, I've found that files such as
MyLibProject/src/main/assets/test.html
are correctly packaged in the final application and can be accessed at runtime via the expected URL:
file:///android_asset/test.html
You can achieve this by creating a symbolic link in the project's asset folder that points to the directory in the library project.
Then you can access as below:
webview.loadUrl("file:///android_asset/folder_in_a_libary_project/info.html", null);
Okay. Ive been stressing out and losing sleep about this for a while. Im the type of person that loves API creation, and HATES complicated integration.
There arent many solutions around on the internet, so im quite proud of what Ive discovered with a bit of Eclipse Hackery.
It turns out that when you put a file in the Android Lib's /assets folder. The target apk will capture this and place it on the root of the APK archive. Thus, making general access fail.
This can be resolved by simply creating a Raw Java Library, and placing all assets in there, ie (JAVALIB)/assets/fileX.txt.
You can in turn then include this as a Java Build Path Folder Source in
Project > Properties > Java Build Path > Source > Link Source.
Link Source
Click on Variables. and Add New Variable, ie VAR_NAME_X. location : ../../(relative_path_to_assets_project)
Click Ok
Now, when you build and run your app, the assets folder in the APK will contain your (GLOBAL Library) files as you intended.
No need to reconfigure android internals or nothing. Its all capable within a few clicks of Eclipse.
I confirm that Daniel Grant's approach works for at least the following situation: target project does NOT have an asset folder (or the folder is empty, so you can safely delete it).
I did not setup any variable.
Simply setup a LinkSource as follows (just an example)
Linked folder location: /home/matthew/workspace_moonblink/assetsForAdvocacy/assets
Folder name : assets
The "assetsForAdvocacy" is a Java project, (created with New- Project - Java Project) with empty src folder, and a new folder named "assets", which now provides the entire assets folder for the target project.
This is a fairly straightforward way within Eclipse to provide assets re-use across many different projects IF they do not already have assets, good enough to get going with. I would probably want to enhance it to become a content provider in the long run, but that is a lot more development.
My project accesses the assets with the following code:
String advocacyFolderInAssets = "no_smoking/"; //a folder underneath assets/
String fn =advocacyFolderInAssets+imageFilename;
Bitmap pristineBitmapForAdvocacy = getBitmapFromAsset(context, fn);
I use Motodev Studio 3.1.0 on Ubuntu. It would not let me 'merge' a new assets folder in the new assets-only project onto an existing assets folder in the target project.
If you want to use a setup where multiple derivate products are created from one library you might consider using svn:externals or similar solution in your SCM system. This will also do the trick that static assets like online help may be versioned seperately from the android source code.
I found this older question, it might help you, too.
This is the official way Google uses to archive this (from the above post): Link