Math

App Crashed when I add other file to assets.

I found a third-lib that can input latex and output customize bitmap image.
so I add the library to my project.it cantains some files in assets.
These files names contains: a folder named fonts the folder contains some ttf files and xml files,and some files DefaultTeXFont.xml,GlueSettings.xml,TeXFormulaSettings.xml,TexSymbols.xml
run my app.and it crashed.the traces is below(when run code: mMathWidget.configure(math,standard);
):
FATAL EXCEPTION: main
Process: com.tal.adaptive.student, PID: 14893
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.tal.adaptive.student/com.tal.adaptive.student.main.activity.AnswerActivity}: java.lang.RuntimeException: Font asset not found fonts/base
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2790)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2855)
at android.app.ActivityThread.access$900(ActivityThread.java:181)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1474)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6117)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
Caused by: java.lang.RuntimeException: Font asset not found fonts/base
at android.graphics.Typeface.createFromAsset(Typeface.java:272)
at com.myscript.atk.math.widget.utils.FontManager.initializeFromAssets(FontManager.java:110)
at com.myscript.atk.math.widget.MathWidget.configure(MathWidget.java:172)


1 person has this question

And when I delete files under assets. It works well.

Dear Shi Tijun,

Based on the error message, it seems Font asset is missing (Font asset not found fonts/base).

Can you please check the fonts needed by your library, and ensure these are properly added into your project?

Best regards,

Olivier

the folder fonts/base is in the folder assets.But I confuse is that the fonts/base is used in my 3th library.
but why the crash accured in MathWidget.configure function?

at com.myscript.atk.math.widget.utils.FontManager.initializeFromAssets(FontManager.java:110)
at com.myscript.atk.math.widget.MathWidget.configure(MathWidget.java:172)

I guess that the reason for crash is maybe in function MathWidget.configure(), it try to scan all the fonts file ttf? but 3th library put some ttf files in assets and contains additional folder and files ?eg. folder base folder eular these folders contains a lot of xmls files.

because when i remove 3th libaray .the function MathWidget.configure() works well...
So I guess may be there are conflicts between MathWidget and 3th library.

below is the code in FontManager.class function initializeFromAssets.
the error is below code. when run Typeface.createFromAsset funtion. it didn't check fontPath.
because 3th library add no ttf files in fonts folder.
so fonts/base is a folder,and run fontPath = fonts/base, MathWidget crashed. It is a bug...
String filename = arr$[i$];
String fontPath = fonts + File.separatorChar + filename;
Typeface typeface = Typeface.createFromAsset(context.getAssets(), fontPath);

public static void initializeFromAssets(@NonNull Context context) {
AssetManager assets = context.getResources().getAssets();

try {
String[] e = assets.list(fonts);
String[] arr$ = e;
int len$ = e.length;

for(int i$ = 0; i$ < len$; ++i$) {
String filename = arr$[i$];
String fontPath = fonts + File.separatorChar + filename;
Typeface typeface = Typeface.createFromAsset(context.getAssets(), fontPath);
if(typeface != null) {
String key = filename.substring(0, filename.indexOf(46));
addTypeface(key, typeface);
}
}
} catch (IOException var10) {
if(DBG) {
Log.d(FontManager, Fail to list fonts);
}
}

}

Dear Shi Tijun,

can you please proceed as follows:
-From the default sample, just add the fonts (not the library). Do not try to load the font.
-If Working, can you then please try the font?
-If working, can you then attach the library?
-If crashing, can you please try to duplicate the font, load one with the MathWidget and the other version with the Library?

Let us know if it fails.

Best regards,

Olivier

I try to add the fonts(only Suffix with .ttf) ,It works well.
But the library put folder and xml files into the path /assets/fonts. The MathWidget crash.
for example assets/fonts/base/.

So I am sure the it is a bug with the code below(int MathWidget):because It didn't check the fontPath. fontPath may not be a ttf file.

String filename = arr$[i$];
String fontPath = “fonts” + File.separatorChar + filename;
Typeface typeface = Typeface.createFromAsset(context.getAssets(), fontPath);

Or I can email the demo project to you ?
Olivier@MyScript.com

Dear Shi Tijun,

can you please provide us with a link where we can download your whole project.

I insist having the whole project, so that we can investigate faster.

Best regards,

Olivier

Hi
I have sent you the whole project.
Please check your mail. And wait for your answer.Thank you!

Dear Shi Tijun,

I tried several times to get your project, but download failed around mid-download.

Can you please try to put the zip file on another location, such as FTP server or Dropbox, or other solution...

Best regards,

Olivier

Dear Shi Tijun,

I could finnally download your project. I am trying to reproduce.

Best regards,

Olivier

OK。Here is another download url:
https://pan.baidu.com/s/1skLtjRZ

Dear Shi Tijun,

I am not a font experts, but it seems there are issues with some of the ones your are trying to include in your project. Indeed, it seems some of these are crashing the application, when your library is not attached.

The error message is native typeface cannot be made.

Such issue is usually related to fonts: http://stackoverflow.com/questions/7531856/issue-when-using-a-custom-font-native-typeface-cannot-be-made

In your project, I then just kept the fonts that by default you put at the root of the assets/fonts directory, and this error message no longer occurs.

=>I then recommend you only keep the fonts you will need, which will prevent from such issue.

Can you please try this, and see if it helps?

Best regards,

Olivier

Login or Signup to post a comment