Thursday, September 1, 2011

[How To] Guide to using the AVD Emulator (SDK)

[How To] Guide to using the AVD Emulator (SDK)

This will be my first, and more to come, guide in explaining how to set up the mysterious SDK and AVD Manager Emulator and using it to adb push and remove files, theming test, APK test and much more.

NOTE: This is WINDOWS set up only. Using SDK and AVD Manager. I'm currently on Windows Vista 32 bit 86x. I have not tested it on other machines nor will I test it on other machines. This set up may work on other machines but this is my set up to help get those of you to understand the basics and getting it started.

Requirements: (NOTE: Please download in following order!)

Latest version of Java java.com: Java + You (Java version 6 update 24 is latest at the start of this thread)

Latest version of JDK Java SE Downloads (JDK version Java SE Development Kit 6u24 is latest at the start of this thread) Press on the DOWNLOAD JDK button at that link.

Android SDK and AVD Manager Android SDK | Android Developers (installer_r10-windows(Recommended) ) Please download only the Recommended one for the time being.

Setting Up Java, JDK, and SDK And AVD Manager:

Install Java and then JDK onto your system. Please do not change the name of the folder(s) in the installation process. Allow it to install into the one it comes up with.

You will probably have older versions of Java and possibly JDK (if you did JDK work before). You will need to allow Java and JDK to remove the older versions and install the new versions. If something goes wrong, then post your problem and I may have a solution to help you out as I too have faced a couple of installation problems with corrective work-around.

After completing these 2 installations you may have to restart your computer. Do so for the changes to be made.

Next, install SDK And AVD Manager. You will be prompted to change the whereabouts this gets installed into. Change the target folder to C:\androidsdk You can change androidsdk to a different name if you wish, but I chose androidsdk just to make it short and noticeable on my C:\ drive. Proceed to install SDK And AVD Manager.

Next, go to your androidsdk (or whatever you named it) folder and you will see SDK Manager with the little android icon to the left of it. Click on it and allow everything to set up. Select on Available Packages, select the packages you want to install and then click on Install Selected. If Choose Packages screen comes up automatically then click on Accept All and click on Install. This may take a bit so go read the news on CNN or something till it is done.

Next step: Environment Variables

Environment Variables: (Note: Java, JDK, and SDK And AVD Manager will not work together if you do not establish variables for these)

