My favorites | Sign in
Project Logo
       
Search
for
Updated Nov 19, 2007 by intelliyole
GettingStarted  

Getting Started with IntelliJ IDEA and Android Development

Download IntelliJ IDEA

If you don't already have IntelliJ IDEA installed, you can download a 30-day evaluation version from http://www.jetbrains.com/idea/download/

The plugin requires IntelliJ IDEA 7.0 or higher and is not compatible with earlier versions of IntelliJ IDEA.

Install Plugin

Go to Settings | Plugins, select the "Android Support" plugin in the Available tab and press Install.

Create New Project

Select "Create project from scratch" option. On the second page of the wizard, enter the name and location of your project.

Accept the default source root option. On the "Technologies" page, select Android and enter the path to your Android SDK installation.

If you are prompted to select a JDK, select the installation home of a Java 1.5 or 1.6 JDK (no JRE).

Create Activity

Select the src directory in the project view, press Alt-Ins (Ctrl-Enter on a Mac) to invoke the "New" menu and select "Package". Enter the name of the package.

Select the package, press Alt-Ins again and select "Activity" from the menu.

In the "New Activity" dialog, enter the class name and label for the activity. Ensure that "Mark as startup activity" checkbox is checked.

Create Activity Implementation

In the activity class, press Ctrl-O to invoke the "Override Methods" dialog. Select the onCreate method.

Type the method body text:

    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        TextView tv = new TextView(this);
        tv.setText("Hello, Android, from IntelliJ IDEA!");
        setContentView(tv);
    }

Run the Activity

Right-click the class and select "Run HelloWorld" from the context menu.

Wait for the emulator to start, and for the activity to be displayed.

If an error "Cannot start activity..." is printed in the console window, close the emulator and try again (this is a known issue with the Android emulator).

Note that the initial release of the plugin does not support debugging Android applications. Debugging support will be added in a future release.

Cool Stuff to Try

(a.k.a. why we're better than ADT :) )

In AndroidManifest.xml, put the cursor on @drawable/icon and press Ctrl-Shift-I.

Try pressing Ctrl-B and Ctrl-Space in a few places to explore the navigation completion options available. Even in the initial release of the plugin, a few things are supported.


Comment by ilyasin, Nov 20, 2007

I did exactly as described here, but I always get an error when I try to run the project: Error: unable to access jarfile ..\framework\dx.jar. I found this file in \tools\lib directory in SDK, so should I copy it to some other place ?

My configuration: Intellih 7.0.1 SDK: android_sdk_windows_m3-rc22a Thank you in advance.

Comment by vvessan, Nov 21, 2007

Nice plugin. However I'm having problem with testing. I have added Android faced into currently existing project and I'm getting this error message when running an Activity: can't find 'C:\Documents and Settings\username\My Documents\Projects\Test\Android\Android.apk' to install

the fact is there is no such file at the location (just classes.dex file) ... Am I doing something wrong? Has anybody the same problem?

Thanks

Comment by vvessan, Nov 21, 2007

OK. Problem solved. For anyone experiencing the same problem:

- add directory named "res" next to your "src" directory (containing source code), adding "res" is required as written in Android documentation even when it's empty

PS: would be nice to add to the plugin functionality for leting user know there is such a problem, or create the folder automatically

Comment by DulcetTone, Nov 26, 2007

I have a similar issue which seems to prevent my .apk file from being created/found. I have "" as my source directory name -- the entire hierarchy I am in is the source tree, and sprinkling "src" like pot pourri all over it is not something I am eager to do!

Is it possible that this could be made to work in such a case where the source code is not stored in a subdirectory of the project?

Thanks.

Comment by sergeytch, Dec 04, 2007

I got "Error:Unable to access jarfile ..\framework\dx.jar" message too. 1) I tried to put ......\tools\lib\ path into the "PATH" environment variable; 2) I made dir named "framework" and copied dx.jar, after that I put this directory inside EVERY directory in my project and even in the upper directories; 3) i even added this jar file to libraries.

