1. Best App Stores For Android
  2. Install Android On Mac
  3. Run Apple Apps On Android
  4. Android File Transfer App Mac
-->

Hi, I was using your app icon generator to generate my app icons, but unfourtunatelly, it stops to do the download of the icons, based in my image I am alwas upload a png file, with 1024 x 1024, like it was done for a long time, but now, the app stopped to open the download option. How to Create a Custom App Icon. To create a custom app icon, you’ll need a third-party launcher app like Nova Launcher, which is one of the most popular in the category. Launch the app and quickly go through the setup stage. Once you’re done, find the app you want to set a custom icon for and long-tap on it.

After an application has been coded and tested, it is necessary toprepare a package for distribution. The first task in preparingthis package is to build the application for release, which mainlyentails setting some application attributes.

Use the following steps to build the app for release:

  • Specify the Application Icon– Each Xamarin.Android application should have an applicationicon specified. Although not technically necessary, some markets,such as Google Play, require it.

  • Version the Application – This stepinvolves initializing or updating the versioning information. Thisis important for future application updates and to ensure that theusers are aware of which version of the application they haveinstalled.

  • Shrink the APK – The size of the final APKcan be substantially reduced by using the Xamarin.Android linker onthe managed code and ProGuard on the Java bytecode.

  • Protect the Application – Prevent usersor attackers from debugging, tampering, or reverse engineering theapplication by disabling debugging, obfuscating the managed code,adding anti-debug and anti-tamper, and using native compilation.

  • Set Packaging Properties –Packaging properties control the creation of the Androidapplication package (APK). This step optimizes the APK, protectsits assets, and modularizes the packaging as needed. Additionally,you can provide your users with an Android App Bundle that's optimizedfor their devices.

  • Compile – This step compiles the code andassets to verify that it builds in Release mode.

  • Archive for Publishing – This step builds theapp and places it in an archive for signing and publishing.

Each of these steps is described below in more detail.

Specify the Application Icon

It is strongly recommended that each Xamarin.Android applicationspecify an application icon. Some application marketplaces will notallow an Android application to be published without one. The Iconproperty of the Application attribute is used to specify theapplication icon for a Xamarin.Android project.

In Visual Studio 2017 and later, specify the application icon throughthe Android Manifest section of project Properties, as shown inthe following screenshot:

In Visual Studio for Mac, it is also possible to specify theapplication icon through the Android Application section ofProject Options, as shown in the following screenshot:

In these examples, @drawable/icon refers to an icon file that islocated at Resources/drawable/icon.png (note that the .pngextension is not included in the resource name). This attributecan also be declared in the file PropertiesAssemblyInfo.cs, asshown in this sample snippet:

Normally, using Android.App is declared at the top ofAssemblyInfo.cs (the namespace of the Application attribute isAndroid.App); however, you may need to add this using statement ifit is not already present.

Version the Application

Versioning is important for Android application maintenance anddistribution. Without some sort of versioning in place, it is difficultto determine if or how an application should be updated. To assist withversioning, Android recognizes two different types of information:

  • Version Number – An integer value (used internally byAndroid and the application) that represents the version of theapplication. Most applications start out with this value set to 1,and then it is incremented with each build. This value has norelationship or affinity with the version name attribute(see below). Applications and publishing services should notdisplay this value to users. This value is stored in theAndroidManifest.xml file as android:versionCode.

  • Version Name – A string that is used only forcommunicating information to the user about the version of theapplication (as installed on a specific device). The version nameis intended to be displayed to users or in Google Play. This stringis not used internally by Android. The version name can be anystring value that would help a user identify the build that isinstalled on their device. This value is stored in theAndroidManifest.xml file as android:versionName.

In Visual Studio, these values can be set in the Android Manifestsection of project Properties, as shown in the followingscreenshot:

These values can be set via the Build > Android Application sectionof Project Options as shown in the following screenshot:

Shrink the APK

