Android Build
The Appcircle Android Build step is designed to build your Android application for the architectures specified in your project.
Prerequisites
Before running the Android Build step, you must complete certain prerequisites, as detailed in the table below:
Prerequisite Workflow Step | Description |
---|---|
Git Clone | To initiate the Android build process, the repository that needs to be built must be fetched from the branch. This is achieved as follows: Upon completion of the Git Clone step, it generates the $AC_REPOSITORY_DIR variable, which is then used as the input for the Android Build step. |
Input Variables
This step contains some input variable(s). It needs these variable(s) to work. The table below gives explanation for this variable(s).
Variable Name | Description | Status |
---|---|---|
$AC_REPOSITORY_DIR | This variable represents the path of the cloned Git repository. If this step runs after the Git Clone step, the variable will be automatically populated. | Required |
$AC_MODULE | This variable specifies the project module to be build. This variable can also be set via the build Configuration. In Android Studio, you can locate the available modules for your project. For more information, please refer to this Android document. | Required |
$AC_VARIANTS | This variable specifies the project variant to be build. This variable can also be set via the build Configuration. In Android Studio, you can find the available variants for your project. For more information, please refer to this Android document. | Required |
$AC_OUTPUT_TYPE | This variable specifies the output type for your build file (APK or AAB). This variable can also be set via the build Configuration. | Required |
$AC_PROJECT_PATH | Specifies the project path. If your project that needs to be built is not located in the root directory where it was cloned from Git, you should provide the subpath as a relative path. | Optional |
$AC_GRADLE_BUILD_EXTRA_ARGS | Extra arguments were passed to build task. For more information, please refer to this Gradle document. | Optional |
If you have filled in the necessary variables in the Configuration section, you will not need to redefine these variables again in the Workflow. For more information about configurations, refer to the Build Profile Configuration Overview document. The information you fill in the configuration will be used as input in the Android Build step. Please replace the example information with your own details:
- The input corresponding to the 1st field:
$AC_MODULE
- The input corresponding to the 2nd field:
$AC_VARIANTS
- The input corresponding to the 3rd field:
$AC_OUTPUT_TYPE
If you are using Gradle 4.3 and above in your project, you can just use the --scan
flag in the build step to enable build scans. For existing projects, you may need to add the Gradle Scan (Gradle Enterprise) plugin. For more information, please refer to
Output Variables
The output(s) resulting from the operation of this component are as follows:
Variable Name | Description |
---|---|
AC_APK_PATH | Path for the generated APK file. This path will be created after the Android Build step runs. |
AC_AAB_PATH | Path for the generated AAB file. This path will be created after the Android Build step runs and when AAB is selected. |
The resulting files will be either APK or AAB, depending on whether you choose the Android App in the project Configuration.
If your project has the signing configuration in Gradle, this step will generate a signed artifact.
If you do not disable the Android Sign step and your project has no signing configuration defined in Gradle, your artifact will remain unsigned.
So, in order to sign your app using the keystore selected in the build configuration, you should enable the Android Sign step after Android Build.
To access the source code of this component, please use the following link:
FAQ
How can I solve the Out of memory error: Java heap memory
or set the heap memory during the build?
To resolve this issue, you need to adjust the Java heap size using the following parameters in the system properties:
-Xms:<size>
, which sets the initial and minimum heap size-Xmx:<size>
, which sets the maximum heap sizeFor example:
java -Xms:1g -Xmx:1g MyApplication
This starts up the JVM with a heap size fixed to 1 GB.
Please refer following documentation for more information:
You can implement this solution using one of the following methods:
Method 1: Using a Custom Script During the Build
If your project has varying heap size requirements, you can adjust the heap size during the build phase with a Custom Script before the Android Build step. Your script should include the following command:
echo "org.gradle.jvmargs=-Xms1g -Xmx7168M" >> $AC_REPOSITORY_DIR/gradle.properties
- Adjust the
-Xms1g -Xmx7168M
values according to your project needs. - Ensure the path
$AC_REPOSITORY_DIR/gradle.properties
matches your file's location.$AC_REPOSITORY_DIR
represents the root project directory. - You can extend the command with additional parameters as needed. For example, for Kotlin, you might add:
"org.gradle.jvmargs=-Xms1g -Xmx7168M kotlin.daemon.jvm.options=-Xms700m -Xmx7168M"
Method 2: Modifying the gradle.properties
File
If the heap size requirement is constant, you can directly add the following code to the end of your project's gradle.properties
file. Feel free to modify this code to fit your specific project requirements:
org.gradle.jvmargs=-Xms1g -Xmx7168M
Also, if you want to solve this issue via Android Studio you can follow this documentation:
How can I generate an APK alongside an AAB?
To generate an APK alongside an AAB, you can use one of these two methods:
- Adding Another Android Build Step:
- Configure for AAB: Set up the build configuration to generate an AAB.
- Add another Android Build Step: Add an additional Android Build step, after the first Android Build step. To avoid confusion, you can add the generates file type to the step name.
- Modify Output Type: Change the
$AC_OUTPUT_TYPE
input variables of the second Android Build step to APK. Now your build will generate an AAB and APK file.
If adding two Android Build steps makes the build process too lengthy, you can use the following alternative method:
- Generating APK from AAB file:
- Configure for AAB: Set up the build configuration to generate an AAB.
- Add a Bundle Universal Apk Step: Insert the
Bundle Universal Apk
step in your workflow after the Android Build step. - Configure the Bundle Universal Apk Step: Complete the inputs for the Bundle Universal Apk step. To sign the APK via this step, you might need to upload your keystore file to the system if there is no uploaded.
- Convert AAB to APK: This step will convert the generated AAB into an APK.
These steps will ensure that both an AAB and an APK are generated during your build process.