nothing helped :(

Comment by vvessan, Dec 05, 2007

Hello, I have the following issue (I also logged is into Issues):

For the first time the activity is launched successfuly and working. Second run is not working, writing "Error: Activity not started, unable to call on to activity manager service" to console. Sometimes restarting project helps, but not everytime.

Not sure whether this is the known issue mentioned in getting started wiki page.

Anybody has solution to this problem?

Thanks

Comment by cpedia, Dec 07, 2007

I met the same issue as the above.

Comment by sergeytch, Dec 08, 2007

"Error:Unable to access jarfile ..\framework\dx.jar" problem can be solved in such way: in dx.bat write

set jarfile=dx.jar set frameworkdir=E:\Android\tools\lib\
(where E:\Android\tools\lib\ is a full path to dx.jar)

Comment by moisei, Dec 19, 2007

"Error:Unable to access jarfile ..\framework\dx.jar" the solid fix is in the dx.bat: -cd %~dp0 +cd /d "%~dp0"

The problem appears when the batch is executed from the other drive. In this case cd command doesn't change drive. cd /d fixes this problem. The quotes around "%~dp0" is for to be safe even if %~dp0 contains spaces.

Comment by nisroc, Dec 20, 2007

I followed the steps and encountered an odd failure when I went to run the activity -- I could not even compile the HelloWorld? class. the Messages window displayed this rather cryptic error:

Information:Compilation completed with 1 error and 0 warnings Information:1 error Information:0 warnings Error:Command "[Ljava.lang.String;@8f25a1" execution failed with exit code 255

This failure occurs with both IDEA 7.0.1 and 7.0.2 on OS X 10.5.1 using android_sdk_darwin_m3-rc37a

On a lark, I tried running through the steps again to see if I could compile without creating an Activity; I got the same error.

-- nisroc

Comment by nisroc, Dec 20, 2007

Argh, I didn't closely read the android sdk requirements:

http://code.google.com/android/intro/installing.html#developmentrequirements

especially the relevant section in Supported OSes:

  • Mac OS X 10.4.8 or later (x86 only)

us poor PPC users are out in the cold. Wow, it has been a while since I've seen something that wasn't a Universal Binary. :(

Comment by charlie.hubbard, Dec 26, 2007

I can't get mine to run. I'm using 7.0.1 on Mac OS 10.4 Intel. I keep getting the following:

/Users/charlie/lib/android_sdk_darwin_m3-rc37a/tools/emulator
/Users/charlie/lib/android_sdk_darwin_m3-rc37a/tools/adb wait-for-device
/Users/charlie/lib/android_sdk_darwin_m3-rc37a/tools/adb install /Users/charlie/projects/android/tutorial/out/production/tutorial/tutorial.apk
270 KB/s (9404 bytes in 0.033s)
/Users/charlie/lib/android_sdk_darwin_m3-rc37a/tools/adb shell am start -n android/android.HelloWorld
Starting: Intent { comp={android/android.HelloWorld} }
Error type 3
Error: Activity class {android/android.HelloWorld} does not exist.

Which I don't understand why android/android.HelloWorld?? is used. It seems to me that it would just be android.HelloWorld?? for the fully qualified name. What is android/ used for?

Comment by charlie.hubbard, Dec 26, 2007

Ok so what's wrong with a package called tutorial? Here is what I see in the logcat output:

/data/app/tutorial.apk (at Binary XML file line #2): <manifest> specifies bad package name: tutorial

So what's a valid package name?

Comment by charlie.hubbard, Dec 26, 2007

Fixed my problem by using something with a dot in it. Then doing the same thing below, and it fixed it. Weird how it doesn't accept first level packages.

So how do you get it to rebuild the application? I make a change to my app, compile/make, and it never picks up those changes. I have to go onto the file system and delete the out/production/module directory to get it to rebuild. What's up?

Comment by didigo9, May 29, 2008

I am getting this:

Information:Compilation completed with 23 errors and 0 warnings Information:23 errors Information:0 warnings Error:UNEXPECTED TOP-LEVEL ERROR: Error:java.lang.OutOfMemoryError?: Java heap space Error: at com.google.ssa.SsaRenamer?.dupArray(SsaRenamer?.java:177) Error: at com.google.ssa.SsaRenamer?.access$300(SsaRenamer?.java:62) Error: at com.google.ssa.SsaRenamer?$BlockRenamer?.process(SsaRenamer?.java:368) Error: at com.google.ssa.SsaRenamer?$1.visitBlock(SsaRenamer?.java:147) Error: at com.google.ssa.SsaMethod?.forEachBlockDepthFirstDom(SsaMethod?.java:600) Error: at com.google.ssa.SsaRenamer?.run(SsaRenamer?.java:145) Error: at com.google.ssa.SsaConverter?.convertToSsaMethod(SsaConverter?.java:46) Error: at com.google.ssa.Optimizer.optimize(Optimizer.java:100) Error: at com.google.ssa.Optimizer.optimize(Optimizer.java:74) Error: at com.google.dex.cf.CfTranslator?.processMethods(CfTranslator?.java:347) Error: at com.google.dex.cf.CfTranslator?.translate0(CfTranslator?.java:183) Error: at com.google.dex.cf.CfTranslator?.translate(CfTranslator?.java:142) Error: at com.google.command.dexer.Main.processClass(Main.java:362) Error: at com.google.command.dexer.Main.processFileBytes(Main.java:346) Error: at com.google.command.dexer.Main.processOne(Main.java:237) Error: at com.google.command.dexer.Main.processDirectory(Main.java:264) Error: at com.google.command.dexer.Main.processOne(Main.java:225) Error: at com.google.command.dexer.Main.processAllFiles(Main.java:169) Error: at com.google.command.dexer.Main.run(Main.java:126) Error: at com.google.command.dexer.Main.main(Main.java:107) Error: at com.google.command.Main.main(Main.java:51)

Comment by paul.bou...@sundog.net, Jun 23, 2008

I get the following error:

... AndroidManifest?.xml line 5: Tag <activity> missing required attribute name

Here is line 5: <activity class="HelloWorld?" android:label="Hello World!">

This is what was generated by the plugin when I created a new Activity. NOt sure what it is missing...

Comment by paul.bou...@sundog.net, Jun 23, 2008

Fixed the attribute problems. Looks like activity, action and category all required an android:name attribute.

Now it makes just fine, but doesn't do anything when I run it... the emulator comes up but there is no trace of my program...

Comment by bdleitner80, Aug 06, 2008

I followed the instructions and can't run the demo: Information:Compilation completed with 55 errors and 0 warnings Information:55 errors Information:0 warnings Error:ERROR: Unknown command 'compile' Error:Android Asset Packaging Tool Error:Usage: Error: aapt list? -v? -a? file.{zip,jar,apk} Error: List contents of Zip-compatible archive. Error: aapt dump? WHAT file.{apk} [asset ...?] Error: permissions Print the permissions from the APK. Error: resources Print the resource table from the APK. Error: configurations Print the configurations in the APK. Error: xmltree Print the compiled xmls in the given assets. ... and more.

Comment by SunMSCHN, Aug 23, 2008

There are many changes in the lastest version of Android SDK. So we need to modify AndroidManifest?.xml as follows: <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="hello.android"> <application android:icon="@drawable/icon">
<activity android:name="HelloAndroid?" android:label="Hello, Android!">
<intent-filter>
<action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>

It just changed 'class' and 'android:value' into 'android:value'. Now the demo works!

Comment by t.greenwoodgeer, Sep 05, 2008

Broken Plugin

The intellij plugin seems to be broken with this combination:

------------------------------------
MAC OS X 
IDEA 7.0.4 | JDK 1.5.0_13
Android SDK 0.9 beta
Intellij Plugin : android_0.1.1.zip
------------------------------------

I've noticed that the commands that are being issued to both tools/aapt and tools/dx seem to be out-of-date.

1. aapt

<<< /Users/todd/bin/android/android-echo-only/tools/aapt package -f -c -M /Users/todd/IdeaProjects/android-demo/AndroidManifest.xml -S /Users/todd/IdeaProjects/android-demo/res -I /Users/todd/bin/android/android-echo-only/android.jar /Users/todd/IdeaProjects/android-demo/out/production/android-demo/android-demo.apk.tmp
>>> /Users/todd/bin/android/android-echo-only/tools/aapt.orig package -f  -M /Users/todd/IdeaProjects/android-demo/AndroidManifest.xml -S /Users/todd/IdeaProjects/android-demo/res -I /Users/todd/bin/android/android-echo-only/android.jar /Users/todd/IdeaProjects/android-demo/out/production/android-demo/android-demo.apk.tmp

2. dx

<<< /Users/todd/bin/android/android-echo-only/tools/dx -JXmx384M --dex --output=/Users/todd/IdeaProjects/android-demo/out/production/android-demo/classes.dex --locals=full --positions=lines /Users/todd/IdeaProjects/android-demo/out/production/android-demo
>>> /Users/todd/bin/android/android-echo-only/tools/dx.orig -JXmx384M --dex --output=/Users/todd/IdeaProjects/android-demo/out/production/android-demo/classes.dex  --positions=lines /Users/todd/IdeaProjects/android-demo/out/production/android-demo

By 'seems to be incorrect', I mean that the respective tool gives a warning stating such. I have created some simple python scripts to munge the commands to aapt and dx and forward the correct commands on to the original tools. However, I'm still stuck b/c the apk.tmp file is not being created.

Note: I have successfully created android apps using eclipse and the eclipse plugin on windows, linux, and mac os x. It seems that the Intellij plugin is seriously behind the eclipse plugin right now.

Comment by t.greenwoodgeer, Sep 23, 2008

From an email I had with Dmitry Jemerov <intelliyole@gmail.com>, you can see that:

  1. This plugin has not been updated for android 0.9
  2. The source is available if you want to update it yourself
  3. Dmitry will accept patches

-Todd


Hello Todd,

Unfortunately I don't receive any notifications about comments to the Getting Started page, so I didn't see your post (or any others, for that matter).

The plugin is not "totally broken on Mac OS X" - it was never updated for compatibility with the 0.9 SDK release on any platform.

And the source is of course available: http://code.google.com/p/idea-android/source/checkout
If you send me a patch updating the plugin for compatibility with the 0.9 SDK version, I'll be happy to check it in and release an updated build of the plugin.
Comment by raulraja, Sep 24, 2008

Same problem as t.greenwoodgeer, I'm gonna have to go with eclipse + ADT for now

Comment by dhoffer6, Oct 05, 2008

Can't compile with IDEA 7.0.4 and Android SDK 1.0r1. I gather from previous posts this may be due to SDK changes? Any idea when this plug-in will be updated?

Comment by ildar.karimov, Oct 15, 2008

Have anyone managed to fix or at least to compile the plugin? I'm getting com.intellij.ide.util.newProjectWizard doesn't exist among with other errors. Maybe something wrong with my Plugin SDK instalation?

Comment by KeHTaBp, Oct 21, 2008

same problem as dhoffer6...

Comment by cowb...@thefrontside.net, Oct 23, 2008

It appears that the source on trunk targets the 8.0 plugin api. I don't know much about the open api, but I've tried backporting it to 7.0.4

I've gotten it to compile, but whenever I try to create a project with and Android facet, I get the following error:

Error adding module to project: null

Unfortunately I don't know where to even get a stack trace for this exception.

Comment by cowb...@thefrontside.net, Oct 25, 2008

Well, I give up, for now. I got it to compile, start the android simulator, but for some reason

1) it is not packaging the application into the .apk as part of the run profile. 2) it doesn't persist the android facet for subsequently re-opening the project.

Here it is, if anyone wants to take it a bit further.

http://github.com/cowboyd/idea-android-selena/tree/master

Comment by matt.weatherford, Nov 03, 2008

If this plugin "was never updated for compatibility with the 0.9 SDK release on any platform" then what good is it now that we're at 1.0r1 ?

Maybe take this page down until someone updates the plugin?

Im betting some folks have wasted a lot of time on this....

Matt

Comment by michal.b...@gmail.com, Nov 08, 2008

Yes, I've tried to run it using 1.0r1 and there is no way how to do that. This plug-in is totaly out. People are working on some NetBeans? plugin here: http://kenai.com/projects/nbandroid

Comment by vkelman, Dec 04, 2008

I'm getting strange compilation error on a very first program: Error: 'C:\Program' is not recognized as internal or external command.

The only things located in 'C:\Program Files' on my WinXP machine are JDK 1.6 and Android SDK. It sounds like Android SDK does not allow space in folder names ('Program Files'}? Please help.

Comment by Sergey.Dotsenko, Jan 08, 2009

This plugin works only with Intellij IDEA 7.0.1 and android_sdk_windows_m3-rc20a, any other variants do not work.

Comment by dhoffer6, Jan 30, 2009

Can you give us a roadmap for this plugin? Is development active?

Comment by richard.walsh.work, Jun 17, 2009

Worked for me. 1. Need to create a new project 2. Create new activity as this tutorial tells you 3. Remove the "package ;" line in the R.java file that is in the /gen directory 4. Click to view the source for your hello world class 5. Right click to Run...

Thanks!

Comment by jawabean, Jun 18, 2009

This plugin doesn't work with IDEA 7.0.3 and android-sdk-windows-1.5_r2.

When I create Activity as per the tutorial, it doesn't extend Activity class. It also doesn't add the android.jar to the libraries of the project. If I try to compile it throws an error: Error:'C:\work\android-sdk-windows-1.5_r2\tools\dx' is not recognized as an internal or external command, Error:operable program or batch file.

Obviously the script dx is not there. The dir structure in the SDK is different.

Comment by cih.exe.by, Jun 18, 2009

hi i cannot compile...and can't see what a problem=\ image

Comment by GuoYibin27, Jul 12, 2009

my sdk path is D:\Program Files\Google\android-sdk-windows-1.5_r2; when i run application and i have an error like this

D:\Program is not recognized as an internal or external command;

Comment by tk7ua1678, Jul 14, 2009

Hi GuoYinbin27?,

Change the directory of your Andriod_HOME. path should not contain any space in between. Make it something like D:\Google\android-sdk-windows-1.5_r2

Comment by GuoYibin27, Jul 20, 2009

thx for you reply.

Comment by gareth.western, Sep 09, 2009

jawabean: I have the same problem as you. Did you manage to find the cause?

Comment by gareth.western, Sep 10, 2009

Actually my problem only applies for Intellij 7. The plugin seems to work correctly with Intellij 8. Guess I have to upgrade? :(

Comment by saw...@fas.harvard.edu, Nov 11, 2009

It appears that my Idea 8.1.3 does not properly integrate my android-support plugin. When creating a new project my Technologies page does not show Android as an option. Further, if I continue to make a new projected the New menu does not include Activity as an option. The android jar file is in the plugins directory and it contains the Activity class file.

Comment by kpelykh, Nov 24, 2009

I'm trying to debug Hello World application on the device, but Idea never connects with debugger to application. Idea uploads the file and starts up application, then I get "Waiting for debugger" pop up message which stays forever. I use Idea 9.0.193.

Here's what I get in debug window:

Waiting for device. Target device: HT842GZ41077 Uploading file

local path: C:\HelloWorld?\HelloWorld?.apk remote path: /data/local/tmp/com.test
Installing application. DEVICE SHELL COMMAND: pm install "/data/local/tmp/com.test" Application is already installed. Reinstalling. DEVICE SHELL COMMAND: pm install -r "/data/local/tmp/com.test" pkg: /data/local/tmp/com.test Success

Launching application: com.ktown/com.test.HelloWorldActivity?. DEVICE SHELL COMMAND: am start -D -n "com.test/com.test.HelloWorldActivity?" Starting: Intent { cmp=com.test/.HelloWorldActivity? }

here's output from Logcat:

11-24 18:39:53.261: DEBUG/ddm-heap(916): Got feature list request 11-24 18:39:53.901: DEBUG/ActivityManager?(76): Uninstalling process com.test 11-24 18:39:53.901: INFO/ActivityManager?(76): Starting activity: Intent { flg=0x10000000 cmp=com.test/.HelloWorldActivity? } 11-24 18:39:53.930: DEBUG/AndroidRuntime?(916): Shutting down VM 11-24 18:39:53.930: DEBUG/dalvikvm(916): DestroyJavaVM waiting for non-daemon threads to exit 11-24 18:39:53.941: DEBUG/dalvikvm(916): DestroyJavaVM shutting VM down 11-24 18:39:53.941: DEBUG/dalvikvm(916): HeapWorker? thread shutting down 11-24 18:39:53.941: DEBUG/dalvikvm(916): HeapWorker? thread has shut down 11-24 18:39:53.941: DEBUG/jdwp(916): JDWP shutting down net... 11-24 18:39:53.941: DEBUG/jdwp(916): Got wake-up signal, bailing out of select 11-24 18:39:53.941: INFO/dalvikvm(916): Debugger has detached; object registry had 1 entries 11-24 18:39:53.951: DEBUG/dalvikvm(916): VM cleaning up 11-24 18:39:54.011: INFO/ActivityManager?(76): Start proc com.test for activity com.test/.HelloWorldActivity?: pid=923 uid=10051 gids={1015} 11-24 18:39:54.061: DEBUG/dalvikvm(916): LinearAlloc? 0x0 used 676436 of 4194304 (16%) 11-24 18:39:54.240: INFO/dalvikvm(923): Debugger thread not active, ignoring DDM send (t=0x41504e4d l=38) 11-24 18:39:54.341: INFO/dalvikvm(923): Debugger thread not active, ignoring DDM send (t=0x41504e4d l=22) 11-24 18:39:54.351: WARN/ActivityThread?(923): Application com.test is waiting for the debugger on port 8100... 11-24 18:39:54.351: INFO/System.out(923): Sending WAIT chunk 11-24 18:39:54.351: INFO/dalvikvm(923): Debugger thread not active, ignoring DDM send (t=0x57414954 l=1) 11-24 18:40:03.936: WARN/ActivityManager?(76): Launch timeout has expired, giving up wake lock! 11-24 18:40:04.278: WARN/ActivityManager?(76): Activity idle timeout for HistoryRecord?{433ad798 com.test/.HelloWorldActivity?} 11-24 18:40:09.471: DEBUG/dalvikvm(561): GC freed 324 objects / 16400 bytes in 176ms

it's obvious that debugger detached for some reason. Any suggestions how to fix this?


Sign in to add a comment
Hosted by Google Code