English 中文(简体)
只释放到某些平台时, 如何排除不必要的抚养包?
原标题:How to exclude unnecessary dependency packages when only releasing for certain platform?

我正在创建一个 dart http 库库用于 flutter 应用程序。 我从 < a href=" https://pub. dev/packages/http# configiforation" rel= "nofollown noreferrer" > >here 中学习到, 每个不同的平台都需要不同的 http 客户端执行, 如 cronet_http/code >, cupertino_http < /code>, , fetch_client 。 所以我必须在软件包 s pubspec.yaml 中包括所有可能的依附关系, 并使用有条件的导入。

问题是,如果我只想在某个平台上发布我的应用程序,不管是它还是机器人。 iOS和网络的依赖性会被纳入他的应用程序吗? 如果是的话,应用程序的大小将会不必要地大于要求。

编辑 :

It s hard to check whether the unnecessary dependencies included or not, because for cronet_http or cupertino_http, i think it s only about several bytes in size. So instead, i am trying to derive the conclusion that, if cupertino_http is not used in the finally released Android app, but it s included, it will be certainly increase the size of the app by some extent. Do i have to really make an app for this library and check whether it s several bytes larger than expected, so that i am qualified to ask my question?

我想象到,可以采取如下一种办法,排除不必要依赖性:

  1. specify cronet_http and cupertino_http as optional dependencies, like there is android_dependencies, or ios_dependencies, besides dependencies in pubspec.yaml.
  2. And let the library users select which dependency to include in his/her release, with the dependencies.

或者在 dev_dependies 中保留可选择的依存关系,并可选择检测和导入包含的依存关系,然后让用户在 dependies 中选择哪个。

很高兴知道有一个treshashking algo在摇摆中去掉这些不必要的依赖代码。但我很难从谷歌找到一些关于它的文件。只有几个博客讨论它,只是更混乱一些,比如 这个问题 说。

最佳回答

Normally Darts linker is pretty good to remove all that isn t needed using its treeshaking algorithm. Especially plugins will always only include the platform-specific code that is used for that platform in your final app. In general, unless you find a problem with size or performance don t try to optimize without need.

问题回答

暂无回答




相关问题
Flutter App cannot be installed on Android TV

I m building a Flutter app that should support Android TV and Mobile devices. Despite Google Play shows that it is supported, I cannot install app on my MiBox device. While trying to install it, both ...

Moving the icon button to the right causes rendering issues

I am trying to align the icon button to the right of the Text field, I tried the row which made the icon button not centered vertically and now I am trying out the Stack widget. Here is my code - ...