close

how to get .apk and .ipa file from flutter?

APK and IPA are application bundling designs for Android and iOS separately. At the point when you are finished structure (and testing!) your Flutter application and prepared to distribute it to the Play Store and the App Store, you need to fabricate an APK and an IPA. You can arrangement a nonstop form of APKs and IPAs on Travis.

Building APKs

Formally Travis just backings the Android SDK on Linux. We need to set language to android, advise Travis to acknowledge Android licenses and introduce an adequate arrangement of segments. Accepting your Flutter application is at the base of the git vault, the .travis.yml record underneath has all you require:

os: linux
language: android
licenses:
  - 'android-sdk-preview-license-.+'
  - 'android-sdk-license-.+'
  - 'google-gdk-license-.+'
android:
  components:
    - tools
    - platform-tools
    - build-tools-25.0.3
    - android-25
    - sys-img-armeabi-v7a-google_apis-25
    - extra-android-m2repository
    - extra-google-m2repository
    - extra-google-android-support
jdk: oraclejdk8
sudo: false
addons:
  apt:
    # Flutter depends on /usr/lib/x86_64-linux-gnu/libstdc++.so.6 version GLIBCXX_3.4.18
    sources:
      - ubuntu-toolchain-r-test # if we don't specify this, the libstdc++6 we get is the wrong version
    packages:
      - libstdc++6
      - fonts-droid
before_script:
  - wget http://services.gradle.org/distributions/gradle-3.5-bin.zip
  - unzip -qq gradle-3.5-bin.zip
  - export GRADLE_HOME=$PWD/gradle-3.5
  - export PATH=$GRADLE_HOME/bin:$PATH
  - git clone https://github.com/flutter/flutter.git -b alpha --depth 1
script:
  - ./flutter/bin/flutter -v build apk

cache:
  directories:
    - $HOME/.pub-cache

The accompanying line introduces Flutter itself:

git clone https://github.com/flutter/flutter.git -b alpha --depth 1

At long last this line assembles the APK:

./flutter/bin/flutter -v build apk

Building IPAs

IPAs must be based on macOS and you need Xcode order line apparatuses introduced. Fortunately, you don’t have to know how Xcode order line instruments work. Shudder wraps all the xcode orders in a pleasant CLI. All things considered, in the event that you are capable with Xcode, a Flutter venture is as yet a customary Xcode venture, which you can fabricate straightforwardly utilizing the Xcode UI and order line instruments.

Presently, we should advise Travis to give us a macOS (actually referred to Travis as osx) climate with Xcode and other Flutter conditions. Once more, accepting your Flutter venture is at the foundation of the git storehouse, the accompanying .travis.yml record is all you require:

os: osx
language: generic
osx_image: xcode8.3
before_script:
  - pip install six
  - brew update
  - brew install --HEAD libimobiledevice
  - brew install ideviceinstaller
  - brew install ios-deploy
  - git clone https://github.com/flutter/flutter.git -b alpha --depth 1
script:
  - ./flutter/bin/flutter -v build ios --no-codesign

cache:
  directories:
    - $HOME/.pub-cache
   

In this model, we are building an “unsigned” IPA document. This implies that you need to sign it before you can run it on an actual iOS gadget or distribute to Apple’s App Store. Code marking is a “captivating” theme that is out of extent of this post, yet you can find out about it here.

Building both utilizing a form lattice

“Yet, stand by,” you state, “isn’t Flutter about building both for Android and iOS?”

Why yes it is! Things being what they are, in case we’re constructing at the same time for the two stages, would we be able to assemble IPAs and APKs all the while as well? Obviously! The issue however, is that one expands on Linux, and the other one expands on Mac. For that, Travis has a component called construct lattice. A form grid can run numerous form occupations as a component of a solitary form. So we can consolidate the over two .travis.yml documents into one record with a form framework, as so:

matrix:
  include:
    - os: linux
      language: android
      licenses:
        - 'android-sdk-preview-license-.+'
        - 'android-sdk-license-.+'
        - 'google-gdk-license-.+'
      android:
        components:
          - tools
          - platform-tools
          - build-tools-25.0.3
          - android-25
          - sys-img-armeabi-v7a-google_apis-25
          - extra-android-m2repository
          - extra-google-m2repository
          - extra-google-android-support
      jdk: oraclejdk8
      sudo: false
      addons:
        apt:
          # Flutter depends on /usr/lib/x86_64-linux-gnu/libstdc++.so.6 version GLIBCXX_3.4.18
          sources:
            - ubuntu-toolchain-r-test # if we don't specify this, the libstdc++6 we get is the wrong version
          packages:
            - libstdc++6
            - fonts-droid
      before_script:
        - wget http://services.gradle.org/distributions/gradle-3.5-bin.zip
        - unzip -qq gradle-3.5-bin.zip
        - export GRADLE_HOME=$PWD/gradle-3.5
        - export PATH=$GRADLE_HOME/bin:$PATH
        - git clone https://github.com/flutter/flutter.git -b alpha --depth 1
      script:
        - ./flutter/bin/flutter -v build apk

    - os: osx
      language: generic
      osx_image: xcode8.3
      before_script:
        - pip install six
        - brew update
        - brew install --HEAD libimobiledevice
        - brew install ideviceinstaller
        - brew install ios-deploy
        - git clone https://github.com/flutter/flutter.git -b alpha --depth 1
      script:
        - ./flutter/bin/flutter -v build ios --no-codesign

