Cordova编译Android 22 以上版本,中文目录出错问题的解决办法

如果用corodva编译工程,并且工程是中文名,在windows下会报错,类似如下贴子

http://www.lai18.com/content/1316143.html

找遍网络没发现处理方法,细看后解决,其实原理很简单,android的文件都按照utf-8处理,但windows下的java默认是gbk,强制指定一下字符集即可。


自己的错误:

2016-01-07 10:49:50 :preDexDebug
2016-01-07 10:49:51 
2016-01-07 10:49:51 UNEXPECTED TOP-LEVEL EXCEPTION:
2016-01-07 10:49:51 java.lang.RuntimeException: D:\Work\SVN\Native\鎴戠殑宸ョ▼\build\src\platforms\android\build\intermediates\classes\debug: file not found
2016-01-07 10:49:51 at com.android.dex.util.FileUtils.readFile(FileUtils.java:51)
2016-01-07 10:49:51 at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:169)
2016-01-07 10:49:51 at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
2016-01-07 10:49:51 at com.android.dx.command.dexer.Main.processOne(Main.java:672)
2016-01-07 10:49:51 at com.android.dx.command.dexer.Main.processAllFiles(Main.java:574)
2016-01-07 10:49:51 at com.android.dx.command.dexer.Main.runMonoDex(Main.java:311)
2016-01-07 10:49:51 at com.android.dx.command.dexer.Main.run(Main.java:277)
2016-01-07 10:49:51 at com.android.dx.command.dexer.Main.main(Main.java:245)
2016-01-07 10:49:51 at com.android.dx.command.Main.main(Main.java:106)
2016-01-07 10:49:51 
2016-01-07 10:49:51 UNEXPECTED TOP-LEVEL EXCEPTION:
2016-01-07 10:49:51 java.io.FileNotFoundException: D:\Work\SVN\Native\鎴戠殑宸ョ▼\build\src\platforms\android\build\intermediates\pre-dexed\debug\classes-bc78ef27922ebddaf5ac264df598226800028ed8.jar (系统找不到指定的路径。)
2016-01-07 10:49:51 at java.util.zip.ZipFile.open(Native Method)
2016-01-07 10:49:51 at java.util.zip.ZipFile.<init>(ZipFile.java:215)
2016-01-07 10:49:51 at java.util.zip.ZipFile.<init>(ZipFile.java:145)
2016-01-07 10:49:51 at java.util.zip.ZipFile.<init>(ZipFile.java:159)
2016-01-07 10:49:51 at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:244)
2016-01-07 10:49:51 at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
2016-01-07 10:49:51 at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
2016-01-07 10:49:51 at com.android.dx.command.dexer.Main.processOne(Main.java:672)
2016-01-07 10:49:51 at com.android.dx.command.dexer.Main.processAllFiles(Main.java:574)
2016-01-07 10:49:51 at com.android.dx.command.dexer.Main.runMonoDex(Main.java:311)
2016-01-07 10:49:51 at com.android.dx.command.dexer.Main.run(Main.java:277)
2016-01-07 10:49:51 at com.android.dx.command.dexer.Main.main(Main.java:245)
2016-01-07 10:49:51 at com.android.dx.command.Main.main(Main.java:106)
2016-01-07 10:49:51 2 errors; aborting
2016-01-07 10:49:51 
2016-01-07 10:49:51 FAILURE: Build failed with an exception.
2016-01-07 10:49:51 
2016-01-07 10:49:51 * What went wrong:
2016-01-07 10:49:51 Execution failed for task ':dexDebug'.
2016-01-07 10:49:51 > com.android.ide.common.internal.LoggedErrorException: Failed to run command:
2016-01-07 10:49:51 D:\Work\BeX5\tools\adt-sdk\build-tools\23.0.2\dx.bat --dex --no-optimize --output D:\Work\SVN\Native\我的工程\build\src\platforms\android\build\intermediates\dex\debug --input-list=D:\Work\SVN\Native\我的工程\build\src\platforms\android\build\intermediates\tmp\dex\debug\inputList.txt
2016-01-07 10:49:51 Error Code:
2016-01-07 10:49:51 1
2016-01-07 10:49:51 Output:
2016-01-07 10:49:51
2016-01-07 10:49:51 UNEXPECTED TOP-LEVEL EXCEPTION:
2016-01-07 10:49:51 java.lang.RuntimeException: D:\Work\SVN\Native\鎴戠殑宸ョ▼\build\src\platforms\android\build\intermediates\classes\debug: file not found
2016-01-07 10:49:51 at com.android.dex.util.FileUtils.readFile(FileUtils.java:51)
2016-01-07 10:49:51 at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:169)
2016-01-07 10:49:51 at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
2016-01-07 10:49:51 at com.android.dx.command.dexer.Main.processOne(Main.java:672)
2016-01-07 10:49:51 at com.android.dx.command.dexer.Main.processAllFiles(Main.java:574)
2016-01-07 10:49:51 at com.android.dx.command.dexer.Main.runMonoDex(Main.java:311)
2016-01-07 10:49:51 at com.android.dx.command.dexer.Main.run(Main.java:277)
2016-01-07 10:49:51 at com.android.dx.command.dexer.Main.main(Main.java:245)
2016-01-07 10:49:51 at com.android.dx.command.Main.main(Main.java:106)
2016-01-07 10:49:51
2016-01-07 10:49:51 UNEXPECTED TOP-LEVEL EXCEPTION:
2016-01-07 10:49:51 java.io.FileNotFoundException: D:\Work\SVN\Native\鎴戠殑宸ョ▼\build\src\platforms\android\build\intermediates\pre-dexed\debug\classes-bc78ef27922ebddaf5ac264df598226800028ed8.jar (系统找不到指定的路径。)
2016-01-07 10:49:51 at java.util.zip.ZipFile.open(Native Method)
2016-01-07 10:49:51 at java.util.zip.ZipFile.<init>(ZipFile.java:215)
2016-01-07 10:49:51 at java.util.zip.ZipFile.<init>(ZipFile.java:145)
2016-01-07 10:49:51 at java.util.zip.ZipFile.<init>(ZipFile.java:159)
2016-01-07 10:49:51 at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:244)
2016-01-07 10:49:51 at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
2016-01-07 10:49:51 at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
2016-01-07 10:49:51 at com.android.dx.command.dexer.Main.processOne(Main.java:672)
2016-01-07 10:49:51 at com.android.dx.command.dexer.Main.processAllFiles(Main.java:574)
2016-01-07 10:49:51 at com.android.dx.command.dexer.Main.runMonoDex(Main.java:311)
2016-01-07 10:49:51 at com.android.dx.command.dexer.Main.run(Main.java:277)
2016-01-07 10:49:51 at com.android.dx.command.dexer.Main.main(Main.java:245)
2016-01-07 10:49:51 at com.android.dx.command.Main.main(Main.java:106)
2016-01-07 10:49:51 2 errors; aborting
2016-01-07 10:49:51 
2016-01-07 10:49:51 
2016-01-07 10:49:51 * Try:
2016-01-07 10:49:51 Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
2016-01-07 10:49:51 :dexDebug FAILED
2016-01-07 10:49:51 
2016-01-07 10:49:51 BUILD FAILED


根据提示把

D:\Work\BeX5\tools\adt-sdk\build-tools\23.0.2\dx.bat

中的最后一行改为

call "%java_exe%" %javaOpts% -Dfile.encoding=UTF-8 -Djava.ext.dirs="%frameworkdir%" -jar "%jarpath%" %params%

增加了-Dfile.encoding=UTF-8 这个强制指定字符集,本质原因是中间文件dex\debug\inputList.txt是utf-8格式

阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

Cordova编译Android 22 以上版本,中文目录出错问题的解决办法

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