Code Monkey home page Code Monkey logo

flutter_install_plugin's Introduction

install_plugin

Build Status pub package license

We use the install_plugin plugin to install apk for android; and using url to go to app store for iOS.

Usage

To use this plugin, add install_plugin as a dependency in your pubspec.yaml file. For example:

dependencies:
  install_plugin: '^2.1.0'

iOS

Your project need create with swift.

Android

You need to request permission for READ_EXTERNAL_STORAGE to read the apk file. You can handle the storage permission using flutter_permission_handler.

 <!-- read permissions for external storage -->
 <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

In Android version >= 8.0 , You need to request permission for REQUEST_INSTALL_PACKAGES to install the apk file

<!-- installation package permissions -->
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />

In Android version <= 6.0 , You need to request permission for WRITE_EXTERNAL_STORAGE to copy the apk from the app private location to the download directory

<!-- write permissions for external storage -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

Example

install apk from the internet

  _networkInstallApk() async {
    if (_progressValue != 0 && _progressValue < 1) {
      _showResMsg("Wait a moment, downloading");
      return;
    }

    _progressValue = 0.0;
    var appDocDir = await getTemporaryDirectory();
    String savePath = appDocDir.path + "/takeaway_phone_release_1.apk";
    String fileUrl =
        "https://s3.cn-north-1.amazonaws.com.cn/mtab.kezaihui.com/apk/takeaway_phone_release_1.apk";
    await Dio().download(fileUrl, savePath, onReceiveProgress: (count, total) {
      final value = count / total;
      if (_progressValue != value) {
        setState(() {
          if (_progressValue < 1.0) {
            _progressValue = count / total;
          } else {
            _progressValue = 0.0;
          }
        });
        print((_progressValue * 100).toStringAsFixed(0) + "%");
      }
    });

    final res = await InstallPlugin.install(savePath);
    _showResMsg(
        "install apk ${res['isSuccess'] == true ? 'success' : 'fail:${res['errorMessage'] ?? ''}'}");
  }

install apk from the local storage

  _localInstallApk() async {
    FilePickerResult? result = await FilePicker.platform.pickFiles();
    if (result != null) {
      final res = await InstallPlugin.install(result.files.single.path ?? '');
      _showResMsg(
          "install apk ${res['isSuccess'] == true ? 'success' : 'fail:${res['errorMessage'] ?? ''}'}");
    } else {
      // User canceled the picker
      _showResMsg("User canceled the picker apk");
    }
  }

Go to AppStore , example appStore url : https://itunes.apple.com/cn/app/%E5%86%8D%E6%83%A0%E5%90%88%E4%BC%99%E4%BA%BA/id1375433239?l=zh&ls=1&mt=8

  _gotoAppStore(String url) async {
    url = url.isEmpty ? _defaultUrl : url;
    final res = await InstallPlugin.install(url);
    _showResMsg(
        "go to appstroe ${res['isSuccess'] == true ? 'success' : 'fail:${res['errorMessage'] ?? ''}'}");
  }

flutter_install_plugin's People

Contributors

530209190 avatar akindone avatar hyjfine avatar lsthye avatar stevieyu avatar woodwen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

flutter_install_plugin's Issues

android install error

[ERROR:flutter/lib/ui/ui_dart_state.cc(144)] Unhandled Exception: MissingPluginException(No implementation found for method installApk on channel install_plugin)

xcode build error

/ios/Pods/Target Support Files/install_plugin/install_plugin-umbrella.h:13:9: Include of non-modular header inside framework module 'install_plugin': '/.pub-cache/hosted/pub.dartlang.org/install_plugin-2.0.0/ios/Classes/InstallPlugin.h'

error: include of non-modular header inside framework module 'install_plugin': '/.pub-cache/hosted/pub.dartlang.org/install_plugin-2.0.0/ios/Classes/InstallPlugin.h'

#import "InstallPlugin.h"
^
:0: error: could not build Objective-C module 'install_plugin'

iOS error

[!] Unable to determine Swift version for the following pods:

  • install_plugin does not specify a Swift version and none of the targets (Runner) integrating it have the SWIFT_VERSION attribute set. Please contact the author or set the SWIFT_VERSION attribute in at least one of the targets that integrate this pod.

Xcode:
The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.

