iT邦幫忙

第 12 屆 iThome 鐵人賽

DAY 25
0
Mobile Development

ReactNative 懶人開發之路,薪水小偷練成日記(X系列 第 25

[Day:24] GitHub Actions 懶人部署-Android 發布上架2 (自動版號的部分晚點會更新,不要急)

  • 分享至 

  • xImage
  •  

Github Actions

昨天有被觀看人數嚇到XD

不過趕者去烤肉,有些地方寫的不正確,今天又拆了一天出來說明&更新

步驟整理: https://gist.github.com/CS6/320ece2c01f9653b2225db28b7c8ca9f

昨天我們遭遇了兩個問題,

  • Package not found: XX.***.
  • APP 的 VersionCode & VersionName 不可以跟前版一樣

解決方法

設定商店資訊

解決:找不到 APP ID : Package not found: XX.***.

https://ithelp.ithome.com.tw/upload/images/20201008/201042205BwEzmJ5Ut.png

https://ithelp.ithome.com.tw/upload/images/20201008/20104220mmZqfMUJjk.png

https://ithelp.ithome.com.tw/upload/images/20201008/201042208A1pXnXtdJ.png

set version (WIP)

in android/app/build.gradle

def getMyVersionCode = { ->
    def code = project.hasProperty('versionCode') ? versionCode.toInteger() : -1
    println "VersionCode is set to $code"
    return code
}

def getMyVersionName = { ->
    def name = project.hasProperty('versionName') ? versionName : "1.0"
    println "VersionName is set to $name"
    return name
}

in android/app/build.gradle

    defaultConfig {
        applicationId "dev.dayuan.rn3d"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
+       versionCode getMyVersionCode()
+       versionName getMyVersionName()
-       // versionCode 1
-       // versionName "1.0"

    }

in android/gradle.properties

起始版號
+       versionCode=5
+       versionName=0.0.5
    }

測試 Build

gradle build bundleRelease -PversionCode=483 -PversionName=4.0.3

測試 Run

adb -s emulator-5554 install app/build/outputs/apk/release/app-release.apk

完整Yml (如果不放簽署過的AAB/APK記得移除部分區塊)

name: Github Actions

# on: [push, pull_request]
on:
  push:
    branches: [  Release-Store  ]
    tags:
      - 'Store*'
  pull_request:
    branches: [  Release-Store  ]
jobs:
  build:
    runs-on: ubuntu-latest
    container: reactnativecommunity/react-native-android
    steps:
    - name: "#️⃣ Generate Build Number"
      id: buildnumber
      uses: einaregilsson/build-number@v2
      with:
        token: ${{ secrets.ACTION_TEST }}
    - name: "#️⃣ Generate Build Number store"
      id: buildnumber_store
      uses: einaregilsson/build-number@v2
      with:
        token: ${{ secrets.ACTION_TEST }}
        prefix: store
    - name: Print new build number
      run: |
        echo "Build number is $BUILD_NUMBER"
        echo "Build number is $buildnumber" ${{ steps.buildnumber.outputs.build_number }}
        echo "Build number is $buildnumber_store" ${{ steps.buildnumber.outputs.buildnumber_store }}
        echo  $BUILD_NUMBER
    - uses: actions/checkout@v2
    - name: Envinfo
      run: npx envinfo
    - name: Build application
      run: |
        yarn install && cd android && chmod +x gradlew && ./gradlew build bundleRelease 
        du -shc `find . -regex '.+\.\(apk\|aab\)$'`
#      run: yarn install && cd android && chmod +x gradlew && ./gradlew assembleRelease
      
      
#       ./gradlew build bundleRelease
#         du -shc `find . -regex '.+\.\(apk\|aab\)$'`
      
      
    #Prepare Release
      
    - name: Prepare Release
      id: prepare_release
#       if: contains(github.ref, 'tags/')
      run: |
        APK_PATH=`find . -name '*.apk' | grep release`
        echo ::set-output name=apk_path::$APK_PATH
        APK_NAME=`basename $APK_PATH`
        echo ::set-output name=apk_name::$APK_NAME
        BUNDLE_PATH=`find . -name '*.aab' | grep release | grep -v intermediates`
        echo ::set-output name=bundle_path::$BUNDLE_PATH
        BUNDLE_NAME=`basename $BUNDLE_PATH`
        echo ::set-output name=bundle_name::$BUNDLE_NAME
