flutter-apk

2021-01-08  本文已影响0人  ChaosHeart

前言:

flutter打包apk,需要连网

1.签名(两种)

目录结构如下:


截屏2021-01-08 08.39.44.png

(1)第一种,直接build.gradle文件配置:

signingConfigs {

debug {
storeFile file("app/keystore.properties")
storePassword "111111"
keyAlias "key"
keyPassword "111111"
}

release {
storeFile file("app/keystore.properties")
storePassword "111111"
keyAlias "key"
keyPassword "111111"
}
}
buildTypes {
debug {
signingConfig signingConfigs.debug
}

release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}

}

(2)第二种,通过读取文件

keystore.properties文件配置

//文件
storeFile=keyStore.jks 
//文件密码
storePassword=123456
//App名字
keyAlias=encrypt
//密码
keyPassword=123456

build.gradle文件配置

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    compileSdkVersion 28

//读取keyStore.properties文件
    def keystorePropertiesFile = rootProject.file("keyStore.properties")
    def keystoreProperties = new Properties()
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
    signingConfigs {
        release {
            storeFile file(keystoreProperties["storeFile"])
            storePassword keystoreProperties["storePassword"]
            keyAlias keystoreProperties["keyAlias"]
            keyPassword keystoreProperties["keyPassword"]
        }
    }
    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        applicationId "com.foxconn.encrypt"
        minSdkVersion 23
        targetSdkVersion 28
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            signingConfig signingConfigs.release
            minifyEnabled false
            shrinkResources false
        }
    }
}

2.清空缓存

flutter clean

3.打包apk

flutter build apk --release

4.成功截图

截屏2021-01-05 09.25.05.png

5.检查apk

截屏2020-12-22 09.00.31.png
截屏2020-12-22 09.02.30.png

6.apk所在位置

截屏2020-12-22 10.13.07.png
上一篇 下一篇

猜你喜欢

热点阅读