Improve the Build Process of your Apps

luizrebelatto

Luiz Gabriel

Posted on July 29, 2024

Improve the Build Process of your Apps

First of all, let's understand what this tool is:

What is Fastlane?

It's an open-source tool that will help you improve the development process and the distribution of your android and ios applications. With this tool you can automate processes such as:

  • Automatically generate screenshots for use in stores
  • Distribute beta versions to testers
  • Sign your own code
  • Upload a new version to testflight

It is possible to use external plugins to implement new flows; these plugins are developed by the open-source community.

Read more in the documentation


How to configure on android?

  • access your project and enter the android folder
cd myApp/android
Enter fullscreen mode Exit fullscreen mode
  • Initialize fastlane
Fastlane init
Enter fullscreen mode Exit fullscreen mode

Now! you have to do configurations:

  • In the terminal you will be asked to enter the package name found in the path NameOfApp/android/app/build.gradle and in the namespace field.
  • As we are working with android at the moment, we need to make some settings in google. We'll have to generate the json file with some settings.

Google Configuration

Create google services

  • Fill in the details and click done
  • Copy the email address provided by the service and save it as we will need it later

service account

  • Create the keys, click on the 3 dots under actions
  • Manage keys

Image manage key

  • Create new key -> JSON -> Create
  • We will place this json inside our project, place this file inside the android/fastlane folder and define a name for it
  • We need to give permission for our service to work

User permissions

  • Open the google console and go to users and permissions
  • Invite user -> enter the email address of the service
  • Set permissions to admin

Configuring the AppFile

json_key_file("android/fastlane/keys.json") # Path to the json secret

# find this data inside android/build.gradle, we use this to identify the app we are working on
package_name("com.nameofapp")
Enter fullscreen mode Exit fullscreen mode

Installing an automatic version change plugin

  • access the path yourProject/android/fastlane
  • run this command
gem 'fastlane-plugin-increment_version_code'
Enter fullscreen mode Exit fullscreen mode

Configuring FastFile

  • This file is where we'll have our fastlane action flow
fastlane_require 'dotenv'

default_platform(:android)

# esta linha faz a leitura do arquivo gradle.properties para
# pegar algumas informações de config
def getGradleProperty(property_name)
  gradle_properties_content = File.read('../gradle.properties')
  property_regex = /^#{property_name}=(.+)/
  match = gradle_properties_content.match(property_regex)
  match[1] if match
end

platform :android do
  desc "Deploy to test internal to Google Play"

  lane :deployBeta do
    pathKeyJson = "android/fastlane/keys.json"

    # aumentar versão do build
    previous_build_number = google_play_track_version_codes(
      package_name: "com.nameofapp",
      json_key: pathKeyJson,
      track: "internal",
    )[0]

    current_build_number = previous_build_number + 1

    increment_version_code(
      gradle_file_path: "./app/build.gradle",
      version_code: current_build_number
    )

    gradle(task: 'clean')
    gradle(
      task: 'bundleRelease',
      properties: {
        "storeFile" => "../app/release.keystore",
        "android.injected.signing.store.password" => getGradleProperty('MYAPP_UPLOAD_STORE_PASSWORD'),
        "android.injected.signing.key.alias" => getGradleProperty('MYAPP_UPLOAD_KEY_ALIAS'),
        "android.injected.signing.key.password" => getGradleProperty('MYAPP_UPLOAD_KEY_PASSWORD'),
      }
    )

    supply(
      json_key: pathKeyJson,
      package_name: "com.nameofapp",
      track: 'internal',
      skip_upload_metadata: true,
      skip_upload_images: true,
      skip_upload_screenshots: true,
      skip_upload_apk: true,
      skip_upload_aab: false
    )
  end
end
Enter fullscreen mode Exit fullscreen mode

Create script package.json

"fastlane:android": "cd android/Fastlane && Fastlane deployBeta"
Enter fullscreen mode Exit fullscreen mode

How to configure on ios?

  • access your project and enter the android folder
cd myApp/android
Enter fullscreen mode Exit fullscreen mode
  • Initialize fastlane
Fastlane init
Enter fullscreen mode Exit fullscreen mode

Tools we will use:

  • app_store_connect_api_key: Tool that allows authentication with App Store Connect, this improves security and simplifies the implementation process.
  • build_app: Used to generate an ipa file of our application.
  • upload_to_testflight: Upload the ipa file to testflight

Generate api key

  1. Select user and access, select tab api keys

  2. Generate api key

  3. Choose a name

  4. Select the type of access -> generate the key

  5. Paste the key file into the path myApp/ios/fastlane

Configuring AppFile

# enter your app identifier
app_identifier("your app_identifier")

# enter your apple_id
apple_id("your apple_id")
Enter fullscreen mode Exit fullscreen mode

Configuring FastFile

default_platform(:ios)

platform :ios do
  desc "Deploy App to Testflight"
  lane :upload_testflight_beta do
    build_app(
      workspace: "myApp.xcworkspace", 
      scheme: "myApp",
      silent: true,
      clean: true,
    )

    api_key = app_store_connect_api_key(
      key_id: "your key id",
      issuer_id: "your issuer id",
      key_filepath: "path to file auth key",
      duration: 1200,
      in_house: false
    )

    upload_to_testflight(
      api_key: api_key,
      skip_submission: true,
      ipa: "myApp.ipa",
      skip_waiting_for_build_processing: true,
    )
  end
end

Enter fullscreen mode Exit fullscreen mode

Create script package.json

"fastlane:ios": "cd iod/Fastlane && Fastlane upload_testflight_beta"
Enter fullscreen mode Exit fullscreen mode
💖 💪 🙅 🚩
luizrebelatto
Luiz Gabriel

Posted on July 29, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related