Flutter用--enable-software-rendering构建apk? [英] Flutter build apk with --enable-software-rendering?

查看:485
本文介绍了Flutter用--enable-software-rendering构建apk?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以执行以下操作:

Is it possible to do something like this:

flutter build apk --enable-software-rendering

我需要一个发布版本,其执行方式为:

I need a release version that performs the say way as:

flutter run --enable-software-rendering --profile

谢谢。

推荐答案

TL; DR 输入 getIntent() .putExtra( enable-software-rendering,true); 在您的 onCreate()


注意-我假设Android来自 apk

Note - I assumed Android from the "apk" in question title and the need for software rendering.

查看源代码-enable-software-rendering 标志,用于波动运行,导致活动使用 am start -ez enable-software-rendering true ,将其作为布尔值添加到意图中。

Looking at the source code, the --enable-software-rendering flag for flutter run causes the activity to be launched using am start with --ez enable-software-rendering true, which puts that as a boolean extra into the intent.

如果您希望控制何时使用软件从代码进行渲染(例如,取决于API级别或设备模型),请在 onCreate()中尽早设置上述意图。

If you wish to control when to use software rendering from code (such as depending on API level or device model), set the mentioned intent extra early in your onCreate().

完整示例:

import android.os.Bundle;
import io.flutter.embedding.android.FlutterActivity;

public class MyActivity extends FlutterActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {

        // use software rendering (ideally only when you need to)
        getIntent().putExtra("enable-software-rendering", true);

        // start Flutter
        super.onCreate(savedInstanceState);
    }
}

这篇关于Flutter用--enable-software-rendering构建apk?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