flutter 新版本build aar支持指定版本号后,打包aar脚本简化很多,将以下脚本保存在module工程根目录下deploy.sh,执行sh deploy.sh一键打包aar到私有maven中,依赖的第三方aar也将一并打包
#!/usr/bin/env bash
#打包前需更新的版本号
readonly VERSION='1.0.0'
readonly RELEASE=true
# 下面按照maven的实际配置修改
readonly REPOSITORY_ID='serverId' # maven setting.xml中配置server账号
readonly MAVEN_URL_SNAPSHOT='http://xx.xx.xx.xxx:xx/nexus/content/repositories/snapshots'
readonly MAVEN_URL_RELEASE='http://xx.xx.xx.xxx:xx/nexus/content/repositories/releases'
buildVersion="${VERSION}-SNAPSHOT"
buildOption='--no-release'
mavenUrl=${MAVEN_URL_SNAPSHOT}
if (${RELEASE})
then
buildVersion=${VERSION}
buildOption='--no-debug'
mavenUrl=${MAVEN_URL_RELEASE}
fi
flutter clean
flutter packages get
flutter build aar --no-profile ${buildOption} --build-number ${buildVersion}
echo "==build aar complete"
echo "==start to upload to maven..."
find . -name "*.pom" -type f -exec sh -c 'mvn deploy:deploy-file -e -DrepositoryId='${REPOSITORY_ID}' -Durl='${mavenUrl}' -DpomFile="$0" -Dfile="${0%.pom}.aar"' '{}' \;
echo "==success"
执行打包上传aar脚本后可将module打包上传到nexus maven中, 请在执行前更新脚本中的版本号和release模式,完成后在android项目中可依赖:
repositories {
...
maven { url 'http://download.flutter.io' }
maven { url 'http://xx.xx.xx.xxx:xx/nexus/content/groups/public' }
}
implementation 'package:flutter_release:1.0.0'