#        選用
#        TAG_NAME=`echo $GITHUB_REF | cut -d / -f3`
#        echo ::set-output name=tag_name::$TAG_NAME
#        PACKAGE_NAME=`./tools/aapt2 dump packagename $APK_PATH`
#        echo ::set-output name=package_name::$PACKAGE_NAME
    - name: Print build PATH
      run: |
        echo ${{steps.prepare_release.outputs.bundle_path}}
        echo ${{steps.prepare_release.outputs.apk_name}}
        echo ${{steps.prepare_release.outputs.bundle_path}}/${{steps.prepare_release.outputs.apk_name}}
#       簽署 BBA
    - name: Sign AAB
      id: sign
      uses: r0adkll/sign-android-release@v1
      with:
        releaseDirectory: ./android/app/build/outputs/bundle/release/
        signingKeyBase64: ${{ secrets.SIGNING_KEY }}
        alias: ${{ secrets.ALIAS }}
        keyStorePassword: ${{ secrets.KEY_STORE_PASSWORD }}
        keyPassword: ${{ secrets.KEY_PASSWORD }}

    #Uploads
    - name: Upload Artifact
      if: steps.prepare_release.outputs.apk_path
      uses: actions/upload-artifact@v1
      with:
        name: app-release.apk
        path: android/app/build/outputs/apk/release/     
    #Uploads
    - name: Upload Artifact
      if: steps.prepare_release.outputs.bundle_path
      uses: actions/upload-artifact@v1
      with:
        name: app-release.aab
        path: android/app/build/outputs/bundle/release/  
        
    - name: Create GitHub release
      id: create_release
#       if: steps.version_check.outputs.changed == 'true'
      uses: actions/create-release@v1
      env:
        GITHUB_TOKEN: ${{ secrets.ACTION_TEST }}
      with:
        tag_name: V-${{ steps.buildnumber.outputs.build_number }}
        release_name: V-${{ steps.buildnumber.outputs.build_number }}
        body: |
          ![release!](https://i.giphy.com/media/lPulaaB9lDMnGZiivs/source.gif)
          # Changelog
          Release type: ${{ steps.buildnumber.outputs.build_number }}
        prerelease: true


    - name: Upload APK Asset
      if: steps.create_release.outputs.upload_url && steps.prepare_release.outputs.apk_path && steps.prepare_release.outputs.apk_name
      uses: actions/upload-release-asset@v1
      env:
        GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
      with:
        upload_url: ${{steps.create_release.outputs.upload_url}}
        asset_path: ${{steps.prepare_release.outputs.apk_path}}
        asset_name: ${{steps.prepare_release.outputs.apk_name}}
        asset_content_type: application/vnd.android.package-archive
#       選用 BBA
    - name: Upload Bundle Asset
      if: steps.create_release.outputs.upload_url && steps.prepare_release.outputs.bundle_path && steps.prepare_release.outputs.bundle_name
      uses: actions/upload-release-asset@v1
      env:
        GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
      with:
        upload_url: ${{steps.create_release.outputs.upload_url}}
        asset_path: ${{steps.prepare_release.outputs.bundle_path}}
        asset_name: ${{steps.prepare_release.outputs.bundle_name}}
        asset_content_type: application/octet-stream
#       上傳 BBA
    - name: Upload Android Release to Play Store (internal track publishing is default)
      uses: r0adkll/upload-google-play@v1
      with:
        serviceAccountJsonPlainText: ${{ secrets.SERVICE_ACCOUNT_JSON }}
        packageName: dev.dayuan.rn3d
        releaseFile: ${{steps.prepare_release.outputs.bundle_path}}
        track: internal
        whatsNewDirectory: distribution/whatsnew

大成功

https://ithelp.ithome.com.tw/upload/images/20201008/20104220vw6bXWYy9m.png

參考

https://ithelp.ithome.com.tw/upload/images/20201008/2010422095OHL1tolH.png


上一篇
[Day:23] GitHub Actions 懶人部署-Android 發布上架
下一篇
[Day:25] GitHub Actions 懶人部署 ---- 各種好用 Actions
系列文
ReactNative 懶人開發之路,薪水小偷練成日記(X31
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言