Android Tutorial Hello world - Installing Android Emulator

Discussion in 'Tutorials & Examples' started by Erel, Nov 3, 2010.

  1. Erel

    Erel Administrator Staff Member Licensed User

    Please follow the installation (and configuration) instructions if you have not done it yet:
    http://www.basic4ppc.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 support@basic4ppc.com

    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.

    [​IMG]

    - The AVD Manager should appear:

    [​IMG]

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

    [​IMG]

    - 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
    [​IMG]

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

    [​IMG]

    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:
    [​IMG]

    You may see this screen, which is the lock screen, instead:
    [​IMG]

    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:
    Code:
    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):

    [​IMG]

    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:

    [​IMG]

    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:
    [​IMG]

    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.
     
    luke2012, miquel and AnkitRohilla like this.
  2. derez

    derez Expert Licensed User

    Erel
    It looks easy !

    What are the tools to control where in the device the application is located after installation (which folder ?).

    What happens when you make an application that needs additional files (like images, sound, text files etc.) - how do you include them with the package for installation ?

    Another issue - I am thinking of buying A81-E which uses a resistive screen, so it cannot handle multiple touch. How will the code handle the difference between capcitive screen and resistive ?

    (more questions will follow until you give us work to do in the B4A...:))
     
  3. agraham

    agraham Expert Licensed User

    You don't and can't. Android takes care of the details of installation and deinstallation. For 2.2 and later I believe there is an option to install a package on the SD card and not internally on the device but the package has to specifically permit this. B4A packages at the moment don't include this option.

    You place them in a folder in the B4A source tree and they are included as assets in the package that you can access from your code like a normal file.

    It doesn't have to as there is no difference visible to either Android or your application.
     
  4. derez

    derez Expert Licensed User

    Thank you :)
     
  5. SarahWard

    SarahWard Banned

    Assets and memory overheads

    >> What about files and images you wish to use during runtime?
    Andrew, what happens if the program has a very large amount of these, say, MP3, JPG, TXT files? In a b4ppc program these would not affect the overall size of the program unless they were 'loaded'. Will including them as 'assets' in a b4a program increase its size massively?

    Sarah
     
  6. agraham

    agraham Expert Licensed User

    I haven't worked out what really happens when an Android package is installed nor have I worked out how assets are accessed - whether from the apk as needed or whether extracted and saved - so can only comment in general terms.

    Having a set of large assets in the package is probably undesirable as prior to Android 2.2 the apk is copied to the, usually limited amount of, internal device flash memory and installed there. The apk file is saved in flash memory, not deleted after app installation, and other data extracted from the apk is also saved. Having said this I see the popular AngryBirds game package is over 12Mbytes in size.

    If an application requests and the user permits it on Android 2.2 and later an app can be installed on the SDcard. The Android docs say "The .apk file is saved on the external storage, but all private user data, databases, optimized .dex files, and extracted native code are saved on the internal device memory." Such an app can only run while the SDcard is mounted implying to me that assets are accessed from the apk as required.

    The "Android" way of dealing with this would be to download the data from the cloud like most Google applications but not everyone has access to a 24/7 web server to host their data.

    How Basic4Android applications are installed is something that will need thinking about.
     
  7. SarahWard

    SarahWard Banned

    Thank you.

    Some of my freeware nature applications use in excess of 90mb of data. With b4ppc I simply read in the small amount of data needed for each record. Android looks like it highly prefers web-based applications when data is in use.
     
  8. agraham

    agraham Expert Licensed User

    On all Android devices I know of the SDcard looks like a USB memory stick to a desktop when the device is plugged in so you even if your app was installed from the Android Market it could look for the data on the SDcard and if missing prompt the user with a download link from which to obtain it.

    If the application is to be downloaded from your own site then you just need two components, the apk for the application and a separate data package to copy to the SDcard of the device. I don't know if it is universal on Android devices but both my devices came with a File Manager that can look at the SDcard and if you click on an apk on the card will install it. Even if a device doesn't come with this ability then as long as it can access the market (not all devices, particularly tablets, can) there are many free installers and file managers that can do so. I use ES File Explorer which seems to be acknowledged as one of the best.
     
  9. ashrafidkaidek

    ashrafidkaidek Member Licensed User

    Error ... Please Help

    i have followed the instruction above, but i'm getting an error when the compiling the program. please see attached image for details.

    any ideas ...

    image link:
    https://sites.google.com/site/ashandroid1/

    thank you
     
    Last edited: Dec 9, 2010
  10. Erel

    Erel Administrator Staff Member Licensed User

    Does adb.exe exist in the exact following path:
    C:\Program Files\Android\android-sdk-windows\platform-tools
    ?
     
  11. agraham

    agraham Expert Licensed User

    Unless you are running with UAC disabled Program Files is not a good location for the Android SDK owing to the extra protection Vista and Windows 7 give to the contents of that folder. You would be better moving your Android folder to be directly under C:.
     
  12. ashrafidkaidek

    ashrafidkaidek Member Licensed User

    No, the file dose not exists!
     
  13. Erel

    Erel Administrator Staff Member Licensed User

    You did install a platform, right (seems so according to the screenshot)?
    You can try to search for adb.exe and see if it appears in any other folder.

    You can also try to uninstall the SDK and reinstall it again.
     
  14. ashrafidkaidek

    ashrafidkaidek Member Licensed User

    Thank you Erel and everybody, i uninstalled the SDK and reinstall it again, no it is OK now
     
    jesus likes this.
  15. mikejsmith1985

    mikejsmith1985 Member Licensed User

    So I have 0 programming experience but want to start. I just got my first android phone and decided I wanted to start by writing apps for my phone. I bought Basic4android installed following all the tutorials to the T.

    Trying to walk through this tutorial for some reason every time I try to start my AVD I get these 2 messages.

    emulator: ERROR: unknown virtual device name: 'Emulator1'
    emulator: could not find virtual device named 'Emulator1'

    I have uninstalled SDK and reinstalled, I've deleted the AVD and rebuilt still same thing. Any suggestions?
    I do have the green checkmark notating "A valid Android Virtual Device"

    There must be a configuration that I have missed Just not sure what it is.

    Thanks to anyone that can point me in the right direction!
     
  16. Erel

    Erel Administrator Staff Member Licensed User

    Can you post a screenshot of the error and the AVD screen?
     
  17. mikejsmith1985

    mikejsmith1985 Member Licensed User

    I will certainly do that this evening when I get home from work!
    Thanks!
    Michael Smith
     
  18. mikejsmith1985

    mikejsmith1985 Member Licensed User

    here are the screen shots you requested.
     

    Attached Files:

  19. Erel

    Erel Administrator Staff Member Licensed User

  20. mikejsmith1985

    mikejsmith1985 Member Licensed User

    Thanks Erel, I'll check all my configs.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice