You are here: Configuring Your Computer > Install platform SDKs and their emulators > Android SDK and Emulator

Android SDK and Emulator

Applies to Kony Visualizer Classic.

Building and testing Android applications in Kony Visualizer requires two primary resources: Android SDK and Gradle. Gradle is an advanced build toolkit that manages dependencies and allows a developer to define custom build logic. This section describes how to install and configure these resources.

Prerequisites that you need to download:

For any queries you may have about installing Android SDKs and Android Studio, see Android SDK and Platform FAQs.

To build and view applications on the Android platform, do the following:

Download and install Android Studio

You must install Android Studio for building and testing Android applications using Kony Visualizer. To download and install Android Studio, click Google Android Studio.

Download and unzip the Android SDK and support packages

Required SDKs and support packages can be optionally downloaded during the Android Studio installation process. If you have not downloaded the required SDKs during the Android Studio installation, you can download and install the Android Command line tools (stand-alone SDK tools) by doing the following:

To download and install the Android Command line tools and necessary support packages, do the following:

  1. Using a web browser, navigate to the Command Line Tools download section on the Android studio and SDK tools download site.
  2. Depending on the operating system of your computer, click the appropriate SDK tools package. After reviewing the terms and conditions of the Android SDK license agreement, if you agree to them, check the option indicating that you have read and agree to them, and then click the download button.
  3. Once the zip file downloads, navigate to the downloaded zip file location and unzip it. Place the contents in a folder in your system.

    Important: For Windows users, install the Android SDK to a folder with a path that has no spaces, for example:
    C:\Android\android-sdk
    The default installation path contains at least one space, which may result in the emulator not being accessible in Eclipse and, therefore, Kony Visualizer.

  4. Kony Visualizer Android project will download all required SDKs, support packages, and any project specific build library dependencies using the Gradle Auto Download mechanism during the Android native project build.

    All required SDK, support packages, and dependent libraries are auto downloaded by Gradle build.
  5. You can also download the missing artifacts using Android Studio.

    Click Install missing platform(s) and sync project link in the message that appears.

    Select the defaults through the Component Installer and wait until Finish is enabled.

    Click the Install Build Tools 26.2 and sync project link in the message window.

    Select the defaults through the Component Installer and wait until Finish is enabled.

Known Issues:

 

Configure Kony Visualizer to build for the Android platform

Now that you have installed the Android SDK, you need to configure Kony Visualizer to recognize the Android platform.

To configure Kony Visualizer to build for the Android platform, do the following:

  1. In Kony Visualizer, click the Window menu, and then click Preferences.
  2. In the left pane, double-click Kony Visualizer, and then click Build.
  3. If it hasn't done so already, at this point Kony Visualizer auto-detects the Android SDK and asks if you would like to use the path that it has discovered as the Android Home. If you wish to, click OK. If Kony Visualizer did not auto-detect the Android SDK, in the Android Home text box, enter the path to the Android SDK packages. To ensure you don't introduce errors into the path that you type, you may want to click the accompanying Browse button, navigate to the Android SDK's location, and then click OK.
  4. Click OK.
  5. Specify which Android SDK to use when building an app. To do so, on the Project menu, click Settings.
  6. In the Project Properties dialog box, click the Native tab. A row of secondary tabs displays. From this row, click Android.
  7. In the SDK Versions section of the tab, from the Minimum drop-down list, ensure you set the minimum SDK version.
  8. From the Target drop-down list, select the SDK version you would prefer to build for.
  9. Click Finish.

Set the Android SDK Home Environment Variable

The following procedure is for the Windows environment, for the Mac, run the following command:
export ANDROID_HOME=/<installation location>

To set the Android SDK home environment variable, do the following:

  1. Click Start.
  2. Right-click Computer, and then select Properties.
  3. Click Advanced system settings.
  4. On the Advanced tab, click Environment Variables.
  5. Under User variables, click New.
  6. For Variable name, type the following value:
    ANDROID_HOME
  7. For Variable value, type the path to the parent directory where your Android SDK is installed. For instance:
    C:\Android\android-sdk
  8. Click OK until you have closed all dialog boxes. Do not click Cancel.
  9. Restart your computer.

Manually Set the Android Environment Variables