Kotlin version error

  • What went wrong:
    The Android Gradle plugin supports only Kotlin Gradle plugin version 1.3.40 and higher.
    The following dependencies do not satisfy the required version:
    project ':install_plugin' -> org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.20

第三方库冲突

AndroidMainfest.xml内:
android:authorities="${applicationId}.fileProvider"字段很多人都是照着网络教程写的。
${applicationId}.fileProvider属性重复会造成冲突,
android:resource="@xml/provider_paths"同理
可以改个名字吗,或者我可以去哪里修改插件内的文本

appid参数是否可以移除

看了下代码,appid应该是当前 context的包名,是不是可以直接去掉,少个参数,因为flutter实际上跟 android中定义applicationId的地方是分离的

android:authorities

Error:
Attribute provider#androidx.core.content.FileProvider@authorities value=(com.hjj.amuse.fileProvider) from [:install_plugin] AndroidManifest.xml:12:13-64
is also present at [com.sangcomz:FishBun:0.9.0] AndroidManifest.xml:14:13-60 value=(com.hjj.amuse.provider).
Suggestion: add 'tools:replace="android:authorities"' to element at AndroidManifest.xml:10:9-18:20 to override.

install error

android plugin(24742): installApk /data/user/0/com.example/apk/example.apk com.example

install apk error: PlatformException(IllegalArgumentException, Failed to find configured root that contains /data/data/com.example/apk/example.apk,null,null)

上下两个路径不一致,是什么原因?

The plugins ` install_plugin ` use a deprecated version of the Android embedding.

flutter 2.5.1
The plugins install_plugin use a deprecated version of the Android embedding.
To avoid unexpected runtime failures, or future build failures, try to see if these plugins support the Android V2 embedding. Otherwise, consider removing them since a future release of Flutter will remove these deprecated APIs.
If you are plugin author, take a look at the docs for migrating the plugin to the V2 embedding: https://flutter.dev/go/android-plugin-migration.

install_plugin and permission_handler are the same problems in ios.

