guoyu/log/备份/ps1/内层_integrate-to-android-studio.ps1
2025-12-07 00:11:06 +08:00

212 lines
6.7 KiB
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# ========================================
# 集成到 Android 离线 SDK
# ========================================
$ErrorActionPreference = "Stop"
# 配置信息
$ProjectRoot = $PSScriptRoot
$AppID = "__UNI__08E0C13"
$AppName = "国语教育平台"
$PackageName = "uni.app.UNI08E0C13"
$SDKRoot = "D:\4_Part\HBuilder-Android\HBuilder-Integrate-AS"
Write-Host "========================================"
Write-Host " 集成到 Android Studio"
Write-Host "========================================"
Write-Host "AppID: $AppID" -ForegroundColor Cyan
Write-Host "应用名: $AppName" -ForegroundColor Cyan
Write-Host ""
# 检查 SDK 是否存在
if (-Not (Test-Path $SDKRoot)) {
Write-Host "错误:离线 SDK 不存在" -ForegroundColor Red
Write-Host ""
Write-Host "请先下载 uni-app Android 离线 SDK" -ForegroundColor Yellow
Write-Host "1. 访问https://nativesupport.dcloud.net.cn/AppDocs/download/android" -ForegroundColor Cyan
Write-Host "2. 下载最新版本HBuilder-Integrate-AS.zip" -ForegroundColor Cyan
Write-Host "3. 解压到D:\SDK\HBuilder-Android\" -ForegroundColor Cyan
Write-Host ""
Write-Host "或者修改脚本中的 `$SDKRoot 变量为你的实际路径" -ForegroundColor Yellow
exit 1
}
Write-Host "✓ 找到离线 SDK$SDKRoot" -ForegroundColor Green
Write-Host ""
# 1. 复制 Web 资源
Write-Host "步骤 1/5复制 Web 资源..." -ForegroundColor Yellow
$WebSource = "$ProjectRoot\unpackage\dist\build\app-plus"
$WebDest = "$SDKRoot\simpleDemo\src\main\assets\apps\$AppID\www"
if (-Not (Test-Path $WebSource)) {
Write-Host "✗ 错误:编译产物不存在" -ForegroundColor Red
Write-Host "请先运行npm run build:app" -ForegroundColor Yellow
exit 1
}
New-Item -ItemType Directory -Path $WebDest -Force | Out-Null
Copy-Item -Path "$WebSource\*" -Destination $WebDest -Recurse -Force
Write-Host "✓ Web 资源已复制" -ForegroundColor Green
Write-Host ""
# 2. 复制 Vosk AAR 库
Write-Host "步骤 2/5复制 Vosk 库..." -ForegroundColor Yellow
$VoskSource = "$ProjectRoot\uni_modules\xwq-speech-to-text\utssdk\app-android\libs\vosk-android-0.3.47.aar"
$LibsDest = "$SDKRoot\simpleDemo\libs"
if (Test-Path $VoskSource) {
New-Item -ItemType Directory -Path $LibsDest -Force | Out-Null
Copy-Item -Path $VoskSource -Destination $LibsDest -Force
Write-Host "✓ Vosk 库已复制" -ForegroundColor Green
} else {
Write-Host "⊙ 警告Vosk 库不存在" -ForegroundColor Yellow
Write-Host " 语音功能可能无法使用" -ForegroundColor Gray
}
Write-Host ""
# 3. 更新 dcloud_control.xml
Write-Host "步骤 3/5更新应用配置..." -ForegroundColor Yellow
$ControlXml = "$SDKRoot\simpleDemo\src\main\assets\data\dcloud_control.xml"
$XmlContent = @"
<?xml version="1.0" encoding="utf-8"?>
<hbuilder>
<apps>
<app appid="$AppID" appver="1.0.0"/>
</apps>
</hbuilder>
"@
New-Item -ItemType Directory -Path (Split-Path $ControlXml) -Force | Out-Null
$XmlContent | Out-File -FilePath $ControlXml -Encoding UTF8 -Force
Write-Host "✓ 应用配置已更新" -ForegroundColor Green
Write-Host ""
# 4. 创建 build.gradle 配置示例
Write-Host "步骤 4/5生成 Gradle 配置..." -ForegroundColor Yellow
$GradleConfig = @"
// ============================================
// simpleDemo/build.gradle
// ============================================
android {
defaultConfig {
applicationId "$PackageName"
minSdkVersion 21 // Vosk API 21
targetSdkVersion 33
versionCode 100
versionName "1.0.0"
}
}
dependencies {
// Vosk
implementation files('libs/vosk-android-0.3.47.aar')
implementation 'net.java.dev.jna:jna:5.12.1'
}
repositories {
maven { url 'https://maven.aliyun.com/repository/public' }
maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://repo1.maven.org/maven2/' }
google()
mavenCentral()
}
"@
$GradleConfig | Out-File -FilePath "$ProjectRoot\gradle-config-for-android-studio.txt" -Encoding UTF8
Write-Host "✓ Gradle 配置已生成gradle-config-for-android-studio.txt" -ForegroundColor Green
Write-Host ""
# 5. 生成操作指南
Write-Host "步骤 5/5生成操作指南..." -ForegroundColor Yellow
$Guide = @"
========================================
Android Studio
========================================
- AppID: $AppID
- : $PackageName
- : $AppName
- SDK : $SDKRoot
========================================
========================================
1. Android Studio
- File -> Open
- $SDKRoot
2. Gradle 5-10
3. build.gradle
simpleDemo/build.gradle
gradle-config-for-android-studio.txt
android {
defaultConfig {
applicationId "$PackageName"
minSdkVersion 21
targetSdkVersion 33
}
}
dependencies {
implementation files('libs/vosk-android-0.3.47.aar')
implementation 'net.java.dev.jna:jna:5.12.1'
}
repositories {
maven { url 'https://maven.aliyun.com/repository/public' }
maven { url 'https://repo1.maven.org/maven2/' }
google()
mavenCentral()
}
4. "Sync Now" Gradle
5. APK
- Build -> Build Bundle(s) / APK(s) -> Build APK(s)
- gradlew assembleDebug
6. APK
$SDKRoot\simpleDemo\build\outputs\apk\debug\simpleDemo-debug.apk
========================================
========================================
Q: Gradle
A: 使
Q: Vosk
A: libs/vosk-android-0.3.47.aar
Q:
A:
========================================
"@
$Guide | Out-File -FilePath "$ProjectRoot\android-studio-guide.txt" -Encoding UTF8
Write-Host "✓ 操作指南已生成android-studio-guide.txt" -ForegroundColor Green
Write-Host ""
Write-Host "========================================"
Write-Host " 集成完成!"
Write-Host "========================================"
Write-Host ""
Write-Host "下一步:" -ForegroundColor Cyan
Write-Host "1. 用 Android Studio 打开:" -ForegroundColor Yellow
Write-Host " $SDKRoot" -ForegroundColor Cyan
Write-Host ""
Write-Host "2. 查看详细指南:" -ForegroundColor Yellow
Write-Host " $ProjectRoot\android-studio-guide.txt" -ForegroundColor Cyan
Write-Host ""
Write-Host "3. 修改 build.gradle参考" -ForegroundColor Yellow
Write-Host " $ProjectRoot\gradle-config-for-android-studio.txt" -ForegroundColor Cyan
Write-Host ""