概述
SonyEricsson模拟器机型覆盖面甚广,运行速度也很好,最好的还是因为它支持NokiaUI。但使用SonyEricsson模拟器调试Java应用程序的时候经常遇到一些问题。本篇文章将列举一些常见问题的处理方法。
[本文针对SonyEricsson模拟器版本2.2.3 with Add On Pack2]
JBuilder打包中RetroGuard混淆问题
问题描述
在开发J2ME游戏时使用了NokiaUI的类库,同时需要使用JBuilder打JAR包,然后使用JBuilder自带的RetroGuard混淆。但添加了默认的SE模拟器SDK设置后,在混淆过程中会出现“ClassNotFound”的问题,因为RetroGuard找不到com.nokia.mid.ui.FullCanvas的类,而无法继续混淆。希望能够解决不能混淆的问题。
解决方案
将X:/SonyEricsson/J2ME_SDK/PC_Emulation/WTK2/lib/nokiaext.jar中的com包打包到X:/SonyEricsson/J2ME_SDK/PC_Emulation/WTK2/wtklib/emptyapi.jar中即可。
原因分析
归根结底,找不到类还是因为在Java运行期间的classpath没有包含所需要的类,查看一下运行RetroGuard期间的classpath输出如下:
"D:/java/Borland/JBuilder2005/jdk1.4/bin/javaw" -classpath "D:/java/Borland/JBuilder2005/thirdparty/retroguard-v1.1/retroguard.jar;D:/java/Borland/JBuilder2005/j2mewtk2.1/wtklib/emptyapi.zip;;d:/SonyEricsson/J2ME_SDK/PC_Emulation/WTK2/wtklib/emptyapi.zip;" RetroGuard "<BaseDir>/<MidletName>.jar" "<BaseDir>/obfuscate-temp/<MidletName>.jar" "<BaseDir>/obfuscate-temp/<MidletName>.rgs" "<BaseDir>/Log.txt"
主要观察“classpath”部分,包含了SonyEricsson的SDK中的“emptyapi.jar”,问题很显然是因为“emptyapi.jar”中并未包含NokiaUI,所以RetroGuard自然不会发现FullCanvas。所以我们把com.nokia包从“/lib/nokiaext.jar”中打包到“emptyapi.jar”即可。
补充说明:
“emptyapi.jar”作用:提供一些空的class,只含有接口信息,并不参与执行。
“nokiaext.jar”作用:提供了NokiaUI的class。
今后,如果在使用Java应用程序的时候出现此类问题,只要把握classpath的原则即可找到问题所在。
模拟器正确显示中文的问题
问题描述
直接启动SonyEricsson的某些模拟器时(如K700)绘制的中文都大多数会显示成小方块,某些中文字符可以显示。希望解决不正常显示中文的问题。
[本问题说明以K700为例]
解决方案
打开X:/SonyEricsson/J2ME_SDK/PC_Emulation/WTK2/wtklib/devices/SonyEricsson_K700/SonyEricsson_K700.properties文件可以看到如下一部分字体定义的参数:
font.default = ../fonts/font0020.properties
font.default.semc = true
font.default.underline.enabled = true
font.default.underline.width = 1
font.default.underline.offset = 2
font.softButton = ../fonts/font0035.properties
font.softButton.semc = true
font.softButton.underline.enabled = true
font.softButton.underline.width = 1
font.softButton.underline.offset = 2
font.system.plain.medium = ../fonts/font0020.properties
font.system.plain.medium.semc = true
font.system.plain.medium.underline.enabled = true
font.system.plain.medium.underline.width = 1
font.system.plain.medium.underline.offset = 2
font.system.plain.small = ../fonts/font0037.properties
font.system.plain.small.semc = true
font.system.plain.small.underline.enabled = true
font.system.plain.small.underline.width = 1
font.system.plain.small.underline.offset = 2
font.system.plain.large = ../fonts/font0027.properties
font.system.plain.large.semc = true
font.system.plain.large.underline.enabled = true
font.system.plain.large.underline.width = 1
font.system.plain.large.underline.offset = 2
font.system.bold.medium = ../fonts/font0035.properties
font.system.bold.medium.semc = true
font.system.bold.medium.underline.enabled = true
font.system.bold.medium.underline.width = 1
font.system.bold.medium.underline.offset = 2
font.system.bold.small = ../fonts/font0034.properties
font.system.bold.small.semc = true
font.system.bold.small.underline.enabled = true
font.system.bold.small.underline.width = 1
font.system.bold.small.underline.offset = 2
font.system.bold.large = ../fonts/font0036.properties
font.system.bold.large.semc = true
font.system.bold.large.underline.enabled = true
font.system.bold.large.underline.width = 1
font.system.bold.large.underline.offset = 2
font.system.italic.medium = ../fonts/font0006.properties
font.system.italic.medium.semc = true
font.system.italic.medium.underline.enabled = true
font.system.italic.medium.underline.width = 1
font.system.italic.medium.underline.offset = 2
font.system.italic.small = ../fonts/font0005.properties
font.system.italic.small.semc = true
font.system.italic.small.underline.enabled = true
font.system.italic.small.underline.width = 1
font.system.italic.small.underline.offset = 2
font.system.italic.large = ../fonts/font0010.properties
font.system.italic.large.semc = true
font.system.italic.large.underline.enabled = true
font.system.italic.large.underline.width = 1
font.system.italic.large.underline.offset = 2
font.system.bold.italic.medium = ../fonts/font0004.properties
font.system.bold.italic.medium.semc = true
font.system.bold.italic.medium.underline.enabled = true
font.system.bold.italic.medium.underline.width = 1
font.system.bold.italic.medium.underline.offset = 2
font.system.bold.italic.small = ../fonts/font0002.properties
font.system.bold.italic.small.semc = true
font.system.bold.italic.small.underline.enabled = true
font.system.bold.italic.small.underline.width = 1
font.system.bold.italic.small.underline.offset = 2
font.system.bold.italic.large = ../fonts/font0001.properties
font.system.bold.italic.large.semc = true
font.system.bold.italic.large.underline.enabled = true
font.system.bold.italic.large.underline.width = 1
font.system.bold.italic.large.underline.offset = 2
font.monospace.plain.medium = ../fonts/font0020.properties
font.monospace.plain.medium.semc = true
font.monospace.plain.medium.underline.enabled = true
font.monospace.plain.medium.underline.width = 1
font.monospace.plain.medium.underline.offset = 2
font.monospace.plain.small = ../fonts/font0037.properties
font.monospace.plain.small.semc = true
font.monospace.plain.small.underline.enabled = true
font.monospace.plain.small.underline.width = 1
font.monospace.plain.small.underline.offset = 2
font.monospace.plain.large = ../fonts/font0027.properties
font.monospace.plain.large.semc = true
font.monospace.plain.large.underline.enabled = true
font.monospace.plain.large.underline.width = 1
font.monospace.plain.large.underline.offset = 2
font.monospace.bold.medium = ../fonts/font0035.properties
font.monospace.bold.medium.semc = true
font.monospace.bold.medium.underline.enabled = true
font.monospace.bold.medium.underline.width = 1
font.monospace.bold.medium.underline.offset = 2
font.monospace.bold.small = ../fonts/font0034.properties
font.monospace.bold.small.semc = true
font.monospace.bold.small.underline.enabled = true
font.monospace.bold.small.underline.width = 1
font.monospace.bold.small.underline.offset = 2
font.monospace.bold.large = ../fonts/font0036.properties
font.monospace.bold.large.semc = true
font.monospace.bold.large.underline.enabled = true
font.monospace.bold.large.underline.width = 1
font.monospace.bold.large.underline.offset = 2
font.monospace.italic.medium = ../fonts/font0006.properties
font.monospace.italic.medium.semc = true
font.monospace.italic.medium.underline.enabled = true
font.monospace.italic.medium.underline.width = 1
font.monospace.italic.medium.underline.offset = 2
font.monospace.italic.small = ../fonts/font0005.properties
font.monospace.italic.small.semc = true
font.monospace.italic.small.underline.enabled = true
font.monospace.italic.small.underline.width = 1
font.monospace.italic.small.underline.offset = 2
font.monospace.italic.large = ../fonts/font0010.properties
font.monospace.italic.large.semc = true
font.monospace.italic.large.underline.enabled = true
font.monospace.italic.large.underline.width = 1
font.monospace.italic.large.underline.offset = 2
font.monospace.bold.italic.medium = ../fonts/font0004.properties
font.monospace.bold.italic.medium.semc = true
font.monospace.bold.italic.medium.underline.enabled = true
font.monospace.bold.italic.medium.underline.width = 1
font.monospace.bold.italic.medium.underline.offset = 2
font.monospace.bold.italic.small = ../fonts/font0002.properties
font.monospace.bold.italic.small.semc = true
font.monospace.bold.italic.small.underline.enabled = true
font.monospace.bold.italic.small.underline.width = 1
font.monospace.bold.italic.small.underline.offset = 2
font.monospace.bold.italic.large = ../fonts/font0001.properties
font.monospace.bold.italic.large.semc = true
font.monospace.bold.italic.large.underline.enabled = true
font.monospace.bold.italic.large.underline.width = 1
font.monospace.bold.italic.large.underline.offset = 2
font.proportional.plain.medium = ../fonts/font0020.properties
font.proportional.plain.medium.semc = true
font.proportional.plain.medium.underline.enabled = true
font.proportional.plain.medium.underline.width = 1
font.proportional.plain.medium.underline.offset = 2
font.proportional.plain.small = ../fonts/font0037.properties
font.proportional.plain.small.semc = true
font.proportional.plain.small.underline.enabled = true
font.proportional.plain.small.underline.width = 1
font.proportional.plain.small.underline.offset = 2
font.proportional.plain.large = ../fonts/font0027.properties
font.proportional.plain.large.semc = true
font.proportional.plain.large.underline.enabled = true
font.proportional.plain.large.underline.width = 1
font.proportional.plain.large.underline.offset = 2
font.proportional.bold.medium = ../fonts/font0035.properties
font.proportional.bold.medium.semc = true
font.proportional.bold.medium.underline.enabled = true
font.proportional.bold.medium.underline.width = 1
font.proportional.bold.medium.underline.offset = 2
font.proportional.bold.small = ../fonts/font0034.properties
font.proportional.bold.small.semc = true
font.proportional.bold.small.underline.enabled = true
font.proportional.bold.small.underline.width = 1
font.proportional.bold.small.underline.offset = 2
font.proportional.bold.large = ../fonts/font0036.properties
font.proportional.bold.large.semc = true
font.proportional.bold.large.underline.enabled = true
font.proportional.bold.large.underline.width = 1
font.proportional.bold.large.underline.offset = 2
font.proportional.italic.medium = ../fonts/font0006.properties
font.proportional.italic.medium.semc = true
font.proportional.italic.medium.underline.enabled = true
font.proportional.italic.medium.underline.width = 1
font.proportional.italic.medium.underline.offset = 2
font.proportional.italic.small = ../fonts/font0005.properties
font.proportional.italic.small.semc = true
font.proportional.italic.small.underline.enabled = true
font.proportional.italic.small.underline.width = 1
font.proportional.italic.small.underline.offset = 2
font.proportional.italic.large = ../fonts/font0010.properties
font.proportional.italic.large.semc = true
font.proportional.italic.large.underline.enabled = true
font.proportional.italic.large.underline.width = 1
font.proportional.italic.large.underline.offset = 2
font.proportional.bold.italic.medium = ../fonts/font0004.properties
font.proportional.bold.italic.medium.semc = true
font.proportional.bold.italic.medium.underline.enabled = true
font.proportional.bold.italic.medium.underline.width = 1
font.proportional.bold.italic.medium.underline.offset = 2
font.proportional.bold.italic.small = ../fonts/font0002.properties
font.proportional.bold.italic.small.semc = true
font.proportional.bold.italic.small.underline.enabled = true
font.proportional.bold.italic.small.underline.width = 1
font.proportional.bold.italic.small.underline.offset = 2
font.proportional.bold.italic.large = ../fonts/font0001.properties
font.proportional.bold.italic.large.semc = true
font.proportional.bold.italic.large.underline.enabled = true
font.proportional.bold.italic.large.underline.width = 1
font.proportional.bold.italic.large.underline.offset = 2
可以将它们删除,替换成以下文本:
(友情提示,备份好原来的文件^_^)
font.default=SansSerif-plain-10
font.softButton=SansSerif-plain-11
font.system.plain.small: SansSerif-plain-9
font.system.plain.medium: SansSerif-plain-11
font.system.plain.large: SansSerif-plain-14
font.system.bold.small: SansSerif-bold-9
font.system.bold.medium: SansSerif-bold-11
font.system.bold.large: SansSerif-bold-14
font.system.italic.small: SansSerif-italic-9
font.system.italic.medium: SansSerif-italic-11
font.system.italic.large: SansSerif-italic-14
font.system.bold.italic.small: SansSerif-bolditalic-9
font.system.bold.italic.medium: SansSerif-bolditalic-11
font.system.bold.italic.large: SansSerif-bolditalic-14
font.monospace.plain.small: Monospaced-plain-9
font.monospace.plain.medium: Monospaced-plain-11
font.monospace.plain.large: Monospaced-plain-14
font.monospace.bold.small: Monospaced-bold-9
font.monospace.bold.medium: Monospaced-bold-11
font.monospace.bold.large: Monospaced-bold-14
font.monospace.italic.small: Monospaced-italic-9
font.monospace.italic.medium: Monospaced-italic-11
font.monospace.italic.large: Monospaced-italic-14
font.monospace.bold.italic.small: Monospaced-bolditalic-9
font.monospace.bold.italic.medium: Monospaced-bolditalic-11
font.monospace.bold.italic.large: Monospaced-bolditalic-14
font.proportional.plain.small: SansSerif-plain-9
font.proportional.plain.medium: SansSerif-plain-11
font.proportional.plain.large: SansSerif-plain-14
font.proportional.bold.small: SansSerif-bold-9
font.proportional.bold.medium: SansSerif-bold-11
font.proportional.bold.large: SansSerif-bold-14
font.proportional.italic.small: SansSerif-italic-9
font.proportional.italic.medium: SansSerif-italic-11
font.proportional.italic.large: SansSerif-italic-14
font.proportional.bold.italic.small: SansSerif-bolditalic-9
font.proportional.bold.italic.medium: SansSerif-bolditalic-11
font.proportional.bold.italic.large: SansSerif-bolditalic-14
如此便可以正确显示简体中文了
原因分析
SE的模拟器采用了配置文件的形式来指导模拟器的运行,而K700原有的配置文件作指向的字体路径是不完整的bitmap形式的字库,所以才会显示成小方块。而在我一次无意中使用P900模拟器的时候发现所有中文都能正常显示。查看了P900的配置文件发现它的字体定义是解决方案中给出的形式。将P900的字体参数覆盖到K700的字体参数中,惊喜地发现K700也可以正确显示中文了。所以,按照解决方案中给出的形式覆盖掉原来的字体定义参数即可。