Android Build Environment and Configurations

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

Access the Generated Android Project for Quantum Visualizer Application

If an application is built in Quantum 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 Quantum 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 Quantum Visualizer.
  3. In Quantum 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 Quantum Visualizer build process generates a Main Activity Java source file with Application ID as its name in the following path: 

  • Mobile<WorkSpace>\temp\SampleApplication\build\luaandroid\dist\SampleApplication\src\com\xyz\sample\SampleApplication.java
  • Tablet<WorkSpace>\temp\SampleApplication\build\luatabrcandroid\dist\SampleApplication\src\com\xyz\sample\SampleApplication.java

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: 

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

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

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

A developer can copy these XMLs into Quantum Visualizer 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 Quantum Visualizer project

Since Quantum'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.

  • For mobile - <WorkSpace>\<Application>\resources\customlibs\lib\android
  • For tablet - <WorkSpace>\<Application>\resources\customlibs\lib\tabrcandroid

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 Quantum 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 Quantum 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>