Search code examples
androidcommand-linesdkcompilationjavac

Android build .jar from command line fails


I would like to generate some .jar for tools to include in an Android project.

So I use command tool "javac" which works great.

But when I try to use Android SDK, it fails:

C:\Dev\Tools.java:123: package android.util does not exist
    android.util.Log.d("MYTAG", "hello !");

To compile, I use this command:

"C:\Program Files (x86)\Java\jdk1.6.0_23\bin\javac.exe" -g -d C:\Gen C:\Dev\Tools.java

Any help?


Solution

    1. "javac" is the Java compiler, not the tool used to create JAR files, so just compiling a class does not generate a jar file
    2. To be able to compile a class, you must also tell the compiler where it can find the required libraries. This is automatically done for system libraries, but you'll have to pass the path to the Android libraries. This can be done by specifying the folders/jar files using the -classpath parameter on the command line, or by adding it to the respective CLASSPATH environment variable.