(thanks to: xKape for variable establishments in (So you want to edit xml's or more... an ADB. APK Manager How-To (Basics))

On your Windows screen, click on Start, right click Computer (or My Computer), click on Properties, click on Advanced system settings on left side, you will be prompted by Windows for permission and click OK, if you aren't on the Advanced tab the please click on that tab, click on Environment Variables and do as following:

User variables for YourName:

click on new

Variable name: adb
Variable value: C:\androidsdk\platform-tools\adb

click ok

System variables:

scroll down to Path
double click on Path or you can just click Edit button

This is what mine looks like:

%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\Sy stem32\Wbem;C:\Program Files\Common Files\Roxio Shared\DLLShared\;C:\Program Files\Common Files\Roxio Shared\10.0\DLLShared\;C:\Program Files\QuickTime\QTSystem\;%SYSTEMROOT%\System32\Wi ndowsPowerShell\v1.0\;C:\Program Files\Java\jre6\bin;C:\Program Files\Java\jdk1.6.0_24\bin;C:\androidsdk\platform-tools;C:\androidsdk\tools

Note:
the lines I bolded are what you need to put in the variables. You will probably have to change according to your folder structure. Make sure Java's bin and JDK's bin are targeted as shown. Please make sure you edit as it show on your folder structures, otherwise it will not work. You can use my example to make sure the structured folders are covered.

Note: in c:\androidsdk\tools folder it may have a file that is named adb_has_moved you will need to download this:

MEGAUPLOAD - The leading online storage and file delivery service

and extract to c:\androidsdk\tools

this will provide a working adb.exe, AdbWinApi.dll, and AdbWinUsbApi.dll for use in your tools folder.

After establishing variables click on Ok, click on Ok again. Save any unsaved work and then close all programs and restart your computer.

You should have everything established by then. Let's run some test...

Open up your Command Prompt (can be found in Start>All Programs>Accessories>Command Prompt. Or just pushing Winkey+R and type cmd)

In Command Prompt type this:

java -version

it should say something like this after entering it:

java version "1.6.0_24"
java SE Runtime Environment
Java HotSpot Client VM

Next, type this:

javac -version

it should say something like this after entering it:

javac 1.6.0_24

If you see those 2 lines then you're all set! These lines are basically echoing to java for version and build to see if it exist. Exit out of Command Prompt or type exit and then enter.


Next, we will be setting up the Emulator. This can be very tricky, so trial and error are the concept of learning to get it to work properly. Please feel free to post some issues and I may be able to help you solve the problem.

1: open up Android SDK And AVD Manager (remember its in androidsdk or whatever folder you named it. it should also be on Start>All Programs>Android SDK Tools> SDK Manager
2: Click on Virtual Devices in the left pane
3: Click on New... on the right side. A big box will come up. We will do just basic info on it just to get started and learn from

Name: you will name your AVD and it can be whatever you want. Example: EmulatorProject_v1
Target: this is the difficult part. we want to keep up with the current version of what platform our Android Device is running on. I go back and forth on Android 2.3.3 - API Level 10 and Android 3.0 - API Level 11. This part is also crucial because you will need to use the right system.img for both platform. So pick one of these and stick with it for now. We will get to the system.img in a bit.
SD Card: this option is also crucial which helps your emulator be able to build on. without this you will get "No SD Card found" errors. We will stick to Size for the time being. I would recommend it to be in MiB rather than KiB (MiB is megabyte and KiB is kilobyte). Minimum MiB is 9, if you push MiB to be over 500 you will have a sluggish machine and a very long waiting period for everything to load up. So, stick to 100 to 500 MiB for safe range.
Snapshot: check box to enable it
Skin: use built-in default for now
Hardware: you will see a few selections coming up after entering info stated from above. It is imperative you click on the New... button. We need SD Card Support in order for our SD Card's hardware to function properly.

When finished, click on Create AVD. It will then begin to create the AVD Emulator and it will save into your C:\Users\Your Name\.android\avd\YourEmulatorName

Exit out of the Android SDK And AVD Manager. Let's go get the rest of the Emulator running.

4:
We need to copy system.img to C:\Users\Your Name\.android\avd\YourEmulatorName folder by doing this, you need to remember what platform you chose when you made your AVD. Here's the 2 locations according to whichever platform you chose:

if it is...

Android 2.3.3 - API Level 10:

go to c:\androidsdk\platforms\android-10\images folder and right click on system and click on Copy

now go to c:\Users\Your Name\.android\avd\YourEmulatorName folder and then right click anywhere in that folder and click paste. You should see a system.img file get pasted in there. Minimize your folder for now.

if it is...

Android 3.0 - API Level 11:

go to c:\androidsdk\platforms\android-11\images folder and right click on system and click on Copy

now go to c:\Users\Your Name\.android\avd\YourEmulatorName folder and then right click anywhere in that folder and click paste. You should see a system.img file get pasted in there. Minimize your folder for now.

5: Let's download these 2 files:

Vending.apk: Vending.apk

GoogleServicesFramework.apk
GoogleServicesFramework.apk

6: Put both Vending.apk and GoogleServicesFramework.apk into c:\androidsdk\tools folder

7: Open up Command Prompt (make sure you right click Command Prompt before opening and click Run as Administrator)

type the following lines:

cd c:\androidsdk\tools (hit enter)
emulator -scale .75 -avd youremulatorname -partition-size 128 (hit enter)

This will launch your emulator. The use of -scale .75 redefines the screen size. If you do not include -scale then you will have an oversized emulator. Also note this, if you use partition size 96 you may get "Out of memory" errors. Try to keep partition size at 128 for stablization.

Note: Please wait till your Emulator is fully running and you see the home screen and everything is loaded up before proceeding to step 8.

8: Launch another Command Prompt. Make sure you keep your original Command Prompt open still.

type the following lines:

cd c:\androidsdk\tools (hit enter)
adb -s emulator-5554 shell (hit enter)
mount (hit enter)

Look for this line:
/dev/block/mtdblock0 /system yaffs2 ro 00

type the following lines:

mount -o remount,rw -t yaffs2 /dev/block/mtdblock0 /system
(hit enter)
chmod 777 /system/app (hit enter)
exit (hit enter)

Once you typed exit it should go back to c:\androidsdk\tools

Note: You may need to replace 5554 with your emulator serial number. Just look at the top of your running emulator for the serial number to replace. If it is 5554 then use 5554, if not, then change it before you use the adb line shown above.

9: ADB pushing to your /system/app Emulator. We will be pushing Vending.apk and GoogleServicesFramework.apk to /system/app section.

On your Command Prompt you were just on type the following lines in:

adb -s emulator-5554 push Vending.apk /system/app/. (hit enter)

Note: yes there is a PERIOD (.) after /system/app/. <----- when entering in that line

If adb push is successful you should see a single line showing how fast it pushed the APK. Like this:

198 KB/s <780456 bytes in 3.845s>

type in the following lines:

adb -s emulator-5554 push GoogleServicesFramework.apk /system/app/.

If adb push is successful you'll see similar results

10: We need to remove a couple of files:

SdkSetup.apk from /system/app if not removed then your SDK will be restored right back to the beginning in a new session.

type in the following lines in Command Prompt you were just using:

adb shell rm /system/app/SdkSetup.apk (hit enter)

It will now be removed.

11: Close your Emulator
12: Go to your c:\Users\Your Name\.android\avd\YourEmulatorName folder and delete these 2 files:

userdata-qemu.img
cache.img

13: All finished! Now you can launch your Emulator from the Android SDK And AVD Manager by click on your Emulator name and then click on the Start button.

Side Notes:

You can continue to push new APK(s) on top of the existing APK on your Emulator. I have been running test for a pull but apparently that is not necessary to do an adb pull. If you need to get rid of the APK for error issues then I recommend this:

type in the following lines:

cd c:\androidsdk\tools (hit enter) (if you are not in this path then you need to be)
adb shell rm /system/app/NameofAPK.apk (hit enter)

To replace with a fresh APK or existing working APK work:

type the following lines:

adb -s emulator-5554 push NameofAPK.apk /system/app/. (hit enter and you will have a fresh original APK in the emulator)

If you have any questions, just leave a post here and I'll be around to answer what I can.


***Linux Users Please Click Link Below***

How to Theme With the Emulator

(thanks to czerdrill for providing the link for Linux users)

No comments:

Post a Comment