blob: dc7c11dcc66302c204cfa2e01656a6b51ffc16c0 [file] [log] [blame]
page.title=In Other IDEs
@jd:body
<p>The recommended way to develop an Android application is to use
<a href="#developingwitheclipse">Eclipse
with the ADT plugin</a>. This 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}reference/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="buildingwithant"></a>
<h2>Building an Android Application</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>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}reference/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}reference/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="#eclipse">how to set up Eclipse to debug
your project</a>. </li>
<a name="eclipse" id="eclipse"></a>
</ol>
<h2>Configuring your IDE to attach to the debugging port</h2>
<p>DDMS will assign a specific debugging port to every virtual machine that it
finds on the emulator. You must either attach your IDE to that
port (listed on the Info tab for that VM), or you can use a default port 8700
to connect to whatever application is currently selected on the list of discovered
virtual machines.</p>
<p>Your IDE should attach to your application running on the emulator, showing you
its threads and allowing you to suspend them, inspect their state, and set breakpoints.
If you selected &quot;Wait for debugger&quot; in the Development settings panel
the application will run when Eclipse connects, so you will need to set any breakpoints
you want before connecting.</p>
<p>Changing either the application being debugged or the &quot;Wait for debugger&quot;
option causes the system to kill the selected application if it is currently
running. You can use this to kill your application if it is in a bad state
by simply going to the settings and toggling the checkbox.</p>