1

I'm new to using anything other than Eclipse for compiling Java projects. I am trying to use command line to compile a java file that uses Android but I have been unsuccessful.

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? 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. 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. 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. I tried changing my classpath to the directory with android-8, but unfortunately it did not change anything. Any ideas?

1
  • The JAR files, once the Android SDK is installed, could be in several places. Find it with Eclipse tool, if you have. Commented Jun 7, 2012 at 20:48

3 Answers 3

1

There's a guide on how to build from command-line. Try:

ant release

or

ant debug

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for the resource. Hopefully, it will have what I'm looking for.
1

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.

My JRE 1.6 is path "C:\Program Files\Java\jdk1.6.0_25\lib" for example. Another possible issue is the directory Program_Files, mine does not have underline, instead a space. If I compile on command line instead of Eclipse, I would put quotes around this path.

The CLASSPATH can take several directories. So for experimenting, use several directories to fix the compile error.

New My Android SDK is at C:\android-sdk-windows\tools. There are many JAR files at android-sdk-windows; find all directories with JARs. I think this is it! consider it your lucky day.

Good luck,

Tommy Kwee

5 Comments

@JHowser, I feel strongly your error is the Android SDK path. Look at the New section, just added.
Tommy, Thanks for the suggestion. The quotes recommendation was definitely useful for future reference as I didn't know what to do about the space. Unfortunately, I do not have that android directory on my computer and I still cannot get it to work. Appreciate the effort, though.
Did you install the Android SDK yet? If you have, it must be stored locally on your local drive. You need the path to that SDK.
Yes. It's at the location in Program Files
@JHowser, If you know where your Android SDK is, then CLASSPATH should be set to that directory where the JAR files are. The CLASSPATH may contain several directories. Simply keep adding them until no more compile errors.
0

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? Try using 1.6 and see if that helps.

It anyone using 1.7, I haven't tried this yet but I know compiling the source was funky with different driver versions.

4 Comments

Thanks, any idea how I switch to 1.6? Do I need to download an older jdk and refer to that?
Exactly. Just like what your doing now with the 1.7 version
I downloaded jdk1.6 and used the directory in my classpath. unfortunately, it didn't change anything. Any other ideas?
No. It sounds like the other guys have the right idea, it's most likely a path issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.