blob: 7bcb509a4f4eee5ea10d335e32810d88891397ff [file] [log] [blame]
page.title=In Other IDEs
@jd:body
<p>The recommended way to develop an Android application is to use
<a href="{@docRoot}guide/developing/eclipse-adt.html">Eclipse with the Android
Development Tools (ADT) plugin</a>, provided in the SDK. The ADT plugin
provides editing, building,and debugging functionality integrated right into the IDE. </p>
<p>However, if you'd rather develop your application in another IDE, such as IntelliJ,
or use Eclipse without the ADT plugin, you can do that instead. The SDK
provides the tools you need to set up, build, and debug your application.
</p>
<h2>Creating an Android Project </h2>
<p>The Android SDK includes <code>activityCreator</code>, a program that generates a number of stub files for your project, as well as a build file. You can use the program to create an Android project for new code or from existing code, such as the sample applications included in the SDK. For Linux and Mac, the SDK provides <code>activitycreator</code> and for Windows, <code>activityCreator.bat</code>, a batch script. Regardless of platform, you can use <code>activitycreator</code> in the same way. </p>
<p>To run <code>activityCreator</code> and create an Android project, follow these steps:</p>
<ol>
<li> In the command line, change to the <code>tools/</code> directory of the SDK and create a new directory for your project files. If you are creating a project from existing code, change to the root folder of your application instead. </li>
<li><p>Run <code>activityCreator</code>. In the command, you must specify a fully-qualified class name as an argument. If you are creating a project for new code, the class represents the name of a stub class that the script will create. If you are creating a project from existing code, you must specify the name of one Activity class in the package. Command options for the script include:
<ul>
<li><code>--out &lt;folder&gt;</code> which sets the output directory. By default, the output directory is the current directory. If you created a new directory for your project files, use this option to point to it. </li>
<li><code>--ide intellij</code>, which generates IntelliJ IDEA project files in the newly created project</li>
</ul>
</li>
</ol>
<p>Here's an example:</p>
<pre>
~/android_linux_sdk/tools $ ./activityCreator.py --out myproject your.package.name.ActivityName
package: your.package.name
out_dir: myproject
activity_name: ActivityName
~/android_linux_sdk/tools $ </pre>
<p>The <code>activityCreator</code> script generates the following files and directories (but will not overwrite existing ones):</p>
<ul>
<li><code>AndroidManifest.xml</code> The application manifest file, synced to the specified Activity class for the project.</li>
<li><code>build.xml</code> An <code>Ant</code> file that you can use to build/package the application.</li>
<li><code>src<em>/your/package/name/ActivityName</em>.java</code>&nbsp;The Activity class you specified on input.</li>
<li><code><em>your_activity</em>.iml, <em>your_activity</em>.ipr,
<em>your_activity</em>.iws&nbsp;&nbsp;&nbsp;</code> [<em>only
with the <code>-ide intelliJ</code> flag</em>] intelliJ project
files. </li>
<li><code>res/</code> &nbsp;&nbsp;A directory to hold resources. </li>
<li><code>src/</code> &nbsp;&nbsp;&nbsp;The source directory.
<li><code>bin/</code> &nbsp;&nbsp;&nbsp;The output directory for the build script.</li>
</ul>
<p>You can now move your folder wherever you want for development, but keep in mind
that you'll have to use the <a href="{@docRoot}guide/developing/tools/adb.html">adb</a> program in the <code>tools/</code> folder to
send files to the emulator, so you'll need access between your solution and
the <code>tools/</code> folder. </p>
<p>Also, you should refrain from moving the
location of the SDK directory, since this will break the build scripts (they
will need to be manually updated to reflect the new SDK location before they will
work again).</p>
<a name="buidingwithant"></a>
<h2 id="antbuild">Building the Application with Ant</h2>
<p>Use the Ant <code>build.xml</code> file generated by
<code>activityCreator</code> to build your application.</p>
<ol>
<li>If you don't have it, you can obtain Ant from the
<a href="http://ant.apache.org/">Apache Ant home page</a>. Install it and make
sure it is on your executable path. </li>
<li>Before calling Ant, you need to declare the JAVA_HOME environment variable to specify the path to where the JDK is installed.
<p class="note"><strong>Note:</strong> When installing JDK on Windows, the default is to install in the "Program Files" directory. This location will cause <code>ant</code> to fail, because of the space. To fix the problem, you can specify the JAVA_HOME variable like this: <code>set JAVA_HOME=c:\Prora~1\Java\<jdkdir></code>. The easiest solution, however, is to install JDK in a non-space directory, for example: <code>c:\java\jdk1.6.0_02</code>. </p>
</li>
<li>If you have not done so already, follow the instructions for Creating a
New Project above to set up the project.</li>
<li>You can now run the Ant build file by simply typing ant in the same folder
as the build.xml file for your project. Each time you change
a source file or resource, you should run ant again and it will package up the
latest version of the application for you to deploy.</li>
</ol>
<h2 id="sign_in_other">Setting Up Application Signing</h2>
<p>As you begin developing Android applications, you should understand that all
Android applications must be digitally signed before the system will install
them on the emulator or an actual device. </p>
<p>The Android build tools help you get started quickly by signing your .apk
files with a debug key, prior to installing them on the emulator. This means
that you can compile your application and install it on the emulator without
having to generate your own private key. However, please note that if you intend
to publish your application, you <em>must</em> sign the application with your
own private key, rather than the debug key generated by the SDK tools. </p>
<p>To sign your applications, the ADT plugin requires the Keytool utility
included in the JDK. To set up your development environment for
signing, all you need to do is make sure that Keytool is available on your
machine that the build tools know how to find it. </p>
<p>In most cases, you can tell the SDK build tools how to find Keytool by making
sure that
your JAVA_HOME environment variable is set and that it references a suitable
JDK. Alternatively,
you can add the JDK version of Keytool to your PATH variable.</p>
<p>If you are developing on a version of Linux that originally came with Gnu
Compiler for Java,
make sure that the system is using the JDK version of Keytool, rather than the
gcj version.
If keytool is already in your PATH, it might be pointing to a symlink at
/usr/bin/keytool.
In this case, check the symlink target to make sure that it points to the
keytool in the JDK.</p>
<p>In all cases, please read and understand <a
href="{@docRoot}guide/publishing/app-signing.html">Signing Your
Applications</a>, which provides an overview of application signing on Android
and what it means to you as an Android application developer. </p>
<h2>Running an Android Application</h2>
<p>To run a compiled
application, you will upload the .apk file to the <code>/data/app/ </code>directory
in the emulator using the <a href="{@docRoot}guide/developing/tools/adb.html">adb</a> tool as described here:</p>
<ol>
<li>Start the emulator (run <code><em>&lt;your_sdk_dir&gt;</em>/tools/emulator</code> from the command line)</li>
<li>On the emulator, navigate to the home screen (it is best not to have that
application running when you reinstall it on the emulator; press the <strong>Home</strong> key
to navigate away from that application).</li>
<li>Run <code>adb install <em>myproject</em>/bin/&lt;<em>appname</em>&gt;.apk</code> to upload
the executable. So, for example, to install the Lunar Lander sample, navigate
in the command line to <code><em>&lt;your_sdk_dir&gt;</em>/sample/LunarLander</code> and type <code>../../tools/adb&nbsp;install&nbsp;bin/LunarLander.apk</code></li>
<li>In the emulator, open the list of available applications, and scroll down to
select and start your application. </li>
</ol>
<p class="note"><strong>Note:</strong> When you install an Activity for the
first time, you might have to restart the emulator before it shows up in the
application launcher, or other applications can call it. This is because
the package manager usually only examines manifests completely on emulator
startup.</p>
<h2>Attaching a Debugger to Your Application</h2>
<p>This section describes how to display debug information on the screen (such
as CPU usage), as well as how to hook up your IDE to debug running applications
on the emulator. </p>
<p>Attaching a debugger is automated using the Eclipse plugin,
but you can configure other IDEs to listen on a debugging port to receive debugging
information.</p>
<ol>
<li><strong>Start the <a href="{@docRoot}guide/developing/tools/ddms.html">Dalvik Debug Monitor Server (DDMS)
tool </a>, </strong> which
acts as a port forwarding service between your IDE and the emulator.</li>
<li><strong>Set
optional debugging configurations on
your emulator</strong>, such as blocking application startup for an activity
until a debugger is attached. Note that many of these debugging options
can be used without DDMS, such as displaying CPU usage or screen refresh
rate on the emulator.</li>
<li><strong>Configure your IDE to attach to port 8700 for debugging.</strong> We
include information on <a href="{@docRoot}guide/developing/debug-tasks.html#ide-debug-port">
how to set up Eclipse to debug your project</a>. </li>
</ol>