🔍   Discover Top 5 Reasons Companies Choose Appcircle Over Microsoft App Center for Mobile!Learn MoreTalk to an Expert 
environment-variables

Using Environment Variables in iOS, Android, and Flutter Projects

Managing environment variables is crucial for customizing build configurations and securely handling sensitive data like API keys and passwords. Appcircle provides a streamlined approach for defining, managing, and utilizing environment variables across iOS, Android, and Flutter projects, ensuring flexible and secure build processes.

Creating Environment Variable Groups

Organize your environment variables into groups for better management and reuse across multiple projects or build profiles.

Example:

A development team creates an environment variable group named "Development" to store variables like API_URL and API_KEY specific to the development environment.

Adding Key and Text-Based Value Pairs

Add key-value pairs where the value is text. Sensitive values can be marked as secret to hide them during the build process.

Example:

  • Key: API_URL
  • Value: https://api.example.com
  • Secret: No
  • Key: API_KEY
  • Value: your_api_key_here
  • Secret: Yes (hidden)

Adding Files as Environment Variables

Include files as environment variables for use in build workflows, such as configuration files or certificates.

Example:

A developer uploads a configuration file as an environment variable with the key CONFIG_FILE, which is then used during the build process.

Using Environment Variable Groups in Builds

Assign the created environment variable groups to your build profiles to make the variables available during the build.

Example:
In the staging build configuration, the team assigns the "Staging" variable group, ensuring that staging-specific settings are applied during the build.

Using Environment Variables in iOS Projects

Integrate environment variables into iOS projects using Xcode configuration files (.xcconfig files). This allows you to manage project-wide variables without hardcoding sensitive information.

Example:
A developer creates a .xcconfig file to store variables like API_URL and API_KEY. These variables are referenced in the project's Info.plist and accessed in the code. During the build process, Appcircle's custom scripts replace placeholders in the .xcconfig file with actual environment variable values, ensuring sensitive data is not exposed in the source code.

Using Environment Variables in Android Projects

Access environment variables in Android projects through Gradle build configurations. This method lets you define variables that can be used throughout your application.

Example:
A developer modifies the build.gradle file to include environment variables for API_URL and API_KEY. These variables are then accessible in the application via the BuildConfig class. By assigning different variable groups in Appcircle, the developer can easily switch between development, staging, and production environments without changing the code.

Best Practices and Considerations

  • Security: Mark sensitive variables as secret in Appcircle to prevent exposure.
  • Environment-Specific Configurations: Create separate variable groups for different environments like development, staging, and production.
  • Consistent Naming Conventions: Use clear and consistent names for your variables and groups.
  • Avoid Hardcoding: Do not embed sensitive information in your source code; use environment variables instead.