Xamarin.Android APKs can be made smaller through a combination of theXamarin.Android linker, which removes unnecessary managed code, andthe ProGuard tool from the Android SDK, which removes unused Javabytecode. The build process first uses the Xamarin.Android linker tooptimize the app at the managed code (C#) level, and then it later usesProGuard (if enabled) to optimize the APK at the Java bytecode level.

Configure the Linker

Release mode turns off the shared runtime and turns on linking so thatthe application only ships the pieces of Xamarin.Android required atruntime. The linker in Xamarin.Android uses static analysis todetermine which assemblies, types, and type members are used orreferenced by a Xamarin.Android application. The linker then discardsall the unused assemblies, types, and members that are not used (orreferenced). This can result in a significant reduction in the packagesize. For example, consider theHelloWorld sample, whichexperiences an 83% reduction in the final size of its APK:

  • Configuration: None – Xamarin.Android 4.2.5 Size = 17.4 MB.

  • Configuration: SDK Assemblies Only – Xamarin.Android 4.2.5 Size = 3.0 MB.

Set linker options through the Android Options section of the projectProperties:

The Linking pull-down menu provides the following options forcontrolling the linker:

  • None – This turns off the linker; no linking will beperformed.

  • SDK Assemblies Only – This will only link the assembliesthat are required by Xamarin.Android.Other assemblies will not be linked.

  • Sdk and User Assemblies – This will link all assembliesthat are required by the application, and not just the onesrequired by Xamarin.Android.

Set linker options through the Linker tab in the Android Buildsection of Project Options, as shown in the following screenshot:

The options for controlling the linker are as follows:

  • Don't link – This turns off the linker; no linking willbe performed.

  • Link SDK assemblies only – This will only link theassemblies that arerequired byXamarin.Android. Otherassemblies will not be linked.

  • Link all assemblies – This will link all assemblies thatare required by the application, and not just the ones required byXamarin.Android.

Linking can produce some unintended side effects, so it is importantthat an application be re-tested in Release mode on a physical device.

ProGuard

ProGuard is an Android SDK tool that links and obfuscates Java code.ProGuard is normally used to create smaller applications by reducingthe footprint of large included libraries (such as Google PlayServices) in your APK. ProGuard removes unused Java bytecode, whichmakes the resulting app smaller. For example, using ProGuard on smallXamarin.Android apps usually achieves about a 24% reduction in size– using ProGuard on larger apps with multiple librarydependencies typically achieves an even greater size reduction.

ProGuard is not an alternative to the Xamarin.Android linker. TheXamarin.Android linker links managed code, while ProGuard links Javabytecode. The build process first uses the Xamarin.Android linker tooptimize the managed (C#) code in the app, and then it later usesProGuard (if enabled) to optimize the APK at the Java bytecode level.

When Enable ProGuard is checked, Xamarin.Android runs the ProGuardtool on the resulting APK. A ProGuard configuration file is generatedand used by ProGuard at build time. Xamarin.Android also supportscustom ProguardConfiguration build actions. You can add a customProGuard configuration file to your project, right-click it, and selectit as a build action as shown in this example:

ProGuard is disabled by default. The Enable ProGuard option isavailable only when the project is set to Release mode. AllProGuard build actions are ignored unless Enable ProGuard ischecked. The Xamarin.Android ProGuard configuration does not obfuscatethe APK, and it is not possible to enable obfuscation, even with customconfiguration files. If you wish to use obfuscation, please seeApplication Protection with Dotfuscator.

For more detailed information about using the ProGuard tool, seeProGuard.

Protect the Application

Disable Debugging

During development of an Android application, debugging is performedwith the use of the Java Debug Wire Protocol (JDWP). This is atechnology that allows tools such as adb to communicate with a JVM forthe purposes of debugging. JDWP is turned on by default for Debugbuilds of a Xamarin.Android application. While JDWP is important duringdevelopment, it can pose a security issue for released applications.

Important

Always disable the debug state in a released application as itis possible (via JDWP) to gain full access to the Java process andexecute arbitrary code in the context of the application if this debugstate is not disabled.

The Android Manifest contains the android:debuggable attribute, whichcontrols whether or not the application may be debugged. It isconsidered a good practice to set the android:debuggable attribute tofalse. The simplest way to do this is by adding a conditional compilestatement in AssemblyInfo.cs:

Note that Debug builds automatically set some permissions to make debugeasier (such as Internet andReadExternalStorage). Release builds, however, use onlythe permissions that you explicitly configure. If you find thatswitching to the Release build causes your app to lose a permissionthat was available in the Debug build, verify that you have explicitlyenabled this permission in the Required permissionslist as described inPermissions.

Application Protection with Dotfuscator

Even with debugging disabled, it is still possible forattackers to re-package an application, adding or removingconfiguration options or permissions. This allows them toreverse-engineer, debug, or tamper with the application.Dotfuscator CommunityEdition (CE) canbe used to obfuscate managed code and inject runtime security statedetection code into a Xamarin.Android app at build time to detectand respond if the app is running on a rooted device.

Dotfuscator CE is included with Visual Studio 2017.To use Dotfuscator, click Tools > PreEmptive Protection - Dotfuscator.

To configure Dotfuscator CE, please seeUsing Dotfuscator Community Edition with Xamarin.Once it is configured, Dotfuscator CE will automatically protect eachbuild that is created.

Even with debugging disabled, it is still possible forattackers to re-package an application, adding or removingconfiguration options or permissions. This allows them toreverse-engineer, debug, or tamper with the application.Although it does not support Visual Studio for Mac, you can useDotfuscator Community Edition (CE)with Visual Studio to obfuscate managed code and inject runtime security statedetection code into a Xamarin.Android app at build time to detectand respond if the app is running on a rooted device.

To configure Dotfuscator CE, please seeUsing Dotfuscator Community Edition with Xamarin.Once it is configured, Dotfuscator CE will automatically protect eachbuild that is created.

Bundle Assemblies into Native Code

When this option is enabled, assemblies are bundled into a nativeshared library. This allows assemblies to be compressed, permittingsmaller .apk files. Assembly compression also confers a minimalform of obfuscation; such obfuscation should not be relied upon.

This option requires an Enterprise license and is only available whenUse Fast Deployment is disabled. Bundle assemblies into nativecode is disabled by default.

Note that the Bundle into Native Code option does not mean thatthe assemblies are compiled into native code. It is not possible to useAOT Compilation to compile assemblies into native code.

AOT Compilation

The AOT Compilation option (on thePackaging Properties page) enablesAhead-of-Time (AOT) compilation of assemblies. When this option isenabled, Just In Time (JIT) startup overhead is minimized byprecompiling assemblies before runtime. The resulting native code isincluded in the APK along with the uncompiled assemblies. This resultsin shorter application startup time, but at the expense of slightlylarger APK sizes.

The AOT Compilation option requires an Enterprise license orhigher. AOT compilation is available only when the project isconfigured for Release mode, and it is disabled by default. For moreinformation about AOT Compilation, seeAOT.

LLVM Optimizing Compiler

The LLVM Optimizing Compiler will create smaller and faster compiledcode and convert AOT-compiled assemblies into native code, but at theexpense of slower build times. The LLVM compiler is disabled bydefault. To use the LLVM compiler, the AOT Compilation option mustfirst be enabled (on thePackaging Properties page).

Note

The LLVM Optimizing Compiler option requires an Enterprise license.

Set Packaging Properties

Packaging properties can be set in the Android Options section ofproject Properties, as shown in the following screenshot:

Packaging properties can be set in the Project Options, as shown inthe following screenshot:

Many of these properties, such as Use Shared Runtime, and UseFast Deployment are intended for Debug mode. However, when theapplication is configured for Release mode, there are other settingsthat determine how the app isoptimized for size and execution speed,how it is protected from tampering, and how it can bepackaged to support different architectures and size restrictions.

Specify Supported Architectures

When preparing a Xamarin.Android app for release, it is necessary tospecify the CPU architectures that are supported. A single APK cancontain machine code to support multiple, different architectures. SeeCPU Architecturesfor details about supporting multiple CPU architectures.

Generate One Package (.APK) per Selected ABI

When this option is enabled, one APK will be created for each of thesupported ABI's (selected on the Advanced tab, as described inCPU Architectures)rather than a single, large APK for all supported ABI's. This option isavailable only when the project is configured for Release mode, and itis disabled by default.

Multi-Dex

When the Enable Multi-Dex option is enabled, Android SDK tools areused to bypass the 65K method limit of the .dex file format. The65K method limitation is based on the number of Java methods that anapp references (including those in any libraries that the app dependson) – it is not based on the number of methods that are writtenin the source code. If an application only defines a few methods butuses many (or large libraries), it is possible that the 65K limit willbe exceeded.

It is possible that an app is not using every method in every librarythat is referenced; therefore, it is possible that a tool such asProGuard (see above) can remove the unused methods from code. The bestpractice is to enable Enable Multi-Dex only if absolutelynecessary, i.e.the app still references more than 65K Java methods evenafter using ProGuard.

For more information about Multi-Dex, seeConfigure Apps with Over 64K Methods.

Android App Bundles

App bundles differ from APKs as they cannot be deployed directly to a device. Rather, it's a format that is intended to be uploaded with all of your compiled code and resources. After you upload your signed app bundle, Google Play will have everything it needs to build and sign your application's APKs and serve them to your users using Dynamic Delivery.

To enable support for Android App Bundles, you'll need to opt-in to the bundle value of the Android Package Format property within your Android project options. Before you do this, ensure you change your project to a Release configuration as app bundles are intended for release packages only.

You can now generate an app bundle by following the Archive Flow. This will generate an app bundle for your application.

For more information about Android App Bundles, see Android App Bundles.

Compile

After all of the above steps are completed, the app is ready forcompilation. Select Build > Rebuild Solution to verify that itbuilds successfully in Release mode. Note that this step does not yetproduce an APK.

Signing the App Package discusses packaging and signing in more detail.

After all of the above steps are completed, compile the application(select Build > Build All) to verify that it builds successfullyin Release mode. Note that this step does not yet produce an APK.

Best App Stores For Android

Archive for Publishing

To begin the publishing process, right-click the project in SolutionExplorer and select the Archive... context menu item:

Archive... launches the Archive Manager and begins the processof archiving the App bundle as shown in this screenshot:

Another way to create an archive is to right-click the Solution in theSolution Explorer and select Archive All..., which builds thesolution and archives all Xamarin projects that can generate anarchive:

Both Archive and Archive All automatically launch the ArchiveManager. To launch the Archive Manager directly, click theTools > Archive Manager... menu item:

The solution's archives at any time by right clicking the Solutionnode and selecting View Archives:

The Archive Manager

The Archive Manager is comprised of a Solution List pane, anArchives List, and a Details Panel:

The Solution List displays all solutions having at least onearchived project. The Solution List includes the followingsections:

  • Current Solution – Displays the current solution. Note that this area may be empty if the current solution does not have an existing archive.
  • All Archives – Displays all solutions that have an archive.
  • Search text box (at the top) – Filters the solutions listed in the All Archives list according to the search string entered in the text box.

The Archives List displays the list of all archives for theselected solution. The Archives List includes the followingsections:

  • Selected solution name – Displays the name of the solution selected in the Solution List. All information shown in the Archives List refers to this selected solution.
  • Platforms Filter – This field makes it possible to filter archives by platform type (such as iOS or Android).
  • Archive Items – List of archives for the selected solution. Each item in this list includes the project name, creation date, and platform. It can also show additional information such as the progress when an item is being archived or published.

The Details Panel displays additional information about eacharchive. It also allows the user to start the Distribution workflow oropen the folder where the distribution has been created. The BuildComments section makes it possible to include build comments in thearchive.

Distribution

When an archived version of the application is ready to publish, selectthe archive in the Archive Manager and click the Distribute...button:

The Distribution Channel dialog shows information about the app, anindication of distribution workflow progress, and a choice ofdistribution channels. On the first run, two choices are presented:

It is possible to choose one of the following distribution channels:

  • Ad-Hoc – Saves a signed APK to disk that can be sideloaded to Android devices. Continue to Signing the App Package to learn how to create an Android signing identity, create a new signing certificate for Android applications, and publish an ad hoc version of the app to disk. This is a good way to create an APK for testing.

  • Google Play – Publishes a signed APK to Google Play. Continue to Publishing to Google Play to learn how to sign and publish an APK in the Google Play store.

To begin the publishing process, select Build > Archive for Publishing:

Archive for Publishing builds the project and bundles it into anarchive file. The Archive All menu choice archives all archivableprojects in the solution. Both options automatically open the ArchiveManager when the build and bundling operations complete:

In this example, the Archive Manager lists only one archivedapplication, MyApp. Notice that the comment field allows a shortcomment to be saved with the archive. To publish an archived version ofa Xamarin.Android application, select the app in the ArchiveManager and click Sign and Distribute... as shown above. Theresulting Sign and Distribute dialog presents two choices:

From here, it is possible to select the distribution channel:

  • Ad-Hoc – Saves a signed APK to disk so it can besideloaded to Android devices. Continue toSigning the AppPackageto learn how to create an Android signing identity, create a newsigning certificate for Android applications, and publish an“ad hoc” version of the app to disk. This is a good wayto create an APK for testing.

  • Google Play – Publishes a signed APK to Google Play.Continue toPublishing to Google Playto learn how to sign and publish an APK in the Google Play store.

Related Links

-->

In this two-part guide, you will build your first Xamarin.Android application with Visual Studio and develop an understanding of the fundamentals of Android application development with Xamarin.

You will create an application that translates analphanumeric phone number (entered by the user) into a numeric phonenumber and display the numeric phone number to the user. The final application looks likethis:

Windows requirements

To follow along with this walkthrough, you will need the following:

  • Windows 10.

  • Visual Studio 2019 or Visual Studio 2017 (version 15.8 or later): Community, Professional, or Enterprise.

macOS requirements

To follow along with this walkthrough, you will need the following:

  • The latest version of Visual Studio for Mac.

  • A Mac running macOS High Sierra (10.13) or later.

This walkthrough assumes that the latest version of Xamarin.Android isinstalled and running on your platform of choice. For a guide toinstalling Xamarin.Android, refer to theXamarin.Android Installation guides.

Configuring emulators

If you are using the Android emulator, we recommend that you configurethe emulator to use hardware acceleration. Instructions for configuringhardware acceleration are available inHardware Acceleration for Emulator Performance.

Create the project

Start Visual Studio. Click File > New > Project to create a new project.

In the New Project dialog, click the Android App template.Name the new project Phoneword and click OK:

In the New Android App dialog, click Blank App and click OKto create the new project:

Create a layout

Tip

Newer releases of Visual Studio support opening .xml files inside the Android Designer.

Both .axml and .xml files are supported in the Android Designer.

After the new project is created, expand the Resourcesfolder and then the layout folder in the Solution Explorer.Double-click activity_main.axml to open it in the Android Designer. Thisis the layout file for the app's screen:

Tip

Newer releases of Visual Studio contain a slightly different app template.

  1. Instead of activity_main.axml, the layout is in content_main.axml.
  2. The default layout will be a RelativeLayout. For the rest of the steps on this page to workyou should change the <RelativeLayout> tag to <LinearLayout> and add another attributeandroid:orientation='vertical' to the LinearLayout opening tag.

From the Toolbox (the area on the left), enter text into the searchfield and drag a Text (Large) widget onto the design surface(the area in the center):

With the Text (Large) control selected on the design surface,use the Properties pane to change the Text property ofthe Text (Large) widget to Enter a Phoneword::

Drag a Plain Text widget from the Toolbox to the design surfaceand place it underneath the Text (Large) widget. Placement of thewidget will not occur until you move the mouse pointer to a place inthe layout that can accept the widget. In the screenshots below, thewidget cannot be placed (as seen on the left) until the mouse pointeris moved just below the previous TextView (as shown on the right):

When the Plain Text (an EditText widget) is placed correctly, itwill appear as illustrated in the following screenshot:

With the Plain Text widget selected on the design surface,use the Properties pane to change the Id property of thePlain Text widget to @+id/PhoneNumberText and change theText property to 1-855-XAMARIN:

Drag a Button from the Toolbox to the designsurface and place it underneath the Plain Text widget:

With the Button selected on the design surface, use theProperties pane to change its Text property to Translate andits Id property to @+id/TranslateButton:

Drag a TextView from the Toolbox to the design surface andplace it under the Button widget. Change the Text property of theTextView to an empty string and set its Id property to@+id/TranslatedPhoneword:

Save your work by pressing CTRL+S.

Write some code

The next step is to add some code to translate phone numbers fromalphanumeric to numeric. Add a new file to the project byright-clicking the Phoneword project in the SolutionExplorer pane and choosing Add > New Item... as shown below:

In the Add New Item dialog, select Visual C# > Code > Code Fileand name the new code file PhoneTranslator.cs:

This creates a new empty C# class. Insert the following code into this file:

Save the changes to the PhoneTranslator.cs file by clickingFile > Save (or by pressing CTRL+S), then close the file.

Install Android On Mac

Wire up the user interface

The next step is to add code to wire up the user interface by insertingbacking code into the MainActivity class. Begin by wiring up theTranslate button. In the MainActivity class, find the OnCreatemethod. The next step is to add the button code inside OnCreate,below the base.OnCreate(savedInstanceState) andSetContentView(Resource.Layout.activity_main) calls. First, modify thetemplate code so that the OnCreate method resembles the following:

Get a reference to the controls that were created in the layoutfile via the Android Designer. Add the following code inside theOnCreate method, after the call to SetContentView:

Add code that responds to user presses of the Translate button.Add the following code to the OnCreate method (after the linesadded in the previous step):

Save your work by selecting File > Save All (or bypressing CTRL-SHIFT-S) and build the application by selectingBuild > Rebuild Solution (or by pressing CTRL-SHIFT-B).

If there are errors, go through the previous steps and correct anymistakes until the application builds successfully. If you get abuild error such as, Resource does not exist in the currentcontext, verify that the namespace name in MainActivity.csmatches the project name (Phoneword) and then completely rebuildthe solution. If you still get build errors, verify that you haveinstalled the latest Visual Studio updates.

Set the app name

You should now have a working application – it's time to set thename of the app. Expand the values folder (inside the Resourcesfolder) and open the file strings.xml. Change the app name stringto Phone Word as shown here:

Run the app

Test the application by running it on an Android device or emulator.Tap the TRANSLATE button to translate 1-855-XAMARIN into aphone number:

Run Apple Apps On Android

To run the app on an Android device, see how to set up your device for development.

Launch Visual Studio for Mac from the Applications folder or fromSpotlight.

Click New Project... to create a new project.

In the Choose a template for your new project dialog, clickAndroid > App and select the Android App template. ClickNext.

In the Configure your Android app dialog, name the new app Phoneword and click Next.

In the Configure your new Android App dialog, leave the Solutionand Project names set to Phoneword and click Create to createthe project.

Create a layout

Tip

Newer releases of Visual Studio support opening .xml files inside the Android Designer.

Both .axml and .xml files are supported in the Android Designer.

After the new project is created, expand the Resources folderand then the layout folder in the Solution pad.Double-click Main.axml to open it in the Android Designer. Thisis the layout file for the screen when it is viewed in the Android Designer:

App

Select the Hello World, Click Me!Button on the designsurface and press the Delete key to remove it.

Android File Transfer App Mac

From the Toolbox (the area on the right), enter text into the search field and drag a Text (Large) widget onto the design surface (the area in the center):

With the Text (Large) widget selected on the design surface, youcan use the Properties pad to change the Text property of theText (Large) widget to Enter a Phoneword: as shown below:

Next, drag a Plain Text widget from the Toolbox tothe design surface and place it underneath the Text (Large)widget. Notice that you can use the search field to help locatewidgets by name:

With the Plain Text widget selected on the design surface, youcan use the Properties pad to change the Id property of thePlain Text widget to @+id/PhoneNumberText and change theText property to 1-855-XAMARIN:

Drag a Button from the Toolbox to the design surfaceand place it underneath the Plain Text widget:

With the Button selected on the design surface, you can use theProperties pad to change the Id property of the Button to@+id/TranslateButton and change the Text property to Translate:

Drag a TextView from the Toolbox to the design surface and place it under the Button widget. With the TextView selected, set the id property of the TextView to @+id/TranslatedPhoneWord and change the text to an empty string:

Save your work by pressing ⌘ + S.

Write some code

Now, add some code to translate phone numbers fromalphanumeric to numeric. Add a new file to the project byclicking the gear icon next to the Phoneword project in theSolution pad and choosing Add > New File...:

In the New File dialog, select General > Empty Class, name the new file PhoneTranslator, and click New. This creates a new empty C# class for us.

Remove all of the template code in the new class and replace it with the following code:

Save the changes to the PhoneTranslator.cs file bychoosing File > Save (or by pressing ⌘ + S), thenclose the file. Ensure that there are no compile-time errors byrebuilding the solution.

Wire up the user interface

The next step is to add code to wire up the user interface byadding the backing code into the MainActivity class.Double-click MainActivity.cs in the Solution Pad to open it.

Begin by adding an event handler to the Translate button. In theMainActivity class, find the OnCreate method. Add the button codeinside OnCreate, below the base.OnCreate(bundle) andSetContentView (Resource.Layout.Main) calls. Remove any existingbutton handling code (i.e., code that references Resource.Id.myButtonand creates a click handler for it) so that the OnCreate methodresembles the following:

Next, a reference is needed to the controls that were created inthe layout file with the Android Designer. Add the followingcode inside the OnCreate method (after the call toSetContentView):

Add code that responds to user presses of the Translate buttonby adding the following code to the OnCreate method (after thelines added in the last step):

Save your work and build the application by selecting Build > Build All(or by pressing ⌘ + B). If the applicationcompiles, you will get a success message at the top of Visual Studio for Mac:

If there are errors, go through the previous steps andcorrect any mistakes until the application builds successfully. Ifyou get a build error such as, Resource does not exist in thecurrent context, verify that the namespace name inMainActivity.cs matches the project name (Phoneword) and thencompletely rebuild the solution. If you still get build errors,verify that you have installed the latest Xamarin.Android andVisual Studio for Mac updates.

Set the label and app icon

Now that you have a working application, it's time to add thefinishing touches! Start by editing the Label for MainActivity.The Label is what Android displays at the top of the screen tolet users know where they are in the application. At the top of theMainActivity class, change the Label to Phone Word as shownhere:

Now it's time to set the application icon. By default, Visual Studio for Mac will provide a default icon for the project. Delete these files from the solution, and replace them with a different icon. Expand the Resources folder in the Solution Pad. Notice that there are five folders that are prefixed with mipmap-, and that each of these folders contains a single Icon.png file:

It is necessary to delete each of these icon files from the project. Right click on each of Icon.png files, and select Remove from the context menu:

Click on the Delete button in the dialog.

Next, download and unzip Xamarin App Icons set. This zip file holds the icons for the application. Each icon is visually identical but at different resolutions it renders correctly on different devices with different screen densities. The set of files must be copied into the Xamarin.Android project. In Visual Studio for Mac, in the Solution Pad, right-click the mipmap-hdpi folder and select Add > Add Files:

From the selection dialog, navigate to the unzipped Xamarin AdApp Icons directory and open the mipmap-hdpi folder. Select Icon.png and click Open.

In the Add File to Folder dialog box, select Copy the file into the directory and click OK:

Repeat these steps for each of the mipmap- folders until the contents of the mipmap- Xamarin App Icons folders are copied to their counterpart mipmap- folders in the Phoneword project.

After all the icons are copied to the Xamarin.Android project, open the Project Options dialog by right clicking on the project in the Solution Pad. Select Build > Android Application and select @mipmap/icon from the Application icon combo box:

Run the app

Finally, test the application by running it on an Android device or emulator and translating a Phoneword:

To run the app on an Android device, see how to set up your device for development.

Congratulations on completing your first Xamarin.Android application!Now it's time to dissect the tools and skills you have just learned. Next up is theHello, Android Deep Dive.

Related links