You are here: Appendix B: Android Build Environment and Configurations

Android Build Environment and Configurations

Android developers can customize and configure Android build environments using the following information:

  1. Access the Generated Android Project for Kony Application
  2. Main Activity and its Life Cycle Methods
  3. Android Pre-compile and Post-compile Ant Tasks Support
  4. Support for Integrating Android Third-Party Libraries With Kony Project

Access the Generated Android Project for Kony Application

If an application is built in Kony Visualizer for the Android platform, a corresponding native Android project is generated.

Changes made to the project can be compiled in the command line using gradle assembleDebug, gradle assembleRelease by navigating to the native Android application folder in the command line.

To access the generated Android project, do the following: 

  1. In Kony Visualizer, in the Project Explorer, on the Project tab, click the context menu arrow for your platform of choice (e.g. Mobile), and then click Open Build Folder.
  2. Launch Kony Visualizer.
  3. In Kony Visualizer, in the Project Explorer, on the Project tab, click the context menu arrow for your platform of choice (e.g. Mobile), and then click Open Build Folder. Open the build folder. A folder opens with the directory structure <WorkSpace>\temp\<AppID>.
  4. Navigate to the respective folder: 
    • Mobile<WorkSpace>\temp\<AppID>\build\luaandroid\dist\<AppID>.
    • Tablet<WorkSpace>\temp\<AppID>\build\luatabrcandroid\dist\<AppID>.

Main Activity and its Life Cycle Methods

If the application package name is com.xyz.sample and the Application ID is SampleApplication, the Kony Visualizer build process generates a Main Activity Java source file with Application ID as its name in the following path: 

A developer can add custom code and add/modify overridden Android activity life cycle methods such as onCreate(), onStart(), onResume(), onPause(), onStop(), onRestart(), onDestroy(), onNewIntent(Intent), and so on. A developer can also invoke any third-party APIs directly from overridden life cycle methods of the class.

While enhancing the Java file, a developer needs to remember the following points: 

  1. You can enhance the auto-generated methods in this class, but you must not remove any auto-generated code.
  2. While overriding life cycle methods, you must call the superclass implementation of each life cycle method.
  3. While using the pre-compile task feature(described in next section), to overwrite the generated Main Activity file with the modified file, a developer may need to maintain separate Main Activity Java source files for debug and release modes, because they differ in certain functions or parameters.

Android Pre-compile and Post-compile Ant Tasks Support

A developer can perform custom tasks before and after compiling the generated native Android application using androidprecompiletask.xml and androidpostcompiletask.xml.

For example, a developer can perform the following pre-compile tasks using androidprecompiletask.xml: 

  1. Overwrite the generated Main Activity Java file with modified file in <AppID>\src\<packagepath>\ folder .
  2. Copy the modified Android application build XML file to the native Android folder.
  3. Copy any custom libs, assets, res, and other files/folders into the native Android hierarchy.
  4. Append custom properties to project.properties or local.properties, etc.

For example, you can perform the following post-compile tasks using androidpostcompiletask.xml: 

  1. Automating signing of an application with a release key.
  2. Trigger a security scan on a generated APK for security flaws.
  3. Trigger automation on a compiled APK file and publish results.
  4. Check-in code in GIT repositories.

A developer can copy these XMLs into Kony project workspace base directory with same names (androidprecompiletask.xml and androidpostcompiletask.xml).

A template androidprecompiletask.xml file is available at <WorkSpace>\temp\<AppID>\build\luaandroid\extres. This XML is available under extres folder after building any sample project. This XML file contains build parameter information useful to perform the tasks explained in the example above.

Note: The pre- and post- compile Ant tasks can support integration with external tools such as binary protection tools, static analyzer tools, and so on.

Support for Integrating Android Third-Party Libraries With Kony Project

Since Kony's build system is based on Gradle, integrate third party Android library format (.aar) files into the project by copying .aar files to the required path.

Similarly, third-party java class (.jar) files can also be integrated into the project by copying .jar files to the required path.

If the library format's .aar or .jar file depends on other libraries, add them to your project.

Important: If the included dependencies have an associated order among them, they must be added in same order. For more information on dependency order, see Dependency order.

For Kony Visualizer version 7.3, use the build.gradle entries to Suffix Gradle property to add dependencies. For example, if your .aar file or .jar file depends on Appcompat and Play Services Analytics, you can add the following dependency entries.

For information on Gradle properties, see Set Native App Properties.

For Kony Visualizer version 7.2 and earlier, add dependencies by adding script code to androidprecompiletask.xml. For example, the following concatenates the Appcompat and Play Services Analytics entries to the build.gradle file.

< concat destfile = "${app.dir}/build.gradle"
append = "true" > $ {
    line.separator
}
dependencies.compile 'com.android.support:appcompat-v7:24.0.0' < /concat>
< concat destfile = "${app.dir}/build.gradle"
append = "true" > $ {
    line.separator
}
dependencies.compile 'com.google.android.gms:play-services-analytics:10.0.0' < /concat>
Copyright © 2013 Kony, Inc. All rights reserved.