Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

スマホ版ビルドWorkflowを追加、スクリプトの見直し #48

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
152 changes: 152 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,16 @@ jobs:

runs-on: ${{ matrix.os }}
steps:
# https://github.com/easimon/maximize-build-space/blob/fc881a613ad2a34aca9c9624518214ebc21dfc0c/action.yml#L122-L136
- name: Remove unnecessary tools
if: startsWith(matrix.os, 'ubuntu-')
run: |
sudo rm -rf /usr/share/dotnet
sudo rm -rf /usr/local/lib/android
sudo rm -rf /opt/ghc
sudo rm -rf /opt/hostedtoolcache/CodeQL
sudo docker image prune --all --force

- uses: actions/checkout@v3

# NOTE: The default sed of macOS is BSD sed.
Expand Down Expand Up @@ -489,3 +499,145 @@ jobs:
dist_electron/nsis-web/out/*.7z.*
dist_electron/nsis-web/*.exe
target_commitish: ${{ github.sha }}

build-and-upload-android:
runs-on: ubuntu-20.04
steps:
- name: Remove unnecessary tools
run: |
sudo rm -rf /usr/share/dotnet
sudo rm -rf /opt/ghc
sudo rm -rf /opt/hostedtoolcache/CodeQL
sudo docker image prune --all --force
- uses: actions/checkout@v3

- name: Replace package version
run: |
sed -i 's/"version": "999.999.999"/"version": "${{ env.VOICEVOX_EDITOR_VERSION }}"/' package.json

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version-file: ".node-version"
cache: "npm"

- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: "adopt"
java-version: "17"
cache: "gradle"

- name: Setup Android SDK
uses: android-actions/setup-android@v3

- name: Add build-tools to PATH
run: |
versions=($ANDROID_SDK_ROOT/build-tools/*)
build_tools_path=${versions[0]}
for version in "${versions[@]}"; do
if [ echo "$version" | grep -q 'rc' ]; then
continue
fi
build_tools_path=$version
done

echo "Build tools path: $build_tools_path"

echo "$build_tools_path" >> $GITHUB_PATH

- name: Cache gradle
uses: actions/cache@v3
with:
path: ./android/.gradle/configuration-cache
key: ${{ env.cache-version }}-gradle-configuration-cache
restore-keys: |
${{ env.cache-version }}-gradle-configuration-cache

- name: Install dependencies
run: |
npm ci
npm run mobile:install

- name: Checkout Product Version Resource
uses: actions/checkout@v3
with:
repository: VOICEVOX/voicevox_resource
ref: ${{ env.VOICEVOX_RESOURCE_VERSION }}
path: resource

- name: Create and replace software resources
run: |
rm build/README.txt
rm public/policy.md
{
cat resource/editor/README.md
echo
cat resource/editor/ACKNOWLEDGMENTS.md
} \
> build/README.txt
cp build/README.txt public/policy.md

cp resource/editor/PRIVACYPOLICY.md public/privacyPolicy.md

- name: Replace .env.production infomations
run: |
# GTM ID
gtm_id=$(jq -er '.gtm_container_id' resource/editor/metas.json)
sed -i 's/VITE_GTM_CONTAINER_ID=.*/VITE_GTM_CONTAINER_ID='"$gtm_id"'/' .env.production

# Engine host
sed -i 's|http://127.0.0.1:50021|local|g' .env.production

- name: Generate public/licenses.json
run: npm run license:generate -- -o public/licenses.json

- name: Setup Credentials (Debug)
if: github.event.inputs.code_signing == 'false'
run: |
cp android/build-options.debug.json android/build-options.json

- name: Setup Credentials (Release)
if: github.event.inputs.code_signing == 'true'
run: |
# メモ:
# ANDROID_BUILD_OPTIONSはbuild-options.jsonを、
# ANDROID_KEYSTOREはkeystore.jksをbase64エンコードしたものを想定
cat <<EOF > android/build-options.json
${{ secrets.ANDROID_BUILD_OPTIONS }}
EOF
cat <<EOF | base64 -d > android/keystore.jks
${{ secrets.ANDROID_KEYSTORE }}
EOF

