2) ten minutes to learn about android-create the first APP, execute the Android program, and android-android

Source: Internet
Author: User

2) ten minutes to learn about android-create the first APP, execute the Android program, and android-android

A Hello World project for Android was created in the previous lesson. The project contains a series of source files by default, which allows us to run the application immediately.

How to run an Android app depends on two things: whether there is an Android device and whether the Android Studio development program is in use. This tutorial teaches you how to install and run applications on real Android devices or android simulators using android Studio and command line.

Run on real devices

If you have a real Android device, follow these steps to install and run the application on your device:

Mobile phone settings

Note:Starting from Android4.2,Developer optionsIt is hidden by default. To make it visible, you can goSettings> about mobile phone (or device)ClickVersion NumberSeven times. Then return to findDeveloper options.

Run a program from Android Studio

Android Studio installs the application on our device and starts the application.

Install and run the application from the command line

Open the command line and switch the current directory to the root directory of the Andriod project. Use Gradle to compile the project in debug mode and run the gradle script to execute assembleDebug to compile the project. After the execution, myfirstapp-debug.apk is generated in build/directory.

In Windows, run:

gradlew.bat assembleDebug

In Mac OS or Linux:

$ chmod +x gradlew$ ./gradlew assembleDebug

After compilation, the apk is generated in the app/build/outputs/apk/directory.

Note:The chmod command adds the execution permission to gradlew and only needs to be executed once.

Make sure thatplatform-tools/Path already added to Environment VariablePATH, Run:

adb install bin/MyFirstApp-debug.apk

Find MyFirstActivity in our Android device and click open.

Run on Simulator

Whether using Android Studio or command line, you must first create an Android Virtual Device (AVD) to run a program in the simulator ). AVD is the configuration of the Android simulator, which allows us to simulate different devices.

Create an AVD:

1. Start Android Virtual Device Manager (AVD Manager) in two ways:

* Use Android Studio, ** Tools> Android> AVD Manager **, or click Android Virtual Device Manager in the toolbar! Export image](avd-manager-studio.png); * in the command line window, switch the current directory to '<sdk>/tools/' and execute:
android avd

2. In the AVD Manager panel, clickCreate Virtual Device.

3. In the Select Hardware window, Select a device, such as Nexus 6, and clickNext.

4. Select the appropriate system image.

5. Check the simulator configuration and clickFinish.

For more information about AVD, see manage AVDs with AVD Manager.

Run the program from Android Studio:

1. Select the project to run in Android Studio and select from the toolbarRun;

2.Choose DeviceWhen the window appears, selectLaunch emulatorSingle region;

3. SlaveAndroid virtual deviceSelect the created simulator from the drop-down menu and clickOK;

It takes several minutes for the simulator to start. After the simulator is started, unlock it and you will see that the program has been running on the simulator screen.

Install and run the application from the command line

1. Use the command line to compile the application and generate an apk in app/build/outputs/apk;

2. Confirm that platform-tools/has been added to the PATH environment variable;

3. Execute the following command:

adb install app/build/outputs/MyFirstApp-debug.apk

4. Find the MyFirstApp on the simulator and run it.

The above is the whole process of creating and running an application on the device!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.