cache:
  directories:
    - $HOME/.pub-cache

Making assembles quick

The methodology above works. In any case, there’s a little issue. This Android and Xcode SDK establishment and building requires some serious energy. In the event that your task utilizes a force demand framework, you may need pull solicitations to be checked for blunders rapidly and permit it to be consolidated. In my past post I discussed Flutter’s super-quick UI testing structure. Running a Travis fabricate that runs Flutter tests just pauses for a moment or two, which incorporates introducing Flutter itself. APK/IPA building can add over 10 minutes to the cycle. That can be irritating. what can be done?

I’ll show you one approach to accelerate your assemble – make a third employment in the construct grid, which just runs tests. You set the fast_finish banner on your fabricate, and imprint all positions aside from that one test work as discretionary utilizing the allow_failures alternative. Travis will in any case run all the positions and assemble APKs and IPAs. Nonetheless, it won’t sit tight for APK/IPA tasks to wrap up. When the test work succeeds or comes up short, it will promptly paint your force demand in the separate tone. Here’s the full .travis.yml record:

matrix:
  # This causes the build to complete immediately upon first failure or once
  # required jobs are green.
  fast_finish: true

  # Building APK/IPA takes a long time; do not wait for them to finish.
  allow_failures:
    - env: JOB=APK
    - env: JOB=IPA

  include:
    # Runs unit tests without emulators.
    - env: JOB=PR
      os: linux
      language: generic
      sudo: false
      addons:
        apt:
          # Flutter depends on /usr/lib/x86_64-linux-gnu/libstdc++.so.6 version GLIBCXX_3.4.18
          sources:
            - ubuntu-toolchain-r-test # if we don't specify this, the libstdc++6 we get is the wrong version
          packages:
            - libstdc++6
            - fonts-droid
      before_script:
        - git clone https://github.com/flutter/flutter.git -b alpha --depth 1
      script:
        - ./flutter/bin/flutter test

    # Builds an APK.
    - env: JOB=APK
      os: linux
      language: android
      licenses:
        - 'android-sdk-preview-license-.+'
        - 'android-sdk-license-.+'
        - 'google-gdk-license-.+'
      android:
        components:
          - tools
          - platform-tools
          - build-tools-25.0.3
          - android-25
          - sys-img-armeabi-v7a-google_apis-25
          - extra-android-m2repository
          - extra-google-m2repository
          - extra-google-android-support
      jdk: oraclejdk8
      sudo: false
      addons:
        apt:
          # Flutter depends on /usr/lib/x86_64-linux-gnu/libstdc++.so.6 version GLIBCXX_3.4.18
          sources:
            - ubuntu-toolchain-r-test # if we don't specify this, the libstdc++6 we get is the wrong version
          packages:
            - libstdc++6
            - fonts-droid
      before_script:
        - wget http://services.gradle.org/distributions/gradle-3.5-bin.zip
        - unzip -qq gradle-3.5-bin.zip
        - export GRADLE_HOME=$PWD/gradle-3.5
        - export PATH=$GRADLE_HOME/bin:$PATH
        - git clone https://github.com/flutter/flutter.git -b alpha --depth 1
      script:
        - ./flutter/bin/flutter -v build apk

    # Builds an IPA.
    - env: JOB=IPA
      os: osx
      language: generic
      osx_image: xcode8.3
      before_script:
        - pip install six
        - brew update
        - brew install --HEAD libimobiledevice
        - brew install ideviceinstaller
        - brew install ios-deploy
        - git clone https://github.com/flutter/flutter.git -b alpha --depth 1
      script:
        - ./flutter/bin/flutter -v build ios --no-codesign

cache:
  directories:
    - $HOME/.pub-cache

A drawback to this methodology is that your construct is as yet viewed as fruitful in any event, when an IPA or an APK neglects to fabricate. You can utilize custom shell contents and check for explicit Travis climate factors to get around this limitation. In light of a legitimate concern for keeping this post short, I’ll need to exclude the subtleties.

I trust this data encourages you arrangement an extremely profitable advancement cycle for your Flutter ventures.

Cheerful coding !

Leave a Comment