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.
 

Avon

Member
Licensed User
Longtime User
Erased and created a new AVD as described above, but with HVGA instead of the nonstandard 640x640. problem went away.
 

Civilsitis

New Member
Could not open AVD

I follow the tutorial about installing Android SDK but when i press

START i take the error


PANIC: Could not open AVD config file: E:\Documents and Settings\Γιάννης\.android\avd\john.avd/config.ini


The unknow word in the path its Greeks from some reason appears this way. I dont think this is the problem cause when i change the path which SDK read the AVD file, I take the same message.
My OS is Windows XP pro and I change the path from Control Panel -> System -> Enviroment Variables.

PLEASE HEEELP :sign0085:
 
Last edited:

Civilsitis

New Member
Solution

I install Windows 7 , all programms install in drive C: and everything works fine :sign0060:

I am starting programming my first App - thanks for develop B4A :sign0098:
 

Civilsitis

New Member
Running problem

Hi again

I dont know what i am doing wrong.

I make my app with the emulator and all its fine

Then I press "Compile (without signing). I get the msg .... "Compile sucesfull and no errors, but my emularor is in design mode and cant test my app :sign0085: :sign0085: :sign0085:
 

Cygnus

New Member
Licensed User
Longtime User
I cannot get the Hello World app to run.

I am trying to use the emulator, I have a fairly powerful Windows 7 desktop pc fyi.
I carefully installed B4A using the tutorial, and have SKD Platform Android 2.2, API 8, revision 3 installed to c:\android

I get the following error:

Compiling code. 0.08
Generating R file. Error
Cannot find: C:\Android\android-sdk\platforms\android-8\tools\aapt.exe
Please configure paths (Tools - Configure Paths).

Here are my paths configurations:
javac.exe: C:\Program Files\Java\jdk1.6.0_21\bin\javac.exe
android.jar: C:\Android\android-sdk\platforms\android-8\android.jar

The folder it cannot find does not exist. I have read this entire thread. Some folks have reported "finding" the tools folder elsewhere and moving it to get this to work.

I do have a "tools" folder in C:\Android\android-sdk\tools. However, it does not contain the aapt.exe file either.

Help?

Edit: I tried copying the "tools" folder from C:\Android\android-sdk\tools to C:\Android\android-sdk\platforms\android-8\ just for grins. Same error.

Edit2: Using search, aapt.exe is not found on my pc anywhere.

Edit3: I have read these threads on the topic as well which did not help.
http://www.b4x.com/forum/basic4android-updates-questions/10675-missing-file-aapt-exe-moved-location.html
http://www.b4x.com/forum/basic4android-updates-questions/7938-missing-file-aapt-exe.html
 
Last edited:

Kevin

Well-Known Member
Licensed User
Longtime User
Hmmm. You are missing some files, but I don't know exactly why.

aapt.exe should be in the platform-tools folder. On my computer, it is C:\Android\android-sdk-windows\platform-tools but yours would (should) probably be in C:\Android\android-sdk\platform-tools.

A couple of things to try:

Open Android SDK & AVD Manager and click on Installed Packages. Do you see Android SDK Tools, revision x and Android SDK Platform-tools, revision x? In my case they are revision 13 and 7 respectively. If not, click on Available Packages then expand the Android Repository node and click on those two packages and install them.


Afterwards, see if the missing files are there now. If so and you still get errors when compiling, try the following (this is for XP so you'll have to figure it out on Win7):

Go to System Properties > Environment Variables. Click to edit the Path variable. Move the cursor to the far-right of the text box. What you see exactly will vary by computer but in my case the last entry was:
C:\WINDOWS\system32\WindowsPowerShell\v1.0

Add a semicolon ( ; ) and add the path to the platform-tools folder such as:

C:\WINDOWS\system32\WindowsPowerShell\v1.0;C:\Android\android-sdk\platform-tools

Substituting the actual path to your platform-tools folder. Save your changes and try again.

Hopefully something here will help. I know I followed the directions here in this forum when I got started and never had any problems. Perhaps I also installed some other files (as mentioned above) or perhaps something has changed in the Android Configuration / Setup since then. Not sure. :)
 
Last edited:

Cygnus

New Member
Licensed User
Longtime User
For some reason I was missing the package: Android SDK Platform-tools, revision x.

I added that package, updated the Android SDK Tools, revision x (since I was there), and that took care of the problem.

Not sure how this got missed, but thank you for helping me solve the problem.
 

Abubaker

New Member
when i compile HelloWorld i face this windows about configuration path

javac path
amdroid.jar
aditional labirary

i tried to upload the photo but seem it is big
anyone can help
 

johnaaronrose

Active Member
Licensed User
Longtime User
Error occurred during initialization of VM

I have the emulator running a Gingerbread 2.3.3 AVD (as that's the version used on my phone) with android-10 selected in the Path for android.jar. I had the emulator loaded & displayed OK. Press F5 (to compile & run) the 'Hello world' app resulted in asking for the 'Package name' (which I entered as 'dial2000computing.helloworld') and asking for the Label (which I guesed at as 'First program') - note that I didn't key in the quote characters. It then displayed a popup:
Compiling code. 0.02
Generating R file. 0.01
Compiling generated Java code. Error
Could not create the Java virtual machine.

Error occurred during initialization of VM

Help please!
 

johnaaronrose

Active Member
Licensed User
Longtime User
Solution

I just found a solution on the Forum:
Open the ini file which is located under:
C:\Users\<Your user name>\AppData\Roaming\Anywhere Software\Basic4android
Change this line:
MaxRamForDex=1024

To a lower value:
MaxRamForDex=256

This worked in correct compilation & execution.

However, it then stopped showing the code in the IDE (even after stopping the run) and even clicking the 'code names'. I think that the code might be showing underneath the displayed window. Any ideas to try?
 

johnaaronrose

Active Member
Licensed User
Longtime User
Issue happens every time. I have a 2GB laptop. Memory usage never gets above 1.7GB when running B4a. No paging happening.
 
Top