Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
ethan
/
appframe
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit b6d4b690
authored
2025-12-18 17:42:59 +0800
by
tanghuan
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
增加Android构建脚本
1 parent
2993e0a9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
123 additions
and
0 deletions
android_build.ps1
android_build.ps1
0 → 100644
View file @
b6d4b69
#################################################
# 脚本代码中不能含有中文,否则默认PowerShell环境可能会报错
#################################################
# 1. 读取脚本参数
#-------------------------------------------
param
(
# app打包环境:dev, prod
[
Parameter
(
Mandatory
=
$true
)]
[
ValidateSet
(
"dev"
,
"pro"
)]
[
string
]
$appenv
,
# App版本,例如:1.0.2512181
[
Parameter
(
Mandatory
=
$true
)]
[
string
]
$version
,
# 下载地址
[
string
]
$url
=
"https://bxe.obs.cn-north-4.myhuaweicloud.com/fronts/material/xehybrid/assets/basepkg/base-
$appenv
.zip"
,
# 下载保存文件的路径
[
string
]
$downloadPath
=
"C:
\U
sers
\t
ang-
\S
tudioProjects
\a
ppframe
\a
ssets
\b
ase-
$appenv
.zip"
,
# App路径
[
string
]
$appPath
=
"C:
\U
sers
\t
ang-
\S
tudioProjects
\a
ppframe"
)
# 2. 验证目录存在
#-------------------------------------------
if
(
-not
(
Test-Path
$appPath
))
{
Write-Error
"appPath not exists:
$appPath
"
exit
1
}
# 确保下载目录存在
$downloadDir
=
Split-Path
$downloadPath
-Parent
if
(
-not
(
Test-Path
$downloadDir
))
{
Write-Error
"the path for save file does not exists:
$appPath
"
exit
1
}
# 3. 下载文件(添加错误处理)
#-------------------------------------------
try
{
Write-Host
"downloading from :
$url
"
-ForegroundColor Green
Write-Host
"save to :
$downloadPath
"
-ForegroundColor Green
Invoke-WebRequest -Uri
$url
-OutFile
$downloadPath
-ErrorAction Stop
if
(
Test-Path
$downloadPath
)
{
Write-Host
"download success!"
-ForegroundColor Green
}
else
{
Write-Error
"download failed!"
exit
1
}
}
catch
{
Write-Error
"downloading failed:
$_
"
exit
1
}
# 4. 执行flutter构建
#-------------------------------------------
try
{
Set-Location
-Path
$appPath
-ErrorAction Stop
Write-Host
"flutter building ..."
-ForegroundColor Green
Write-Host
"appenv:
$appenv
, version:
$version
"
-ForegroundColor Cyan
flutter build apk
`
--release
`
--split-per-abi
`
--target-platform android-arm64
`
--dart-define
=
env
=
$appenv
`
--dart-define
=
version
=
$version
if
(
$LASTEXITCODE
-eq 0
)
{
Write-Host
"build success!"
-ForegroundColor Green
}
else
{
Write-Error
"build failed!"
exit
$LASTEXITCODE
}
}
catch
{
Write-Error
"building failed:
$_
"
exit
1
}
# 5. 复制生成新命名的APK文件
# "build\app\outputs\flutter-apk\app-arm64-v8a-release.apk"
#-------------------------------------------
try
{
$apkOutputDir
=
Join-Path
$appPath
"build
\a
pp
\o
utputs
\f
lutter-apk"
$sourceApk
=
Join-Path
$apkOutputDir
"app-arm64-v8a-release.apk"
$newApkName
=
"bxeapp-
$appenv
-
$version
.apk"
$destApkPath
=
Join-Path
$apkOutputDir
$newApkName
if
(
Test-Path
$sourceApk
)
{
Copy-Item
-Path
$sourceApk
-Destination
$destApkPath
-Force
Write-Host
"Copied and renamed:
$newApkName
"
-ForegroundColor Yellow
}
else
{
Write-Warning
"Source APK not found:
$sourceApk
"
}
}
catch
{
Write-Error
"Failed to copy and rename APK:
$_
"
}
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment