8

let's say i have a Flutter APK hosted on my website where users can download and install , what i'm interested to know is how possible that the application can check for newer version when the app lunches and if true a progress bar appears showing the automatic updating of the application from the server (not play store or app store) ? .
here is a company that do exactly the mentioned above meaning :

  • download the apk from there server
  • whenever a new version is released the app will update from their server

any ideas how to achieve this ?

5
  • 1
    How wide is the distribution? Are you supporting a handful of installs or many?
    – spartygw
    Sep 8, 2020 at 20:06
  • @spartygw it's one app and each time i upload a new version users will auto update their version to the new one, does this answer your question ?
    – Asmoun
    Sep 8, 2020 at 20:20
  • 1
    No, I meant to ask how many users are installing this app? Depending on your answer I may have a proposed solution.
    – spartygw
    Sep 8, 2020 at 20:24
  • @spartygw i would say 50 to 100 active users on my website , and now i'm developing this flutter app , but it is scalable up to 1k active users daily
    – Asmoun
    Sep 8, 2020 at 20:46
  • 1
    I would say, that you will need to implement the download of the APK from your server, for that you can use several packages available, while you have finished downloading just launch the apk installation, for this you will need to create a plugin yourself to use Android native code.
    – Jav T
    Sep 9, 2020 at 4:35

5 Answers 5

12

i found this package ota_update 2.4.1,looks very promising for updating a Flutter from a remote hosted Apk here is an exmple :

   // IMPORT PACKAGE
    import 'package:ota_update/ota_update.dart';
    
      // RUN OTA UPDATE 
      // START LISTENING FOR DOWNLOAD PROGRESS REPORTING EVENTS
      try {
          //LINK CONTAINS APK OF FLUTTER HELLO WORLD FROM FLUTTER SDK EXAMPLES
          OtaUpdate()
              .execute(
            'https://internal1.4q.sk/flutter_hello_world.apk',
            // OPTIONAL
            destinationFilename: 'flutter_hello_world.apk',
            //OPTIONAL, ANDROID ONLY - ABILITY TO VALIDATE CHECKSUM OF FILE:
            sha256checksum: "d6da28451a1e15cf7a75f2c3f151befad3b80ad0bb232ab15c20897e54f21478",
          ).listen(
            (OtaEvent event) {
              setState(() => currentEvent = event);
            },
          );
      } catch (e) {
          print('Failed to make OTA update. Details: $e');
      }

any other proposed solutions are welcome.

5
  • 2
    This plugin looks good to me for this use case, alternative would be to download APK using something like flutter_downloader, and start initent for install using android_intent. Sep 11, 2020 at 5:32
  • 1
    But that is too much work!! Just use the plugin you mentioned, if it functions well. Sep 11, 2020 at 5:32
  • 1
    hi , how to get sha256checksum?
    – ff .n
    Apr 10, 2021 at 9:47
  • @ff.n hello, based on the documentation i think it is optional so you can pass it , if you found the answer useful can you please upvote the post and answer
    – Asmoun
    Apr 10, 2021 at 18:35
  • I use ota_update:4.0.1 and it works like a charm for downloading and installing a new .apk from hosted server
    – cwhisperer
    Jan 6, 2022 at 13:16
9
+50

ota_update(as mentioned by @Asmoun) looks good to me for this use case, alternative would be to download APK using something like flutter_downloader and start intent for install using android_intent.

Moreover for fetching latest version code or download URL, I suggest you use firebase_remote_config.

3
  • 1
    @Asmoun Let me know if you need some code sample. The readme instructions of those plugins look self-explanatory to me! Sep 13, 2020 at 17:42
  • yes it would be great if you can share the code sample. I need to do this in my project, but not sure exactly what all I need to do. If I use ota_update and give the link to the apk file on my server, shouldn't be it good enough? What is the need of flutter_downloader and other packages that you mentioned. Thanks in advance May 20, 2021 at 11:03
  • Great, thanks.. Jan 28, 2022 at 7:38
4

You can write a service on the server-side that check the current version with the old version in the splash screen. First, you must send the current version to the server and check version uploading with the old version uploaded then if there are a new version return alert and apk for download

1
  • Salem , thanks for the help can you refer to some links please for Flutter
    – Asmoun
    Sep 9, 2020 at 8:32
2

import 'package:ota_update/ota_update.dart';

  // RUN OTA UPDATE 
  // START LISTENING FOR DOWNLOAD PROGRESS REPORTING EVENTS
  try {
      //LINK CONTAINS APK OF FLUTTER HELLO WORLD FROM FLUTTER SDK EXAMPLES
      OtaUpdate()
          .execute(
        'https://internal1.4q.sk/flutter_hello_world.apk',
        // OPTIONAL
        destinationFilename: 'flutter_hello_world.apk',
        //OPTIONAL, ANDROID ONLY - ABILITY TO VALIDATE CHECKSUM OF FILE:
        sha256checksum: "d6da28451a1e15cf7a75f2c3f151befad3b80ad0bb232ab15c20897e54f21478",
      ).listen(
        (OtaEvent event) {
          setState(() => currentEvent = event);
        },
      );
  } catch (e) {
      print('Failed to make OTA update. Details: $e');
  }

To get the sha256checksum, in linux the command is sha256sum followed by the path of the apk file. Example:
sha256sum .../build/app/outputs/flutter- apk/app-release.apk > outputFilename
cat outputFilename
here is the sha256checksum
01b65bdbef021df3ceae02c03aeb303770d03d02f100693ab3f4d6aca599ab4c

1

If you need this for Android only, you could use the in_app_update library.

If you need functionality for iOS too, the above library recommends upgrader that does something similar but not the same.

1
  • thanks for the help but i'm looking for a solution for Flutter app
    – Asmoun
    Sep 12, 2020 at 19:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.