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 ?

Asmoun
  • 1,417
  • 5
  • 20
  • 53
  • 1
    How wide is the distribution? Are you supporting a handful of installs or many? – spartygw Sep 08 '20 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 08 '20 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 08 '20 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 08 '20 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 09 '20 at 04:35

5 Answers5

10

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.

Asmoun
  • 1,417
  • 5
  • 20
  • 53
  • 1
    This plugin looks good to me for this use case, alternative would be to download APK using something like [flutter_downloader](https://pub.dev/packages/flutter_downloader), and start initent for install using [android_intent](https://pub.dev/packages/android_intent). – Harsh Bhikadia Sep 11 '20 at 05:32
  • 1
    But that is too much work!! Just use the plugin you mentioned, if it functions well. – Harsh Bhikadia Sep 11 '20 at 05:32
  • 1
    hi , how to get sha256checksum? – ff .n Apr 10 '21 at 09: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 '21 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 06 '22 at 13:16
7

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.

Asmoun
  • 1,417
  • 5
  • 20
  • 53
Harsh Bhikadia
  • 10,095
  • 9
  • 49
  • 70
  • 1
    @Asmoun Let me know if you need some code sample. The readme instructions of those plugins look self-explanatory to me! – Harsh Bhikadia Sep 13 '20 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 – Sunpreet Singh May 20 '21 at 11:03
  • Great, thanks.. – vishalknishad Jan 28 '22 at 07: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

hosein moradi
  • 444
  • 3
  • 7
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.

S.V.
  • 1,181
  • 6
  • 23
1

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