Java eclipse with android

Android + Eclipse Simple Example Step by Step

In this page we will quick start an android application using eclipse. To run the application, eclipse can be integrated with Android Virtual Device that will behave as Android Emulator. Application can be deployed as Android Application Package (apk) file. Application LOG can be seen in console and Android Virtual Device LOG will be available in LogCat. Here we will discuss step by step the creation of simple application of android using eclipse.
We will focus on below points.

1. Perquisites to Run the Application
2. Create Android Simple Application
3. Create Android Virtual Device to Run the Application
4. Check Log in Console and LogCat
5. Install Android Application (APK file) in Android Mobile Phone

Perquisites to Run the Application

Before starting the demo you should be ready with development environment. Find the perquisites to run the application.

1. There should be JDK 6 or above version in your system.
2. Your favorite up-to-date Eclipse Version
3. Go through the link to setup Android in Eclipse before starting the demo.

Create Android Simple Application

We will create a simple android application starting from wizard. For fast learning you can download the project given on bottom and import it as Android Project from Existing Code and run as Android application. Ensure that you have created Android Virtual Device already.

Читайте также:  Выберите операции языка javascript возвращающие логический результат

Go to File->New->Other and search for Android Application Project.

Android + Eclipse Simple Example Step by Step

Android + Eclipse Simple Example Step by Step

Application Name is that name which will appear in the Mobile or Emulator after deployment. Click on the next and next and leave all the default setting as such. Finally click on the finish button. In your eclipse you will able to see your project as below.

Android + Eclipse Simple Example Step by Step

package com.concretepage.cpandroid; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; public class CpActivity extends Activity < public void onCreate(Bundle savedInstanceState) < super.onCreate(savedInstanceState); TextView text = new TextView(this); text.setText("Concretepage.com: This is First Android App. "); setContentView(text); >>

This is activity class which extends android.app.Activity class. This is the class which contains methods that will run when our will application run. Define onCreate() method for demo.

Now replace AndroidManifest.xml by below code. This xml keeps all the information related our application.
AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.concretepage.cpandroid" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="7" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name=".CpActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>

Create Android Virtual Device to Run the Application

Eclipse has Android Virtual Device that works like an emulator to run and test the android application. Find the steps to create the Android Virtual Device.

Click on the Window->Android Virtual Device . You will be able to see below scree.

Android + Eclipse Simple Example Step by Step

Initially there will be no row for AVD. You need to create it. Click on create button and fill the data as below.

Android + Eclipse Simple Example Step by Step

To run the application. Start the AVD and then go to your application and right click then go to
Run As->Android Application You will be able to see below screen.

Android + Eclipse Simple Example Step by Step

Your app has been deployed in AVD. You can also check the ICON of your Demo android app in AVD that will look like below.

Android + Eclipse Simple Example Step by Step

Check Log in Console and LogCat

There will be two log. One is eclipse console log that will provide start+ deployment + stop of the application. LogCat is detail log of the Android Virtual Device, which will display all the action being performed in the device in detail. The console log will look like below.
Console.log

[2014-08-03 19:11:16 - CPAndroid] Android Launch! [2014-08-03 19:11:16 - CPAndroid] adb is running normally. [2014-08-03 19:11:16 - CPAndroid] Performing com.concretepage.cpandroid.CpActivity activity launch [2014-08-03 19:11:16 - CPAndroid] Automatic Target Mode: using existing emulator 'emulator-5554' running compatible AVD 'AVDOne' [2014-08-03 19:11:19 - CPAndroid] Application already deployed. No need to reinstall. [2014-08-03 19:11:19 - CPAndroid] Starting activity com.concretepage.cpandroid.CpActivity on device emulator-5554 [2014-08-03 19:11:22 - CPAndroid] ActivityManager: Starting: Intent < act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.concretepage.cpandroid/.CpActivity >
08-03 12:38:25.590: E/AndroidRuntime(823): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2161) 08-03 12:38:25.590: E/AndroidRuntime(823): . 11 more 08-03 12:38:28.860: I/Process(823): Sending signal. PID: 823 SIG: 9 08-03 12:41:10.450: D/gralloc_goldfish(868): Emulator without GPU emulation detected. 08-03 12:47:52.230: I/Choreographer(868): Skipped 107 frames! The application may be doing too much work on its main thread.

Install Android Application (APK file) in Android Mobile Phone

You can also install your android application to any android mobile phone. Find the below steps.

1. Find the .apk file. In our demo, go to bin directory and you will get CPAndroid.apk file .
2. Transfer this apk file from your PC to mobile.
3. Click to install and it will be installed as a normal android application.
4. Go to mobile phone menu. You will be able to see the icon of your app. Our demo apk file will create the icon with the name CPAndroid .
5. Click CPAndroid icon to run the demo android app.

To build android project using maven, find the another post. Build Android Project with Maven

Источник

Java eclipse with android

Eclipse for Android Developers

Package Description

An IDE for developers creating Android applications.

This package includes:

  • Eclipse Git Team Provider
  • Eclipse Java Development Tools
  • Maven Integration for Eclipse
  • Mylyn Task List
  • Code Recommenders Tools for Java Developers
  • Eclipse XML Editors and Tools
  • org.eclipse.andmore.android.basic.feature
  • org.eclipse.andmore.ndk.feature
  • org.eclipse.andmore.hierarchyviewer.feature
  • org.eclipse.andmore.traceview.feature
  • org.eclipse.andmore.gldebugger.feature
  • org.eclipse.buildship
  • org.eclipse.egit
  • org.eclipse.egit.import
  • org.eclipse.egit.mylyn
  • org.eclipse.epp.package.common.feature
  • org.eclipse.equinox.p2.user.ui
  • org.eclipse.help
  • org.eclipse.jdt
  • org.eclipse.jgit
  • org.eclipse.m2e.feature
  • org.eclipse.m2e.logback.feature
  • org.eclipse.mylyn.context_feature
  • org.eclipse.mylyn_feature
  • org.eclipse.mylyn.bugzilla_feature
  • org.eclipse.mylyn.git
  • org.eclipse.mylyn.hudson
  • org.eclipse.mylyn.ide_feature
  • org.eclipse.mylyn.java_feature
  • org.eclipse.mylyn.wikitext_feature
  • org.eclipse.platform
  • org.eclipse.rcp
  • org.eclipse.recommenders.rcp.feature
  • org.eclipse.recommenders.snipmatch.rcp.feature
  • org.eclipse.recommenders.mylyn.rcp.feature
  • org.eclipse.wst.xml_ui.feature

Maintained by: Eclipse Packaging Project

Windows 32-bit: MD5 — SHA1 — SHA512
Windows 64-bit: MD5 — SHA1 — SHA512
Mac OS X (Cocoa) 64-bit: MD5 — SHA1 — SHA512
Linux 32-bit: MD5 — SHA1 — SHA512
Linux 64-bit: MD5 — SHA1 — SHA512

Bugzilla

Bug ID Title Status
512672 DDMS files not found — org.eclipse.andmore.ddms NEW
530999 Cannot execute Eclipse.exe after extract NEW
512671 Unable to execute early startup code for the org.eclipse.ui.IStartup NEW
512670 Problems occurred when invoking code from plug-in org.eclipse.ui.workbench NEW
493641 [Welcome] Adopt Solstice theme for Android package NEW
496792 I see errors when i open eclipse for android . NEW
492475 Error when loading the sdk NEW

Bugs listed in italics indicate the bug has been moved to another project.

Bug ID Title Status
495378 Add incubation to Android Neon Package CLOSED

Bugs listed in italics indicate the bug has been moved to another project.

Источник

Оцените статью