install_plugin and permission_handler are the same problems in ios. It's all the mistakes reported below. I wonder if I've ever met you before. I don't know much about ios.
error message:
install_plugin does not specify a Swift version and none of the targets (Runner) integrating it have the SWIFT_VERSIONattribute set. Please contact the author or set theSWIFT_VERSION` attribute in at least one of the targets that integrate this pod.

Need Swift version

install_plugin does not specify a Swift version and none of the targets (Runner) integrating it have the SWIFT_VERSION attribute set. Please contact the author or set the SWIFT_VERSION attribute in at least one of the targets that integrate this pod

Couldnt Find Metadata

install apk error: PlatformException(IllegalArgumentException,
 Couldn't find meta-data for provider with authority com.jio.jioplay.tv.fileProvider.install, null)

I am passing apk path and its package name(If I am right it is equal to AppID)
And yes I am using android
Android 9

Flutter 1.17.1 • channel stable •
https://github.com/flutter/flutter.git
Framework • revision f7a6a7906b (11 days
ago) • 2020-05-12 18:39:00 -0700
Engine • revision 6bc433c6b6
Tools • Dart 2.8.2

Incompatible kotlin gradle plugin version

I use com.android.tools.build:gradle:3.2.1 from flutter 1.0 template

  • What went wrong:
    The Android Gradle plugin supports only Kotlin Gradle plugin version 1.2.51 and higher. Project 'install_plugin' is using version 1.2.30.

I'm experiencing an issue with the Kotlin Gradle Plugin version.

the exact error is as stated below:

  • What went wrong:
    The Android Gradle plugin supports only Kotlin Gradle plugin version 1.5.20 and higher.
    The following dependencies do not satisfy the required version:
    project ':install_plugin_v2' -> org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.32

Thank you in advance for your assistance.

PlatformException(NullPointerException, Attempt to invoke virtual method 'android.content.res.XmlResourcePars

I am having trouble working on devices. In genymotion it works normal, but in my device I can't make it work.

install apk error: PlatformException(NullPointerException, Attempt to invoke virtual method 'android.content.res.XmlResourceParser android.content.pm.PackageItemInfo.loadXmlMetaData(android.content.pm.PackageManager, java.lang.String)' on a null object reference, null)

The apk file is in the correct folder, there are permissions but it does not install.
My manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.vigilancia"> <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <application android:name="io.flutter.app.FlutterApplication" android:label="vigilancia" android:icon="@mipmap/ic_launcher"> <activity android:name=".MainActivity" android:launchMode="singleTop" android:theme="@style/LaunchTheme" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" android:hardwareAccelerated="true" android:windowSoftInputMode="adjustResize"> <meta-data android:name="io.flutter.app.android.SplashScreenUntilFirstFrame" android:value="true" /> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity> </application> </manifest>

Can someone help me?

"There was a problem parsing the package"

Error "There was a problem parsing the package" displaying on device, while trying to install app with your plugin. If i directly opening file from file explorer it installing properly.
I followed example

install err

PlatformException(IllegalArgumentException, Couldn't find meta-data for provider with authority com.example.app_update_demo.fileProvider.install, null)

Podia ter corrido normalmente.
Repentinamente mal relatado

NullPointerException

here is my code:

void executeDownloadAndInstall(
      String platform, String versionName, DownloadModel model) async {
    final Directory directory = await getExternalStorageDirectory();
    final String saveDir = '${directory.path}';
    print(saveDir);
    String filePath = '$saveDir/${platform}_$versionName.apk';
    File apk = File(filePath);
    if (!await apk.exists()) {
      model.startDownload();
      print('create file ');
      apk = await apk.create();
      print('start download');

      List<int> downloadBytes = [];
      Stream.fromFuture(RequestHelper.request(
              'http://www.nionco.com:7001/api/smth/downloadApp?platform=$platform&versionName=$versionName',
              HttpMethod.get))
          .listen((data) {
        downloadBytes.addAll(data.bodyBytes);
        print(data.bodyBytes.length);
        model.download(data.bodyBytes.length);
        print(model.downloadSize);
      }, onDone: () async {
        await apk.writeAsBytes(downloadBytes);
        model.downloadFinished = true;
        print('start install');
        InstallPlugin.installApk(filePath, "com.example.flowersm")
            .then((result) {
          print('install apk $result');
        }).catchError((error) {
          print('install apk error:$error');
        });
      }, onError: (error) {
        print('download error $error');
        model.errorOccurred = true;
      }, cancelOnError: false);
    } else {
      print('existed');
      apk.delete();
    }
  }

the error info is:
install apk error:PlatformException(NullPointerException, Attempt to invoke virtual method 'android.content.res.XmlResourceParser android.content.pm.ProviderInfo.loadXmlMetaData(android.content.pm.PackageManager, java.lang.String)' on a null object reference, null)

FAILURE: Build failed with an exception

FAILURE: Build failed with an exception.

  • Where:
    Build file '/Users/xx/.pub-cache/hosted/pub.flutter-io.cn/flutter_plugin_android_lifecycle-1.0.5/android/build.gradle' line: 22

  • What went wrong:
    A problem occurred evaluating root project 'flutter_plugin_android_lifecycle'.

Failed to apply plugin [id 'com.android.library']
Minimum supported Gradle version is 5.4.1. Current version is 4.10.2. If using the gradle wrapper, try editing the distributionUrl in /Users/xx/.pub-cache/hosted/pub.flutter-io.cn/flutter_plugin_android_lifecycle-1.0.5/android/gradle/wrapper/gradle-wrapper.properties to gradle-5.4.1-all.zip

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.``

compile error ,may be need androidX

  • Error running Gradle:
    ProcessException: Process "D:\codes\kcytxl\android\gradlew.bat" exited abnormally:
    Starting a Gradle Daemon, 1 incompatible and 1 stopped Daemons could not be reused, use --status for details

Configure project :app
WARNING: API 'variant.getMergeAssets()' is obsolete and has been replaced with 'variant.getMergeAssetsProvider()'.
It will be removed at the end of 2019.
For more information, see https://d.android.com/r/tools/task-configuration-avoidance.
To determine what is calling variant.getMergeAssets(), use -Pandroid.debug.obsoleteApi=true on the command line to display a stack trace.
WARNING: API 'variantOutput.getProcessResources()' is obsolete and has been replaced with 'variantOutput.getProcessResourcesProvider()'.
It will be removed at the end of 2019.
For more information, see https://d.android.com/r/tools/task-configuration-avoidance.
To determine what is calling variantOutput.getProcessResources(), use -Pandroid.debug.obsoleteApi=true on the command line to display a stack trace.

Configure project :install_plugin
WARNING: API 'variant.getJavaCompile()' is obsolete and has been replaced with 'variant.getJavaCompileProvider()'.
It will be removed at the end of 2019.
For more information, see https://d.android.com/r/tools/task-configuration-avoidance.
To determine what is calling variant.getJavaCompile(), use -Pandroid.debug.obsoleteApi=true on the command line to display a stack trace.
*********************************************************
WARNING: This version of device_info will break your Android build if it or its dependencies aren't compatible with AndroidX.
See https://goo.gl/CP92wY for more information on the problem and how to fix it.
This warning prints for all Android build failures. The real root cause of the error may be unrelated.
*********************************************************

FAILURE: Build failed with an exception.

  • What went wrong:
    The Android Gradle plugin supports only Kotlin Gradle plugin version 1.3.0 and higher.
    The following dependencies do not satisfy the required version:
    project ':install_plugin' -> org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.71

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

  • Get more help at https://help.gradle.org

BUILD FAILED in 1m 7s
Command: D:\codes\kcytxl\android\gradlew.bat app:properties

Finished with error: Please review your Gradle project setup in the android/ folder.

PlatformException(NullPointerException, Attempt to invoke virtual method 'android.content.res.XmlResourceParser android.content.pm.ProviderInfo.loadXmlMetaData(android.content.pm.PackageManager, java.lang.String)' on a null object reference, null)

PlatformException(NullPointerException, Attempt to invoke virtual method 'android.content.res.XmlResourceParser android.content.pm.ProviderInfo.loadXmlMetaData(android.content.pm.PackageManager, java.lang.String)' on a null object reference, null)�[0m

has conflict and flutter_webview_plugin

Attribute provider#androidx.core.content.FileProvider@authorities value=(com.example.app.fileProvider.install) from [:install_plugin] AndroidManifest.xml:12:13-72

    is also present at [:flutter_webview_plugin] AndroidManifest.xml:11:13-64 value=(com.example.app.fileprovider).

    Suggestion: add 'tools:replace="android:authorities"' to <provider> element at AndroidManifest.xml:10:9-18:20 to override.

包冲突

与百度地图的插件flutter_bmfmap有冲突,无法同时存在

MissingPluginException(No implementation found for method installApk on channel install_plugin)

Platform: Android
OS: 8.1.0

MissingPluginException(No implementation found for method installApk on channel install_plugin)

Log as follow:

E/flutter (17248): [ERROR:flutter/shell/common/shell.cc(184)] Dart Error: Unhandled exception:
E/flutter (17248): MissingPluginException(No implementation found for method installApk on channel install_plugin)
E/flutter (17248): #0      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:291:7)
E/flutter (17248): <asynchronous suspension>
E/flutter (17248): #1      InstallPlugin.installApk (package:install_plugin/install_plugin.dart:19:27)

wrong

The Android Gradle plugin supports only Kotlin Gradle plugin version 1.2.51 and higher. Project 'install_plugin' is using version 1.2.30.

install_plugin/install_plugin-Swift.h

Xcode's output:

/Users/songzhaojie/.pub-cache/hosted/pub.flutter-io.cn/install_plugin-2.0.0/ios/Classes/InstallPlugin.m:2:9: fatal error: 'install_plugin/install_plugin-Swift.h' file not found
#import <install_plugin/install_plugin-Swift.h>
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

解析错误

解析错误,解析程序包时出现问题。

用外部浏览器下载包没有问题,app内部下载用这个插件安装就出现解析错误

D/android plugin(17226): installApk /data/data/com.aaa.bbb/cache/app.apk com.aaa.bbb
D/FlutterView(13737): Detaching from a FlutterEngine: io.flutter.embedding.engine.FlutterEngine@36bccd6e
W/InputMethodManager(13737): startInputInner : InputBindResult == null

install apk error:Couldn't find meta-data

install apk error: PlatformException(IllegalArgumentException, Couldn't find meta-data for provider with authority com.suyetech.sy_im.fileProvider.install, null)

android 6.0 应用签名异常

Android 9.0 正常。不过Android 6.0 安装时 出现 应用签名异常。这是个bug 还是 我落了关键点?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.