- name: Build Android
run: |
chmod +x ./android/gradlew
npm run mobile:build:android -- --androidreleasetype APK --signing-type apksigner
npm run mobile:build:android -- --androidreleasetype AAB --signing-type jarsigner

- name: Rename
run: |
mkdir /tmp/build_artifacts
cp android/app/build/outputs/bundle/release/app-release-signed.aab /tmp/build_artifacts/VOICEVOX-${{ env.VOICEVOX_EDITOR_VERSION }}.aab
cp android/app/build/outputs/apk/release/app-release-signed.apk /tmp/build_artifacts/VOICEVOX-${{ env.VOICEVOX_EDITOR_VERSION }}.apk

- name: Upload Android binary to Artifacts
if: github.event.inputs.upload_artifact == 'true'
uses: actions/upload-artifact@v3
with:
name: android-apk
path: |-
/tmp/build_artifacts/VOICEVOX-${{ env.VOICEVOX_EDITOR_VERSION }}.apk
/tmp/build_artifacts/VOICEVOX-${{ env.VOICEVOX_EDITOR_VERSION }}.aab

- name: Upload Android binary to Release Assets
if: (github.event.release.tag_name || github.event.inputs.version) != ''
uses: softprops/action-gh-release@v1
with:
prerelease: ${{ github.event.inputs.prerelease }}
tag_name: ${{ env.VOICEVOX_EDITOR_VERSION }}
files: |-
/tmp/build_artifacts/VOICEVOX-${{ env.VOICEVOX_EDITOR_VERSION }}.apk
/tmp/build_artifacts/VOICEVOX-${{ env.VOICEVOX_EDITOR_VERSION }}.aab
target_commitish: ${{ github.sha }}
30 changes: 22 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Node.js の管理ツール ([nvs](https://github.com/jasongin/nvs)など)を利

```bash
npm ci
npm run mobile:install
```

また、Android・iOS 開発用のツールも必要です。[Capacitor: 環境設定](https://capacitorjs.jp/docs/getting-started/environment-setup)を参照してください。
Expand All @@ -26,21 +27,21 @@ npm ci
PC のプライベート IP アドレスは自動で取得されますが、手動で設定する場合は`.env` 内で `CAPACITOR_ADDRESS` を指定してください。

```bash
npm run cap:serve
npm run mobile:serve
```

または、以下のコマンドで Web 側の変更をビルドし、Capacitor のライブリロードなしで反映します。

```bash
npm run cap:sync
npm run mobile:sync
```

### Android 版

以下のコマンドで Android Studio が起動します。起動後、Android Studio で実行ボタンを押してください。

```bash
npm run cap:open:android
npm run mobile:open:android
```

[Capacitor Android ドキュメンテーション](https://capacitorjs.jp/docs/android) も参照してください。
Expand All @@ -53,14 +54,27 @@ TODO

### Android 版

`apksigner` に PATH が通っている必要があります。
`android/build-options.json` に keystore の情報を記述してください。

```jsonc
{
// 相対パスはプロジェクトルートから解決されます。
"keystorePath": "./android/debug.keystore",
"keystorePassword": "android",
"keystoreAlias": "androiddebugkey",
"keystoreAliasPassword": "android"
}
```

セットアップが完了したら以下のコマンドでビルドできます。

```bash
ANDROID_HOME=/path/to/android-sdk

npm run cap:build:android -- \
--keystorepath /path/to/keystore.jks \
--keystorepass Password_here \
--keystorealias TestKey \
--keystorealiaspass Password_here
npm run mobile:build:android -- \
--androidreleasetype APK
# --androidreleasetype AAB
```

### iOS/iPadOS 版
Expand Down
3 changes: 3 additions & 0 deletions android/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,6 @@ app/src/main/res/xml/config.xml
# Assets generated by build/ script
app/src/main/assets/*.zip
app/src/main/assets/*.sha256

# Credentials file
build-options.json
10 changes: 5 additions & 5 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ android {
}
}

repositories {
flatDir {
dirs '../capacitor-cordova-android-plugins/src/main/libs', 'libs'
}
}
// repositories {
// flatDir {
// dirs '../capacitor-cordova-android-plugins/src/main/libs', 'libs'
// }
// }
Comment on lines +40 to +44
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ionic-team/capacitor#5287 (comment)
警告が出ていたので消しました(Cordovaのプラグインを使わなければ消していいらしい)

def urlZipFile = { name, path, url ->
File zipFile = new File("$buildDir/download/${name}.zip")
zipFile.parentFile.mkdirs()
Expand Down
6 changes: 6 additions & 0 deletions android/build-options.debug.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"keystorePath": "./android/debug.keystore",
"keystorePassword": "android",
"keystoreAlias": "androiddebugkey",
"keystoreAliasPassword": "android"
}
Binary file added android/debug.keystore
Binary file not shown.
24 changes: 24 additions & 0 deletions capacitor.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
/// <reference types="@capacitor/splash-screen" />
import { networkInterfaces } from "os";
import fs from "fs";
import path from "path";
import dotenv from "dotenv";
import { CapacitorConfig } from "@capacitor/cli";

let keystorePath = "";
let keystorePassword = "";
let keystoreAlias = "";
let keystoreAliasPassword = "";
if (fs.existsSync("./android/build-options.json")) {
const buildOptions = JSON.parse(
fs.readFileSync("./android/build-options.json", "utf-8")
);
keystorePath = path.resolve(buildOptions.keystorePath);
keystorePassword = buildOptions.keystorePassword;
keystoreAlias = buildOptions.keystoreAlias;
keystoreAliasPassword = buildOptions.keystoreAliasPassword;
}

const config: CapacitorConfig = {
appId: "jp.hiroshiba.voicevox",
appName: "VOICEVOX",
Expand All @@ -12,6 +28,14 @@ const config: CapacitorConfig = {
launchAutoHide: false,
},
},
android: {
buildOptions: {
keystorePath,
keystorePassword,
keystoreAlias,
keystoreAliasPassword,
},
},
};

if (process.env.CAPACITOR_MODE === "serve") {
Expand Down
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,19 @@
"electron:build_pnever": "cross-env VITE_TARGET=electron vite build && electron-builder --config electron-builder.config.js --publish never",
"electron:build_pnever_prepackaged": "cross-var electron-builder --config electron-builder.config.js --publish never --prepackaged $PREPACKAGED",
"electron:serve": "cross-env VITE_TARGET=electron vite",
"postinstall": "electron-builder install-app-deps && node build/download7z.js && ts-node --transpileOnly build/downloadMobileAssets.mts && node build/generateSpeakerInfo.js",
"postinstall": "electron-builder install-app-deps && node build/download7z.js",
"browser:serve": "cross-env VITE_TARGET=browser vite",
"browser:build": "cross-env VITE_TARGET=browser vite build",
"postuninstall": "electron-builder install-app-deps",
"license:generate": "node build/generateLicenses.js",
"license:merge": "node build/mergeLicenses.js",
"cap:serve": "cross-env CAPACITOR_MODE=serve cap sync && cross-env VITE_TARGET=mobile vite --host 0.0.0.0",
"cap:sync": "cross-env VITE_TARGET=mobile vite build && cross-env CAPACITOR_MODE=build cap sync",
"cap:build:android": "npm run cap:sync && npx cap build android",
"cap:build:ios": "npm run cap:sync && npx cap build ios",
"cap:open:android": "npx cap open android",
"cap:open:ios": "npx cap open ios",
"mobile:install": "ts-node --transpileOnly build/downloadMobileAssets.mts && node build/generateSpeakerInfo.js",
"mobile:serve": "cross-env CAPACITOR_MODE=serve cap sync && cross-env VITE_TARGET=mobile vite --host 0.0.0.0",
"mobile:sync": "cross-env VITE_TARGET=mobile vite build && cross-env CAPACITOR_MODE=build cap sync",
"mobile:build:android": "npm run mobile:sync && npx cap build android",
"mobile:build:ios": "npm run mobile:sync && npx cap build ios",
"mobile:open:android": "npx cap open android",
"mobile:open:ios": "npx cap open ios",
"generate-icons": "npx matex -r ./build/matexRecipes.yml -o public"
},
"dependencies": {
Expand Down
Loading