Under some circumstances, you might have to add the Android SDK environment variables manually. This is most commonly necessary if you installed Kony Visualizer before installing the Android SDK. If you already had the Android SDK installed when you install Kony Visualizer, Kony Visualizer detects the presence of the Android SDK and adds the necessary environment variables automatically.

For more information, click the procedure you want.

Add Windows Android Environment Variables Manually

Add Mac Android Environment Variables Manually

Add Windows Android Environment Variables Manually

To manually set the Android environment variables for a Windows computer, do the following:

  1. Click Start.
  2. Right-click Computer, and then select Properties.
  3. Click Advanced system settings.
  4. On the Advanced tab, click Environment Variables.
  5. Under System Variables, double-click Path.
  6. Add to the Path variable the location of the /bin folder in your installation of the JDK. For example:
  7. C:\Java\jdk1.7.0_79\bin

  8. Add to the Path variable the locations of the /emulators, /tools, and /platform-tools folders in your installation of the Android SDK. For example:
  9. C:\Android\android-sdk\emulator; C:\Android\android-sdk\tools;C:\Android\android-sdk\platform-tools

  10. Click OK until you have closed all dialog boxes. Do not click Cancel.
  11. Restart your computer.

Add Mac Android Environment Variables Manually

To manually set the Android environment variables for a Mac computer, do the following:

  1. In the home directory, locate .bash_profile, and then open it. If you do not have the .bash_profile file, create it.
  2. Add to the Path variable the locations of the /emulators, /tools, and /platform-tools folders in your installation of the Android SDK. For example:
    C:\Android\android-sdk\emulator; C:\Android\android-sdk\tools;C:\Android\android-sdk\platform-tools
  3. Save the file and close it.

Enable USB debugging on your Android Device

On Android 4.1 and lower, the Developer options screen is available by default. On Android 4.2 and higher, do the following:

  1. Open the Settings app.
  2. Select System.
  3. Scroll to the bottom and select About phone.
  4. Scroll to the bottom and tap Build number 7 times.
  5. Return to the previous screen to find Developer options near the bottom.
  6. Scroll down and enable USB debugging.

List Devices and View Logs

To List the Android devices connected to the Windows 10 PC, do the following:

  1. Navigate to C:\Users\USERNAME\AppData\Local\Android\platform-tools.
  2. Open a command window.
  3. Run adb devices -l to list the Android devices connected to the Windows 10 PC.

To connect to an Android device on your Windows machine, do the following:

  1. Navigate to C:\Users\USERNAME\AppData\Local\Android\tools
  2. Run monitor.bat and click on the connected device.

Configure an Android Emulator

Google has stopped supporting the standalone AVD manager and SDK Manager GUI tools, with latest Android SDK tools. When using, latest Android SDK tools >= 25.3.0, support for launching AVD Manager GUI to create android emulators and SDK manager to download missing components are deprecated from Kony Visualizer V8 release. You must install Android Studio on your machine to get GUI to create and use Android emulators. Click here for more information.

Alternatively, you can use avdmanager command line utility to create the emulators. Refer https://developer.android.com/studio/command-line/avdmanager.html for avdmanager command usage.

When using older Android SDK tools( < 25.3.0), you still would be able to create and launch AVDs using AVD Manager and SDK Manager GUI Tools.

Follow Gradle-related Changes for different Kony Visualizer Versions

This section describes the various Gradle-related changes pertaining to different versions of Kony Visualizer.

V8 SP2 Changes

V8 SP3 Changes

V8 SP4 Changes

Follow Gradle Recommendations

For using Gradle, you must go through the following sections:

Important: When you upgrade to Kony Visualizer 8.2 and later, ensure that there are no conflicts in the dependencies of the build.gradle and libs folder. For example, appcompat-v7 added to the build.gradle is X version and if the same file is in the libs folder is of Y version. Due to differences in versions of the file, following build exceptions occur.
duplicate entry exception or com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
For more information on how to debug these type of conflicts, click here.

General Recommendations

Build-related Recommendations

Build failures occur if there are any deviations from the Android-specified requirements. To build an understanding of how Android enforces its requirements, you can create a native application and test various scenarios. In creating such an app, you will want to be aware of the following:

Compilation Dependencies and Gradle Build Java Symbol Conflicts Resolution Methodology

If the build fails with the following exceptions and you do not know the root cause, following the debugging procedure provided here:

