I'm working on to make android application with react-native and expo.
I'm using library to render some 3d object.
.obj format file need to be in android/app/src/main/assets to use that library.
I can load pictures something like .jpg, .png but .obj.
I don't control the android folder with git because it creates too much different files every time. (git ignored)
expo-file-system library doesn't save the file in exact address that I want(android/app/src/main/assets).
If there is a any way to save file with that library, please tell me.
So I created assets folder after expo build android folder.
Then I put .obj file manually(copy and paste) with my self.
Do I have to create folder manually whenever expo builds android folder?
And even I put my file in assets folder, the file is not showing after eas build .....
Please help
Related
I am using the following code to load font in my libgdx project.
BitmapFont(Gdx.files.local("fonts/test.fnt"))
This is working fine when i launch using Desktop Launcher.
however when I launch using Android Launcher i get the following error.
com.badlogic.gdx.utils.GdxRuntimeException: File not found: fonts/test.fnt (Local)
I am not sure What am i doing wrong here. My Android project's assets for folder contains fonts folder and has the files test.fnt and test.png.
On Android, assets can only be accessed using the internal file system:
Gdx.files.internal("filename");
Are you using different assets folders for both desktop and android so that you have separate copies of your files? Or are you using the same assets folder for both desktop and android?
If your are using the same assets folder, then both desktop and android have to use the android assets folder. Android is finicky in this way. So you will have to set your desktop assets folder to point to the android assets folder, then anytime you add new assets you have to add them to the android folder.
This is how I initialize my fonts.
fontTexture = new Texture(Gdx.files.internal("assets/texture/font.tga"));
buttonFont = new BitmapFont(Gdx.files.internal("assets/texture/font.fnt"), new TextureRegion(fontTexture), true);
By using internal it searches your project for the folder containing the assets for me that folder is "assets" my project looks something like this:
Eventhough I clearly have my assets packed into my project, I will get the same error when I export my application just like this.
Now here's how to solve that issue. You need to open up your exported project with something like 7z or Winrar, and manually drop in the 'assets' folder. In your case "fonts". This should should fix it, atleast I always have to do that, it never packs the assets for me.
I am following a guide on creating a replica of Flappy Bird. - http://www.kilobolt.com/day-6-adding-graphics---welcome-to-the-necropolis.html
The step I am having trouble is loading the texture from the assets directory. There are the author's instructions on how to do this.
And the code that he uses to actually load the texture
texture = new Texture(Gdx.files.internal("data/texture.png"));
My file structure looks like this(I am using Android Studio 1.0 while the author is using eclipse)
I had to manually create the data directory inside the assets folder. However when I try to run the application, I get these exceptions
Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load file: data/texture.png
Caused by: com.badlogic.gdx.utils.GdxRuntimeException: File not found: data\texture.png (Internal)
Does anyone know what the issue is? The texture.png is clearly inside the data directory of assets. I also made sure to clean the project right after copying the .png file into the data directory as the author mentioned.(so resources can be properly loaded). Is the issue just that were using two different IDES, so that different method calls have to be made?
You are trying to run Desktop app. Since assets is located in android project you have to explicitly set working directory for Desktop project. Go to Edit Configurations..., choose desktop configuration and set Working directory to path to android assets folder. Something like:
I want to know what is the path for the assets folder. I'm using Irrlicht Engine for render the graphics, and as you can see in the following code, I add a Folder File Archive to use the assets in the folder MyGameAssets that is located in the sd card directory.
//Create the irrlichtDevice
device = irr::createDevice(irr::video::EDT_OGLES1,
irr::core::dimension2d<irr::u32>(screenWidth, screenHeight), 32,
false, false, false, 0);
//With this path my Game can use the assets in the folder that is on SD card
device->getFileSystem()->addFolderFileArchive("/sdcard/myGameAssetsFolder/");
Whith those lines of code my Android Game works fine, but as I said before, I don't want to use the sdcard/MyGameAssetsFolder/. I want to use the Assets Folder of the Android Project. What could be the possible path? Is there any other solution in order to not to use the sdcard path?
I'm guessing you're following "Android NDK Beginner's Guide" Book tutorial. I am too! and I'm having the same issue you are having.
Seems there's no way pure Native C++ can access the asset folder inside the apk. You have to make your app JNI so with Java you can pass the asset folder path to C++.
But, it seems there's also a way to use the AAssetManager inside android native glue library but I don't know how because there is no documentation about, not even inside the docs folder inside NDK folder.
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
I am trying to invoke opencv library from my android code.
I previously stored my haar xml under the /data/data/org.siprop.opencv/files/ directory and passed this file path (i.e. /data/data/org.siprop.opencv/files/haarcascade_frontalface_alt.xml) to the opencv library. This xml was successfully read by the opencv code.
But I noticed that these xml files were not packaged in the .apk file which meant I would have a problem when distributing the same.
I hence tried storing these haar xmls in the assets/files folder. Now the files were included in the .apk file but i could not locate this in the emulator via the DDMS file explorer. So not sure what file path can I pass back to the opencv library.
Can you please let me know where am i going wrong?