Android Tutorial Hello world - Installing Android Emulator

Please follow the installation (and configuration) instructions if you have not done it yet:
http://www.b4x.com/android/downloads.html

In this tutorial we will create a new AVD (Android Virtual Device) which is an emulator instance. Then we will create a simple program that displays a simple message box and also writes a message to the log.
You can also connect a real device to the IDE:
Connecting your device with B4A-Bridge
Common issues are listed at the end of this post. If you encounter an error that is not listed or that you are unable to solve, please contact [email protected]

Create new AVD

- Run Basic4android.
- Choose Tools Menu - Run AVD Manager.
Wait a few seconds.
- The SDK Manager may appear depending on the version and configuration. You should choose Tools - Manage AVDs.

newavd.png


- The AVD Manager should appear:

avd_manager_empty.png


- Choose New and fill the fields similar to the following image (it is recommended to choose HVGA) :

SS-2013-04-08_10.51.28.png


- Press on Create AVD.
- Note that you can create more than one AVD. Each can have a different resolution or can target a different API version (you will need to install additional platforms first).
- Now press Start in order to start the emulator
emulator_start.png


- You will see several windows popping up and disappearing. This is fine.
- The emulator should boot up:

emulator1.png


Wait... on the first time it can take several minutes till the emulator is ready.

The emulator is ready when it gets to this screen:
emulator2.png


You may see this screen, which is the lock screen, instead:
emulator_locked.png


Drag the lock icon to the right to unlock the device.

Note that there is no need to restart the emulator each time you deploy a program. The emulator can be kept running all the time.

If you are not familiar with Android you can play with the emulator. Press on the button with the small squares to get to the application page.

Troubleshooting: If you get an error message similar to:
invalid command-line parameter: Files\Android\android-sdk\tools/emulator-arm.exe.
Hint: use '@foo' to launch a virtual device named 'foo'.

Then you should reinstall Android SDK in a path without spaces, such as c:\android.


Writing your first Basic4android program

- As this is a new program we should first set its location by choosing File - Save.
It is highly recommended to save each project in its own folder.
- Create a new folder: "Hello world", open the folder and save the program as "Hello world".

- Write the following code under Sub Activity_Create:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    Log("Hello world!")
    Msgbox("Hello world?", "First program")
End Sub
- Press F5 to compile and deploy your program to the emulator.
The package dialog should appear (empty):

package_dialog.png


Each Android application is identified by a unique package string.
This is a string built of several parts separated with periods.
The string should include at least two parts. You cannot install two applications with the same package on one device.
Note that you can always change the package name (and the label) under tools menu.

- Enter a package name.
- Next you will be asked to enter the application "label". This is the application name that the user will see.

Your program will now be compiled and installed to the emulator:

hello_world_success.png


The emulator is significantly slower than a real device.
In many cases it is more convenient to work with a real device as the installation is much faster.

Note that you can always redeploy your program. There is no need to close the running program on the emulator.

Tracking the log with LogCat

Android devices keep an internal buffer of log messages. These messages can be very handy for debugging.

To view the logs you should switch to the Logs tab in the right pane and press connect:
hello_world_logcat.png


There are two "Hello world!" messages in the screenshot as I ran the program twice.
Unchecking "Filter" will show all available messages (not just messages relevant to your program).

Hello world :)

Common issues
- "emulator: ERROR: no search paths found in this AVD's configuration
weird, the AVD's config.ini file is malformed. Try re-creating it."
This error happens when you have non-ASCII characters in your Windows user name. Android SDK fails to find the proper path.
The solution is to create a folder named: c:\android
And to add an environment variable named ANDROID_SDK_HOME with the value of c:\android.

- "invalid command-line parameter: Files\Android\android-sdk\tools/emulator-arm.exe.
Hint: use '@foo' to launch a virtual device named 'foo'." This error sometimes happen when you install Android SDK in a path with spaces. Copy the SDK to C:\Android and update the paths configuration to solve it.
 

m0hammed

New Member
Hi
Im having exactly the same problem. Im using eclipse but whn i run my first application it returns "emulator : cannot find virtual device named my_avd"

My android sdk is in
C:/ program files/ android-sdk-windows

My avd folder is in
C:/users/<username>/documents/.android

Ive also tried putting android sdk iin
C:/users/<username>/documents

Still same error message
Please help
 

m0hammed

New Member
Any possible ideas?
I am struggling with this.
I think if i get the emulator running i can acually get some programing started.
Im using eclipse if tht helps.
 

James Moxham

Member
Licensed User
Longtime User
Hi MOhammed,

Have you got an emulator running?

Tools/Run AVD manager
Then select the first one and click "start"

And then wait. and wait. and wait about 4minutes until you have the screen on the emulator with a picture of the sea.

