Skip to content

[Android]Add android sdk and sample app #18

[Android]Add android sdk and sample app

[Android]Add android sdk and sample app #18

Workflow file for this run

name: Build Android AAR
on:
push:
branches:
- main
- android-sdk
pull_request:
jobs:
build:
name: Build AAR
runs-on: ubuntu-latest
if: github.event_name == 'push'
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
- name: Cache Gradle packages
uses: actions/cache@v3
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Navigate to android Directory and Build AAR
run: |
echo "Navigating to the example directory..."
cd android/llama.android
echo "Starting Gradle build process in $(pwd)..."
./gradlew assembleRelease --stacktrace --info
shell: bash
- name: Rename and upload AAR
run: |
echo "Navigating to the android directory to find AAR output..."
cd android/llama.android
mkdir -p ../artifacts
ls -ld ../artifacts || echo "Artifacts directory does not exist."
AAR_PATH=$(find ./llama/build/outputs/aar -type f -name "*.aar" | head -n 1)
if [ -z "$AAR_PATH" ]; then
echo "No AAR file found. Build might have failed."
exit 1
fi
BRANCH_NAME=${{ github.ref_name }}
CUSTOM_NAME="com-nexa-${BRANCH_NAME}-${{ github.run_number }}.aar"
echo "Found AAR at $AAR_PATH, renaming to $CUSTOM_NAME..."
mv "$AAR_PATH" "../artifacts/$CUSTOM_NAME"
shell: bash
- name: Upload AAR as an artifact
uses: actions/upload-artifact@v3
with:
name: custom-aar-${{ github.ref_name }}-${{ github.run_number }}
path: android/artifacts/
release:
name: Create GitHub Release
needs: build
runs-on: ubuntu-latest
if: github.event_name == 'push' && contains(github.ref, 'main')
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Download Artifacts
uses: actions/download-artifact@v3
with:
name: custom-aar-${{ github.ref_name }}-${{ github.run_number }}
path: release-artifacts
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ github.run_number }}
release_name: "Release v${{ github.run_number }}"
body: |
This is an automated release containing the latest AAR build.
- **Branch:** ${{ github.ref_name }}
- **Build Number:** ${{ github.run_number }}
draft: false
prerelease: false
- name: Upload AAR to Release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: release-artifacts/com-nexa-${{ github.ref_name }}-${{ github.run_number }}.aar
asset_name: com-nexa-${{ github.ref_name }}-${{ github.run_number }}.aar
asset_content_type: application/java-archive