I had searched to create the assets folder in an android app, the solution which i had tried is <App Name>/src/assets/fonts/
but when i try to use a ttf file in my Application, i have an error :
the code :
mFace = Typeface.createFromAsset(mContext.getAssets(),"fonts/fontType.ttf");
and the error :
native typeface cannot be made
I don't know if the assets folder is in the good place.
The problem is at the path of asset
<App Name>/src/assets/fonts/
should be
<App Name>/assets/fonts/
Read more at Directory Structure of an Android Project
Android project directory structure is as below
In Android Studio, I tried the root "app" folder, and that didn't work. I looked for the AndroidManifest.xml file and put the assets folder there. That worked for me.
For me it ended up being app\src\main\assets
ProjectName/assets/fonts
Not in under the src.
The assets folder is an independent folder.
While creating an Android project itself the Assets folder is independent to the src folder. Not inside the src folder.
Confirm that assets folder was created in the following way /assets.
Later create a fonts folder inside the assets folder and place fonts file inside the fonts : /assets/fonts
Related
I need to add some files to my android/assets folder of my project however, it isn't there ? I may have accidentally deleted it without knowing.
how do I create the assets folder?
Android studio doest provide ASSETS folder by default
you have to create it from
For the Android plugin, extra files and folders specific to Android:
AndroidManifest.xml
res/
assets/
aidl/
rs/
jni/
jniLibs/
Please read where to place asset folder
I have created 2 directories in the assets folder.
One is android and second is window.
--assets
1:- android
2:- window
I have a few files inside in the android folder. I need to copy all of them from the android folder to the window folder at runtime. How do I do it?
You can't. The assets folder is read-only and cannot be modified after compilation.
You can copy your files into a similar structure on the internal storage if you wish to do so.
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'm trying to copy and paste a whole bunch of files/folders into my Assets folder (that I created in the Main folder by selecting New > Folder > Assets Folder). But I get this error:
Cannot create class-file
The file in question is GUIDemo.class but there are others like it, too. Any suggestions how I can copy and paste the assets files into my project?
Android Studio uses Gradle-based build system, you should
putting assets/ inside of the source sets (e.g., src/main/assets/)
or create a folder under res
Try right click your app -- New -- Folder-- Assets folder
Change Android tag to Project, right click src --- make module app
I have a True type Fonts file which contains fonts of Rockwell.I need to put it in assets folder in android studio.But i am not able to put it.Can anyone tell how to do this?
Just create assets directory under your main directory of your project (src/main/assets). copy and paste it in that folder and use it.
these links maybe useful for complete information : gradle based projects