The debugging procedure for these build issues is as follows:

  1. Find the two jars/dependencies that are conflicting by making the following changes in the generated native Android build project. These latest tools will print exactly which classes conflict and their sources/origins. These are taken from Google's suggestions form:
    1. Go to the folder where the native Android project is generated:
      • For Mobile: <workspace>\temp\<appid folder>\build\luaandroid\dist\<appid folder>\

      • For Tablet: <workspace>\temp\<appid folder>\build\luatabandroid\dist\<appid folder>\

    2. Change com.android.tools.build:gradle version to 3.4.0-beta03 in the build.gradle file:
      buildscript {dependencies{classpath 'com.android.tools.build:gradle:3.4.0-beta03'}}
    3. Change the distributionUrl in the gradle-wrapper.properties file (available in dist\<appid folder>\gradle\wrapper) to https://services.gradle.org/distributions/gradle-5.1.1-all.zip.
    4. Type the following command in the command prompt, with the same directory as the native Android project: gradlew assembleDebug

    The build log then prints the complete details of all the conflicting libraries that fetch duplicate classes.

  2. Identify from where the conflicting dependencies are pulled by using this command: gradlew dependencies
    This command helps you to view the dependency tree hierarchy in your project. You can then locate the dependency version that was enforced by the relevant compilation dependency.
  3. Resolve the conflicts by following these steps:
    1. Adopt the conflict resolution strategy, if dependency version conflicts is the reason. For example, if the project specifies design dependency version (say X) and another version of design dependency (say version Y) is pulled form recursive dependencies of another dependency (say appcompat-v7), then the build fails.
      To resolve this build issue, you can force the build to use only the Y version, regardless of any version included by the dependency tree by adding a snippet as shown in the build.gradle.
    configurations.all {
        resolutionStrategy {
            force "com.android.support:design:Y"
        }
    }						
    
    1. Remove any duplicate jars or classes found in any of the .aar files and libraries.
      For example, you can use the following script to delete the volley and gson-2.2.4 jar files from libs if they conflict with your dependencies in the build.gradle file.

      task deleteJars
      {
      delete "libs/volley.jar"
      delete "libs/gson-2.2.4.jar"
      }}

Note: To add additional entries in the build.gradle file, select the build.gradle entries to suffix option under the Gradle Entries tab in Application Properties. For more information on Gradle properties, click here.

Proxy-Related Build Recommendations

If your computer has proxy settings, you can alleviate build errors at the system level, and at the project level.

System-Level Proxy Recommendations

To address proxy-related build issues at the system level, you can either disable your computer's proxy settings, or create a gradle.properties file to your Gradle installation.

To create a gradle.properties file, do the following:

  1. Navigate to the following folder:
    For Windows
    C:\Users\<UserName>\.gradle

    For the Mac
    /Users/<UserName>/.gradle
  2. Create a new text file using a text editor such as Notepad or TextEdit, and save it with the following file name:
    gradle.properties
  3. Edit the gradle.properties file to include the following settings (replace the values given in the example with your own settings).
  4. Replace http with https, based on the proxy server settings.
  5. For more information, see The Build Environment on the Gradle web site.

Project-Level Automated Recommendations

