简体   繁体   English

无法使用命令行编译Android / Java项目

[英]Can't compile Android/Java project using command line

I'm new to using anything other than Eclipse for compiling Java projects. 我不习惯使用Eclipse以外的任何东西来编译Java项目。 I am trying to use command line to compile a java file that uses Android but I have been unsuccessful. 我正在尝试使用命令行来编译使用Android的java文件但我没有成功。

I've been trying variations of the following (where my root directory is my project directory): 我一直在尝试以下变体(我的根目录是我的项目目录):

    javac -classpath C:\Program_Files\Java\jdk1.7.0_04\bin;
          C:\Program_Files\Android\android-sdk\platforms\android-15\android.jar
          src\package1\package2\projectName.Java

It hasn't been working. 它没有奏效。 I get a lot of errors saying: 我收到很多错误说:

    package android.content does not exist
    package android.database does not exist
    package android.net does not exist
    package android.os does not exist
    package android.util does not exist

Am I doing something drastically wrong here? 我在这里做了什么严重的错误吗? How can I get it to recognize those android packages? 我如何让它识别那些android包? Could someone point me in the right direction here? 有人能指出我在正确的方向吗? I've read a bunch of documentation on javac, command-line and classpaths, but I can't seem to pinpoint the main problem here. 我已经阅读了大量有关javac,命令行和类路径的文档,但我似乎无法确定这里的主要问题。 Thank you. 谢谢。

NEW

I'm not sure if this information will make a difference... but when I run my program in eclipse, it uses the Android 2.2 with the directory C:\\Program_Files\\Android\\android-sdk\\platforms\\android-8\\android.jar instead of C:\\Program_Files\\Android\\android-sdk\\platforms\\android-15\\android.jar . 我不确定这些信息是否有所作为......但是当我在eclipse中运行我的程序时,它使用的是Android 2.2,目录为C:\\Program_Files\\Android\\android-sdk\\platforms\\android-8\\android.jar而不是C:\\Program_Files\\Android\\android-sdk\\platforms\\android-15\\android.jar Does this change anything? 这会改变什么吗? When I try to go to that folder on my computer, though... it does not exist. 当我尝试在我的计算机上访问该文件夹时,虽然......它不存在。 The android-15 folder is what exists. android-15文件夹是存在的。 I tried changing my classpath to the directory with android-8 , but unfortunately it did not change anything. 我尝试将我的类路径更改为android-8目录,但不幸的是它没有改变任何东西。 Any ideas? 有任何想法吗?

There's a guide on how to build from command-line . 有关如何从命令行构建指南 Try: 尝试:

ant release 蚂蚁释放

or 要么

ant debug 蚂蚁调试

For the classpath, I think your directory is not correct. 对于类路径,我认为您的目录不正确。 For one thing, the bin subdirectory normally has the EXEs or DLLs on a Windows system. 首先,bin子目录通常在Windows系统上具有EXE或DLL。

My JRE 1.6 is path " C:\\Program Files\\Java\\jdk1.6.0_25\\lib " for example. 例如,我的JRE 1.6是路径“ C:\\ Program Files \\ Java \\ jdk1.6.0_25 \\ lib ”。 Another possible issue is the directory Program_Files, mine does not have underline, instead a space. 另一个可能的问题是目录Program_Files,我的没有下划线,而是一个空格。 If I compile on command line instead of Eclipse, I would put quotes around this path. 如果我在命令行而不是Eclipse上编译,我会在这条路径上加上引号。

The CLASSPATH can take several directories. CLASSPATH可以采用多个目录。 So for experimenting, use several directories to fix the compile error. 因此,对于实验,使用几个目录来修复编译错误。

New My Android SDK is at C:\\android-sdk-windows\\tools. 新的我的Android SDK位于C:\\ android-sdk-windows \\ tools。 There are many JAR files at android-sdk-windows; android-sdk-windows上有很多JAR文件; find all directories with JARs. 使用JAR查找所有目录。 I think this is it! 我觉得这就是! consider it your lucky day. 认为这是你的幸运日。

Good luck, 祝好运,

Tommy Kwee 汤米克威

I feel it could be 1 of 2 things. 我觉得这可能是两件事之一。 First, your path is not correct, however in this case it seems to be ok. 首先,你的路径不正确,但在这种情况下它似乎没问题。

The second thing, shot in the dark here, does Android support java 1.7? 第二件事,在黑暗中拍摄,Android支持java 1.7吗? Try using 1.6 and see if that helps. 尝试使用1.6,看看是否有帮助。

It anyone using 1.7, I haven't tried this yet but I know compiling the source was funky with different driver versions. 任何使用1.7的人,我还没有尝试过这个,但我知道编译源代码的时候有不同的驱动程序版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM