Flutter 笔记

相关链接

环境搭建

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
# 环境变量清华大学镜像
PUB_HOSTED_URL
https://mirrors.tuna.tsinghua.edu.cn/dart-pub

FLUTTER_STORAGE_BASE_URL
https://mirrors.tuna.tsinghua.edu.cn/flutter

# 下载 SDK
https://storage.flutter-io.cn/flutter_infra/releases/stable/windows/flutter_windows_1.17.4-stable.zip

# path
D:\Link\flutter\bin

# 更新包
flutter pub get

flutter doctor
flutter create flutter_demo
cd flutter_demo
flutter run

中国镜像

D:\Link\flutter\packages\flutter_tools\gradle\flutter.gradle

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
buildscript {
    repositories {
        maven { url 'https://maven.aliyun.com/repository/jcenter' }
        maven { url 'https://maven.aliyun.com/repository/google' }
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.0'
    }
}

打包 APK

生成签名文件

D:\WWW\flutter\keystore\key.jks 为密钥生成目录,可根据自身需要修改

1
keytool -genkey -v -keystore D:\WWW\flutter\keystore\key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias key

新建 android\key.properties

1
2
3
4
storePassword=123456
keyPassword=123456
keyAlias=key
storeFile=D:/WWW/flutter/keystore/key.jks

修改android\app\build.gradle

28行

1
2
3
4
5
def keystorePropertiesFile = rootProject.file("key.properties")
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))

compileSdkVersion 28

48行

1
2
3
4
5
6
7
8
signingConfigs {
    release {
        keyAlias keystoreProperties['keyAlias']
        keyPassword keystoreProperties['keyPassword']
        storeFile file(keystoreProperties['storeFile'])
        storePassword keystoreProperties['storePassword']
    }
}

53行

1
2
3
4
5
6
7
buildTypes {
    release {
        // TODO: Add your own signing config for the release build.
        // Signing with the debug keys for now, so `flutter run --release` works.
        signingConfig signingConfigs.release
    }
}