Then it should connect.

I've found it a lot quicker to program to a real android device rather than the emulator. Downloads using wifi are only about 10 seconds.
 

markdude

New Member
Hey mikejsmith1985,
I'm running windows xp on my virtual machine on my mac as well, and I have this problem on the emulator. Where did you change this paths for the Emulator? Where should I add //psf ?

Regards,
Markdude
 

mshihrer

Member
Licensed User
Longtime User
Phone "Skins"

Hey all, my first post. I didn't see this mentioned, but it is possible to load "skins" of your actual phone in B4A.
I have a Motorola Bravo MB520 (Kobe) phone. I went to this site, and signed up as a developer, its free:
MOTODEV
Once I signed up, I was given access to the downloads. The skins are under Docs & Tools/Additional Tools & Resources.
I downloaded the file for the Bravo, unzipped it (in this case, they forgot to put the .zip extension to the file. I just renamed it, and all was good) and placed it into the C:\Program Files\Android\android-sdk-windows\add-ons folder. Then, in B4A, I ran the AVD manager, and selected the "new" button, and in the next window, selected the "Kobe" sdk. I named it Bravo, and then hit "start", and I had an emulator that looked like my phone, with proper display settings. I can also tell you the B4A designer works, as well. I haven't tried to deploy to my phone, just yet, but I bet all is good. I'll let you know when I get there. I can see this as handy for targeting specific phones, even if you don't have them.

edited to add:
One thing though, it doesn't emulate the MotoBlur application that is forced on this device. So, instead of 7 home screens, there are only three.
 
Last edited:

JogiDroid

Member
Licensed User
Longtime User
edited to add:
One thing though, it doesn't emulate the MotoBlur application that is forced on this device. So, instead of 7 home screens, there are only three.

If I remember right it is just a skin, so emulation does not change...
 

SJD

New Member
Hi All :)
It's my first post to forum. Today I installed and tried emulator B4A (I have any real device not yet) according to here described progress. It looked ok but the final result was one big "nothing". I reran it several times ...

I attached two descriptive (I hope) pictures.
Any idea is greatly appreciated :sign0085:

Best Regards,
Svat
 

Attachments

  • screenshot4.jpg
    screenshot4.jpg
    40 KB · Views: 312
  • screenshot2.jpg
    screenshot2.jpg
    19.8 KB · Views: 301

SJD

New Member
Hi Erel,

Yes, it didn't! Only the "Big Black Barrens" (except the name)

Best Regards,
Svat
 

SJD

New Member
:signOops: Your second tut is running right for me ... and the first ...ehm... is running right too

I forgot that I have to close the application and only then it run again
now I can see it at this log: ** Activity (main) Pause, UserClosed = false **
(the right log should be: ** Activity (main) Create, isFirst = true ** )

Probably I processed insensibly the first dialogbox and this was a start of the comedy...

:sign0013:. Thank you again for your advice and time !

Best Regards,
Svat
 

ethanpil

New Member
I want to suggest you add something to this hello world. This took me an hour to figure out. I couldnt find it anywhere in the documentation.

For probably everyone developing an app that wants to actually use a GUI, these are the steps necessary to actually show an Activity screen with Views that has been made with the Designer:

[For newbies this means "How to actually display the GUI on the device"]

Sub Activity_Create(FirstTime As Boolean)

Activity.LoadLayout("Test") 'Replace Test with the name of the Activity (GUI) that has been designed

End Sub
 

Gary Miyakawa

Active Member
Licensed User
Longtime User
I've just installed the full version (1.30) and bumped into an issue getting adb.exe to run.... I've setup the paths correctly but get an error that Basic4Android can't find adb.exe ..

I've checked and it's not in the "tools" directory but in the "Platform-tools"... I've browsed to the directory and set that up in the configuration paths but when I try to restart the adb.exe I get an error message that adb.exe can't be found....

The message box that comes up says:
"An error occurred. Cannot find: C:\Program Files (x86)\Android\android-sdk-windows\tools\..\platform-tools\adb.exe" ....

Not sure where the "tools" is coming from because I've removed it from the configuration path...

I need a little bit of assistance on this one.

Thanks,

Gary M
 

aklisiewicz

Active Member
Licensed User
Longtime User
when running this example I get TIMEOUT ERROR. I tried several times, with the same result.
Even with the Emulator already started and ready....
I'm really surprised. So what is it going to take to compile and package an App with 10000 lines of code?
-------------------------------------------------------------------------
ZipAlign file. 0.86
Installing file to device. Error
Process timed out.
Restarting ADB Server may solve this problem.
Tools - Restart ADB Server. Device serial: emulator-5554

ANY CLUE ?
Art
 
Last edited:
Top