生成签名的指令:

keytool -genkey -v -keystore ./key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias key

说明:keytool -export -alias 【密钥别名】-file 【导出途径】-keystore 【密钥文件途径】-storepass 【暗码】

打包 apk 指令:

flutter build apk

指定架构 apk 打包 指令:

flutter build apk --obfuscate --split-debug-info=debugInfo --target-platform android-arm,android-arm64,android-x64 --split-per-abi

打包完成后会在 build/app/outputs/apk/release下呈现一个 app-release.apk 的文件。

打包bundle指令:

flutter build appbundle

打包完成后会在 build/app/outputs/bundle/release/app-release.aab呈现一个aab 的文件,重命名后上传到google play 即可。

上传Google PLay

在经过指令行打包aab 上传googleplay 后呈现了 您上传的是在调试形式下签名的 APK 或 Android App Bundle。请在发布形式下为 APK 或 Android App Bundle 签名的问题

Flutter 打包aab 并上传到google play

所以后台改为了运用android studio进行打包

Flutter 打包aab 并上传到google play

Flutter 打包aab 并上传到google play

Flutter 打包aab 并上传到google play

Flutter 打包aab 并上传到google play

点击 create 便会在release 下生成好对应的aab 包,简略的重命名下就可以成功上传google play 了。

版本号修改

每次升级使用都会需求修改一下使用的版本号,那么如何操作呢?

(安卓原生项目)

Flutter 打包aab 并上传到google play

(Flutter项目)

Flutter 打包aab 并上传到google play

当然您也可以直接修改android 文件夹下的版本信息直接进行打包 文件途径:android/local.properties

sdk.dir=/Users/ymc/Library/Android/sdk
flutter.sdk=/usr/local/flutter
flutter.buildMode=release
flutter.versionName=1.0.2
flutter.versionCode=3

Flutter 项目中 假如需求在项目中显示版本号,以GETX 示例:

binding.dart

import 'package:get/get.dart';
import 'controller.dart';
class AboutScreenBinding extends Bindings {
  @override
  void dependencies() {
    Get.lazyPut(() => AboutScreenController());
  }
}

controller.dart

import 'package:get/get.dart';
import 'package:package_info/package_info.dart';
import 'state.dart';
class AboutScreenController extends GetxController {
  final AboutScreenState state = AboutScreenState();
  @override
  void onReady() {
    super.onReady();
    getPackageInfo();
  }
  Future<Map<String, String>> getPackageInfo() async {
    PackageInfo packageInfo = await PackageInfo.fromPlatform();
    state.appName = packageInfo.appName;
    state.packageName = packageInfo.packageName;
    state.version = packageInfo.version;
    state.buildNumber = packageInfo.buildNumber;
    update(['about_version']);
    //Map<String, String> info = {};
    //info.addAll({ 'appName': packageInfo.appName });
    //info.addAll({ 'packageName': packageInfo.packageName });
    //info.addAll({ 'version': packageInfo.version });
    //info.addAll({ 'buildNumber': packageInfo.buildNumber });
    //return info;
  }
}

state.dart

class AboutScreenState {
  String version = '';
  String appName = '';
  String packageName = '';
  String buildNumber = '';
  AboutScreenState() {
    ///Initialize variables
  }
}

view.dart

import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:keta/common/values/main.dart';
import 'package:keta/component/app/constans/app_colors.dart';
import '../../../component/app/constans/app_icons.dart';
import '../../../component/system/app_bar.dart';
import '../../../lang/keys.dart';
import 'controller.dart';
class AboutScreen extends StatelessWidget {
  const AboutScreen({super.key});
  @override
  Widget build(BuildContext context) {
    final controller = Get.find<AboutScreenController>();
    final state = Get.find<AboutScreenController>().state;
    return Scaffold(
        backgroundColor: Colors.white,
        appBar: AppHeaderBar(title: SR.about.tr),
        body: Center(
            child: Container(
                width: double.infinity,
                height: double.infinity,
                padding: const EdgeInsets.only(top: 20.0, bottom: 50.0, left: 16.0, right: 16.0),
                child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
                  AppIcons.checkLogo,
                  const SizedBox(height: 10),
                  GetBuilder(
                      init: controller,
                      id: 'about_version',
                      builder: (_) {
                        return Text('${SR.version.tr} ${state.version} (${state.buildNumber})',  style: AppColors.normal8); //这儿显示的便是版本号
                      }),
                  const SizedBox(height: 10),
                  AppIcons.aboutBackground,
                  const SizedBox(height: 25),
                  Row(
                    children: [
                      Icon(
                        Icons.home_outlined,
                        color: AppColors.lineDark,
                        size: 20,
                      ),
                      SizedBox(
                        width: 8,
                      ),
                      Expanded(child: Text('${SR.company.tr}:$company', style: AppColors.normal))
                    ],
                  ),
                  const SizedBox(height: 20),
                  Row(
                    children: [
                      Icon(
                        Icons.card_travel_outlined,
                        color: AppColors.lineDark,
                        size: 20,
                      ),
                      SizedBox(
                        width: 8,
                      ),
                      Expanded(child: Text('${SR.resultC.tr}:$email', style: AppColors.normal))
                    ],
                  ),
                  const SizedBox(height: 20),
                  Row(
                    children: [
                      Icon(
                        Icons.settings_phone_outlined,
                        color: AppColors.lineDark,
                        size: 20,
                      ),
                      SizedBox(
                        width: 8,
                      ),
                      Expanded(child: Text('${SR.phoneNumber.tr}:$tel', style: AppColors.normal))
                    ],
                  ),
                  const SizedBox(height: 20),
                  Row(
                    children: [
                      Icon(
                        Icons.room_outlined,
                        color: AppColors.lineDark,
                        size: 20,
                      ),
                      SizedBox(
                        width: 8,
                      ),
                      Expanded(child: Text('${SR.zipcode.tr}:$email', style: AppColors.normal))
                    ],
                  ),
                  const SizedBox(height: 20),
                  Row(
                    children: [
                      Icon(
                        Icons.account_balance_outlined,
                        color: AppColors.lineDark,
                        size: 20,
                      ),
                      SizedBox(
                        width: 8,
                      ),
                      Expanded(child: Text('${SR.address.tr}:$address', style: AppColors.normal))
                    ],
                  ),
                ]))));
  }
}