我正在使用ANT編譯我構建的Android應用程序。這聽起來很奇怪,可能沒有什麼區別,但我使用Android SDK來構建一個新項目,然後使用.NET以編程方式修改項目中的幾個文件,以便按照我想要的方式構建。用Ant編譯的Android項目無法編譯,非法字符錯誤
我已經將項目加載到Eclipse中,它似乎可以正確編譯,但是當我通過ANT運行它時,它不能正確編譯。錯誤似乎說我有'?'在項目中的一項活動中。我已多次確認,肯定沒有'?'在文件中。
錯誤:
[javac] C:\IBE_temp\_RTS\ANTTest\$SimpleTest\proj\src\com\infosol\SimpleTest\MyActivity.java:1: illegal character: \65279
[javac] ?package com.infosol.SimpleTest;
[javac]^
[javac] 1 error
如果任何人有什麼我做錯了的想法,我真的很感激它。不確定什麼會有幫助,但下面是ANT輸出的結果。
命令行:
C:\ IBE_temp \ java中\ BIN \ java的-Dant.home = 「C:\ IBE_temp \打包\ ANTSDK」 -classpath「C:\ IBE_temp \打包\ ANTSDK \ lib中\螞蟻launcher.jar」 org.apache.tools.ant.launch.Launcher釋放-v
部分ANT結果:
compile:
Property "tested.project.absolute.dir" has not been set
Property "tested.project.absolute.dir" has not been set
[javac] C:\IBE_temp\Packager\AndroidSDK\tools\ant\main_rules.xml:384: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=l
ast; set to false for repeatable builds
[javac] com\infosol\SimpleTest\MyActivity.java added as com\infosol\SimpleTest\MyActivity.class doesn't exist.
[javac] com\infosol\SimpleTest\R.java added as com\infosol\SimpleTest\R.class doesn't exist.
[javac] Compiling 2 source files to C:\IBE_temp\_RTS\ANTTest\$SimpleTest\proj\bin\classes
[javac] Using modern compiler
[javac] Compilation arguments:
[javac] '-d'
[javac] 'C:\IBE_temp\_RTS\ANTTest\$SimpleTest\proj\bin\classes'
[javac] '-classpath'
[javac] 'C:\IBE_temp\_RTS\ANTTest\$SimpleTest\proj\bin\classes;C:\IBE_temp\_RTS\ANTTest\$SimpleTest\proj;C:\IBE_temp\_RTS\ANTTest\$SimpleTest\proj
\libs\airbootstap.jar;C:\IBE_temp\_RTS\ANTTest\$SimpleTest\proj\libs\xcelsiusLoad.jar;C:\IBE_temp\Packager\ANTSDK\lib\ant-launcher.jar;C:\IBE_temp\Pac
kager\ANTSDK\lib\ant-antlr.jar;C:\IBE_temp\Packager\ANTSDK\lib\ant-apache-bcel.jar;C:\IBE_temp\Packager\ANTSDK\lib\ant-apache-bsf.jar;C:\IBE_temp\Pack
ager\ANTSDK\lib\ant-apache-log4j.jar;C:\IBE_temp\Packager\ANTSDK\lib\ant-apache-oro.jar;C:\IBE_temp\Packager\ANTSDK\lib\ant-apache-regexp.jar;C:\IBE_t
emp\Packager\ANTSDK\lib\ant-apache-resolver.jar;C:\IBE_temp\Packager\ANTSDK\lib\ant-apache-xalan2.jar;C:\IBE_temp\Packager\ANTSDK\lib\ant-commons-logg
ing.jar;C:\IBE_temp\Packager\ANTSDK\lib\ant-commons-net.jar;C:\IBE_temp\Packager\ANTSDK\lib\ant-jai.jar;C:\IBE_temp\Packager\ANTSDK\lib\ant-javamail.j
ar;C:\IBE_temp\Packager\ANTSDK\lib\ant-jdepend.jar;C:\IBE_temp\Packager\ANTSDK\lib\ant-jmf.jar;C:\IBE_temp\Packager\ANTSDK\lib\ant-jsch.jar;C:\IBE_tem
p\Packager\ANTSDK\lib\ant-junit.jar;C:\IBE_temp\Packager\ANTSDK\lib\ant-junit4.jar;C:\IBE_temp\Packager\ANTSDK\lib\ant-netrexx.jar;C:\IBE_temp\Package
r\ANTSDK\lib\ant-swing.jar;C:\IBE_temp\Packager\ANTSDK\lib\ant-testutil.jar;C:\IBE_temp\Packager\ANTSDK\lib\ant.jar;C:\IBE_temp\java\lib\tools.jar'
[javac] '-sourcepath'
[javac] 'C:\IBE_temp\_RTS\ANTTest\$SimpleTest\proj\src;C:\IBE_temp\_RTS\ANTTest\$SimpleTest\proj\gen'
[javac] '-target'
[javac] '1.5'
[javac] '-bootclasspath'
[javac] 'C:\IBE_temp\Packager\AndroidSDK\platforms\android-8\android.jar'
[javac] '-encoding'
[javac] 'UTF-8'
[javac] '-g'
[javac] '-source'
[javac] '1.5'
[javac]
[javac] The ' characters around the executable and arguments are
[javac] not part of the command.
[javac] Files to be compiled:
[javac] C:\IBE_temp\_RTS\ANTTest\$SimpleTest\proj\src\com\infosol\SimpleTest\MyActivity.java
[javac] C:\IBE_temp\_RTS\ANTTest\$SimpleTest\proj\gen\com\infosol\SimpleTest\R.java
[javac] C:\IBE_temp\_RTS\ANTTest\$SimpleTest\proj\src\com\infosol\SimpleTest\MyActivity.java:1: illegal character: \65279
[javac] ?package com.infosol.SimpleTest;
[javac]^
[javac] 1 error
BUILD FAILED
C:\IBE_temp\Packager\AndroidSDK\tools\ant\main_rules.xml:384: Compile failed; see the compiler error output for details.
at org.apache.tools.ant.taskdefs.Javac.compile(Javac.java:1150)
at org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:912)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:68)
at com.android.ant.IfElseTask.execute(IfElseTask.java:120)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:390)
at org.apache.tools.ant.Target.performTasks(Target.java:411)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
at org.apache.tools.ant.Main.runBuild(Main.java:809)
at org.apache.tools.ant.Main.startAnt(Main.java:217)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
Total time: 1 second
你太棒了。我永遠都不會想到那件事。爲了解決這個問題,我在Notepad ++中打開了java文件,然後在Encoding中將編碼更改爲無編碼的編碼。 – Greg
具體來說,我用這個代碼,所以解決這個問題:'修改活動文件(必須保存在UTF-8沒有BOM) Dim utf8WithoutBom As New System.Text.UTF8Encoding(False) 使用sw作爲新的StreamWriter(文件夾+ m_InternalName +「.java」,False,utf8WithoutBom) sw.Write(Android_BuildActivityFile()) End Using – Greg
對於Mac OSX用戶,請注意使用TextEdit也可以。默認情況下,TextEdit保存爲不含BOM的UTF-8。 –