如何在Ubuntu上没有Android Studio的情况下安装Flutter

In this article, I will show you how to install Flutter on Ubuntu, Google’s framework for mobile, web, and desktop applications. I will use Ubuntu 20.04 but it will also work with Ubuntu 18.04 or higher. This process will make use of your terminal, so open it up and let’s get started.

在本文中,我将向您展示如何在Ubuntu(用于移动,Web和桌面应用程序的Google框架)上安装Flutter。 我将使用Ubuntu 20.04,但它将与Ubuntu 18.04或更高版本一起使用。 此过程将利用您的终端,因此打开它,让我们开始吧。

下载包 (Download Packages)

First download Flutter and the command-line tools

首先下载Flutter命令行工具

Then download Java 8 and Git through the terminal.

然后通过终端下载Java 8和Git。

Note: The latest versions of Java, are showing some problems with the flutter so we will use version 8 because it is the most indicated

注意 :Java的最新版本显示出一些抖动问题,因此我们将使用版本8,因为它是最能说明问题的版本

sudo apt install openjdk-8-jre

sudo apt install openjdk-8-jre

sudo apt install git

sudo apt install git

设置环境变量 (Setup Environment Variables)

安卓 (Android)

Go to the folder where you downloaded the command line tools package and unzip the file. You can use the ls command to find out the name of the file.

转到下载命令行工具包的文件夹,然后解压缩该文件。 您可以使用ls命令找出文件的名称。

unzip commandlinetools-linux-6514223_latest.zip

unzip commandlinetools-linux-6514223_latest.zip

Now, create a new folder and name it Android, and then move the folder you extract to this new folder.

现在,创建一个新文件夹并将其命名为Android ,然后将提取的文件夹移动到该新文件夹。

mkdir Android

mkdir Android

sudo mv tools/ Android/

sudo mv tools/ Android/

We’re going to move the Android folder to another directory. I will move it to my home folder.

我们将把Android文件夹移动到另一个目录。 我将其移至主文件夹。

sudo mv Android/ ~/

sudo mv Android/ ~/

Go to your home directory and open the file .profile in your favorite editor. This file will keep your environment variables.

转到您的主目录,然后在您喜欢的编辑器中打开文件.profile 。 该文件将保留您的环境变量。

cd ~/

cd ~/

sudo gedit .profile

sudo gedit .profile

At the end of the file, type, or copy these few lines. Make sure you don’t put extra spaces and then save your file.

在文件末尾,键入或复制以下几行。 确保您没有放置多余的空格,然后保存文件。

Note: If you did not move your Android folder to the home directory, substitute the first line with the path to where you move it.

注意 :如果您没有将Android文件夹移动到主目录,请用移动路径替换第一行。

# Android
export ANDROID=$HOME/Android
export PATH=$ANDROID/tools:$PATH
export PATH=$ANDROID/tools/bin:$PATH
export PATH=$ANDROID/platform-tools:$PATH# Android SDK
export ANDROID_SDK=$HOME/ANDROID
export PATH=$ANDROID_SDK:$PATH

(Flutter)

Go to where you downloaded the Flutter package and extract it.

转到下载Flutter软件包并解压缩的位置。

tar xvf flutter_linux_1.17.3-stable.tar.xz

tar xvf flutter_linux_1.17.3-stable.tar.xz

Move the flutter folder to a new directory. I will also move it to my home directory.

flutter文件夹移动到新目录。 我还将其移至我的主目录。

sudo mv flutter/ ~/

sudo mv flutter/ ~/

Go to your home directory, open up .profile again, and type the lines below. Save your file.

转到您的主目录,再次打开.profile ,然后键入以下行。 保存文件。

# Flutter
export FLUTTER=$HOME/flutter
export PATH=$FLUTTER/bin:$PATH

Now our environment variables are created, and to make it work, all we need to do is type the line below in the terminal:

现在,我们的环境变量已创建,要使其起作用,我们所需要做的就是在终端中键入以下行:

source ~/.profile

source ~/.profile

Android配置 (Android Configuration)

Type the following lines in your terminal.

在终端中键入以下行。

The android-29 means we are getting Android 10 in our emulator. If you want Android 11 just put android-30, and for the older ones, you can downgrade the number.

android-29意味着我们正在模拟器中获得Android 10。 如果您想将Android 11放到android-30上,而对于较旧的版本,则可以将其降级。

Note: If you get an error, don’t worry. This happened only because we name the folder that contains our command-line tools as Android, you only have to type sdkmanager --sdk_root=${ANDROID} tools

注意 :如果出现错误,请不要担心。 发生这种情况仅是因为我们将包含命令行工具的文件夹命名为Android ,而只需键入sdkmanager --sdk_root=${ANDROID} tools

sdkmanager "system-images;android-29;google_apis;x86_64"
sdkmanager "platforms;android-29"
sdkmanager "platform-tools"
sdkmanager "patcher;v4"
sdkmanager "emulator"
sdkmanager "build-tools;29.0.2"

Now accept the licenses.

现在接受许可证。

sdkmanager --licenses

sdkmanager --licenses

颤振配置 (Flutter Configuration)

We are going to configure Flutter by setting the path to the Android SDK.

我们将通过设置Android SDK的路径来配置Flutter。

flutter config --android-sdk ~/Android

flutter config --android-sdk ~/Android

After that, you should get the message.

在那之后,您应该得到消息。

Image for post

创建模拟器 (Creating the Emulator)

Type the line below and this will show a list of devices, choose one, and copy its ID.

键入下面的行,这将显示设备列表,选择一个设备,然后复制其ID。

avdmanager list

avdmanager list

Give a name to your emulator and paste the ID that you copy on the following line.

给您的仿真器起个名字,然后将您复制的ID粘贴到下一行。

avdmanager -s create avd -n name -k "system-images;android-29;google_apis;x86_64" -d id_device

奏效了吗? (Did it Work?)

Run flutter doctor

flutter doctor

It should appear all green for the exception of the Android Studio path.

除了Android Studio路径外,它应该全部显示为绿色。

If everything worked fine, now let’s launch the emulator. You can do this by either run flutter emulator --launch name in your terminal or you can test launch from Visual Studio Code, install the Flutter plugin, and create a new project by using CTRL + SHIFT + P and type Flutter: create a new project.

如果一切正常,现在让我们启动模拟器。 您可以通过运行flutter emulator --launch name来执行此flutter emulator --launch name 在您的终端中,或者您可以测试从Visual Studio Code启动,安装Flutter插件,并使用CTRL + SHIFT + P Flutter: create a new project然后键入Flutter: create a new project

Image for post

Now you are ready to create your Flutter applications have fun!

现在您准备好创建您的Flutter应用程序了!

翻译自: https://levelup.gitconnected.com/how-to-install-flutter-without-android-studio-on-ubuntu-6d8b55741afa

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值