【问题标题】:Adding run/debug configuration environment variables to a flutter project?将运行/调试配置环境变量添加到颤振项目?
【发布时间】:2022-10-24 21:03:15
【问题描述】:

我正在尝试在 Android Studio 的颤振项目中将环境变量添加到我的运行/调试配置中,但该字段显示为灰色,我不知道如何以其他方式创建环境变量。任何想法如何以这种方式或其他方式添加它们?

A picture of my Run/Debug cConfigurations where the Environment variables are greyed out

【问题讨论】:

  • 您应该为您的项目创建不同的风格,然后将各自的风格添加到 Build Flavor 选项中。

标签: flutter android-studio environment-variables


【解决方案1】:

一种不推荐的方法是编辑flutter 命令源文件(脚本文件:unix: bash,windows: bat)。 see here
我正在使用 linux 并且我遇到了应用程序规模的问题(因为我使用的是 hidpi 屏幕),解决问题的最简单方法是设置环境变量GDK_SCALE=2。经过一番挣扎,我终于像这样编辑了我的颤振源文件:

#!/usr/bin/env bash
# Copyright 2014 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

export GDK_SCALE=2
# ---------------------------------- NOTE ---------------------------------- #
#
# Please keep the logic in this file consistent with the logic in the
# `flutter.bat` script in the same directory to ensure that Flutter continues


# ... [content omitted] ...

如果您想在启动新项目时更改环境变量,请考虑RUN confiugration 中的before launch 选项,您可以在运行当前配置之前运行其他配置。理想的运行顺序是运行delete environment variable lines配置(Shell Script类型),然后执行(启动前)flutter run配置,然后执行(启动前)add environment variable lines配置(Shell脚本类型)。(共3个配置文件按顺序链接)它还应该显示颤振调试窗口,因为此选项存在于flutter run 配置中。

我尝试过的其他方法:

  1. 设置全局环境(所有应用规模发生变化)
  2. 修改android studio桌面文件(android studio大小改变)
  3. 破解 android studio 运行配置(如 $(export x=1) 执行命令,但失败)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-08-19
    • 2020-10-16
    • 1970-01-01
    • 1970-01-01
    • 2020-02-06
    • 2016-09-25
    • 2020-08-27
    • 1970-01-01
    相关资源
    最近更新 更多