To automate project-level requirements, do the following:

    1. Create Android pre-compile and post-compile automated tasks. For more information, see Android Pre-compile and Post-compile Ant Tasks Support.
    2. Add the gradle.properties file mentioned earlier to the project folder. For example:
      For Windows
      C:\<workspace>\<ProjectName>

      For the Mac
      /Users/<UserName>/<Workspace>/<ProjectName>
    3. Copy the file androidprecompiletask.xml from the path
      <workspace>\temp\DeepLinkApp\build\luaandroid\extres
      to
      <workspace>\DeepLinkApp
    4. Open androidprecompiletask.xml in a text editor such as Notepad or TextEdit, and edit it as your situation requires. For example:
    <target name = "PreCompileSetup">
    <echo message = "basedir = ${basedir}, appdir = ${app.dir}, isMobileBuild = ${isMobileBuild}">
    <echo message = "Build mode = ${build.option}, Packagepath = ${packagepath}, x86 Support = ${supportx86}">
    <delete file = "${app.dir}/gradle.properties">
    <copy file = "${basedir}/gradle.properties">
    tofile = "${app.dir}/gradle.properties">
    </target>						
    
  • Project-Level Manual Recommendations

    To manually make the necessary changes at the project level, do the following:

    Note: This needs to be done following each time you build the project

    1. In Windows Explorer or Finder, navigate to the following path:

      For Windows
      <Workspace>\temp\<ProjectName>\build\luaandroid\dist\<ProjectName>

      For the Mac
      /Users/<UserName>/<Workspace>/temp/<ProjectName>/build/luaandroid/dist/<ProjectName>
    2. If you haven't done so already, edit the gradle.properties file to include the proxy settings mentioned earlier.
    3. Open a command or terminal window.
    4. Navigate to the path in step 1.
    5. Build the application using the following command line:
      gradle assembleDebug

    Packaging Error Build Recommendations

    Android generates a packaging error if one or more JAR files have duplicate files or classes. To solve this issue, do one of the following:

    Convert JPGs named as PNGs to the PNG Format

    Gradle checks for PNG files while building your application. If a JPEG file in the folder is named as a PNG file (that is, the JPG has a .png extension) Gradle generates a build error. To avoid this issue, Kony developed a Python script tool to check if the image files are correctly named. You can use this tool to convert the JPEG files to PNG.

    To use the Python JPG conversion tool, do the following:

    1. Install the following Python executables: 
    2. https://www.python.org/ftp/python/2.7.10/python-2.7.10.msi

      http://effbot.org/downloads/PIL-1.1.7.win32-py2.7.exe

    3. Download the following archive from here and execute the following command: 
    4. $ python pngConversion.py -p E:\res\drawable(replace with the folder)

    Common Issues with Gradle Migration

    The following issues and errors can arise as a result of a Gradle migration.

    Gradle Could not resolve com.android.tools.build:gradle:1.3.1
    This condition can occur if there is no internet connection or when the system is being used when the proxy is not set. To resolve, set the proxy, or connect the computer to an internet connection.

    Error: Gradle Wrapper not found in Android SDK
    If you have been using Cordova applications in Visualizer and upgrade your Android SDK tools version to later than 25.2.5, when you build a project with Cordova support the Gradle Wrapper not found error occurs. Android removed Gradle wrapper package from the Android SDK tools version later than 25.2.5. As a result, Gradle wrapper does not exist in the Android SDK PATH and that results in the error.

    To resolve, add Gradle to your path environment variable. For more information, refer to Gradle in Android Platform Guide.

    Error: Unsupported type net, etc.
    This condition can occur if the application is packing some internal files which are used in the android fwk, this would normally happen if the application is be packing *.xml which can be found in the following folder:
    ..\resources\res\values
    To resolve, modify the XML files to change the custom tags net to string.

    Duplicate Entry error
    Occurs when the same .jar files are being added multiple times, or when different .jar files have the same classes. To resolve, remove the duplicate classes from .jar files.

    Gradle OOM issue
    To resolve, add javaMaxHeapSize (build.gradle), org.gradle.jvmargs(gradle.properties) values to the script. These are general options, which you can configure according to the needs of your app.

    Peer not authenticated (proxy with https setting)
    To resolve, download the local proxy server certificate and add it to the Java Key store.

    Error: Could not create the Java Virtual Machine
    Usually occurs when Gradle is not able to allocate the required memory to build the project, generally noticed on 32-bit computers. If the error occurs on a 64-bit computer, add javaMaxHeapSize (build.gradle), org.gradle.jvmargs (gradle.properties) values to the script. These are general options, which you can configure according to the needs of your app.

    Common Issues with Android Builds

    The following build issue may occur while using the Quantum Visualizer plugin compatible with Android 12(API Level 31) compile-SDK:

    [exec-shell] An exception has occurred in the compiler (1.8.0_151). Please file a bug against the Java compiler via the Java bug reporting page (http://bugreport.java.com) after checking the Bug Database (http://bugs.java.com) for duplicates. Include your program and the following diagnostic in your report. Thank you.

    [exec-shell] java.lang.AssertionError: annotationType(): unrecognized Attribute name MODULE (class com.sun.tools.javac.util.UnsharedNameTable$NameImpl)

    [exec-shell] \tat com.sun.tools.javac.util.Assert.error(Assert.java:133)

    You can use one of the following workarounds to resolve the build issue:

     

     

     

    Copyright © 2013 Kony, Inc. All rights reserved.