commit a529be86155ab82634d9916bde3d22834d17ae4f Author: amos Date: Tue Jun 2 09:45:02 2026 +0800 Fix: Complete Android project with proper Gradle setup diff --git a/.gitea/workflows/android-build.yml b/.gitea/workflows/android-build.yml new file mode 100644 index 0000000..554dc95 --- /dev/null +++ b/.gitea/workflows/android-build.yml @@ -0,0 +1,37 @@ +name: Android Build + +on: + push: + branches: [ master, main ] + pull_request: + branches: [ master, main ] + workflow_dispatch: + +jobs: + build: + runs-on: android + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + + - name: Setup Gradle + uses: gradle/gradle-build-action@v2 + + - name: Build Debug APK + run: | + # 使用 gradle 命令而不是 ./gradlew + gradle wrapper --gradle-version 8.2 + ./gradlew assembleDebug --no-daemon + + - name: Upload APK + uses: actions/upload-artifact@v4 + with: + name: app-debug + path: app/build/outputs/apk/debug/app-debug.apk diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..54bb0a7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,22 @@ +*.iml +.gradle +/local.properties +/.idea +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +local.properties + +# Keystore files +*.jks +*.keystore + +# Google Services (e.g. google-services.json) +google-services.json + +# Freeline +freeline.py +freeline/ +freeline_project_description.json diff --git a/README.md b/README.md new file mode 100644 index 0000000..582489f --- /dev/null +++ b/README.md @@ -0,0 +1,19 @@ +# Android CI Demo + +这是一个用于测试 Gitea Actions Android 编译的示例项目。 + +## 功能 + +- 自动编译 Android Debug APK +- 使用 JDK 17 +- 支持 Gradle 缓存 + +## 使用方法 + +1. Push 代码到 `main` 分支 +2. Gitea Actions 自动触发构建 +3. 在 Actions 页面下载 APK artifact + +## 构建产物 + +- `app/build/outputs/apk/debug/app-debug.apk` diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..52a5082 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,32 @@ +plugins { + id 'com.android.application' +} + +android { + namespace 'com.example.demo' + compileSdk 34 + + defaultConfig { + applicationId "com.example.demo" + minSdk 24 + targetSdk 34 + versionCode 1 + versionName "1.0" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 + } +} + +dependencies { + implementation 'androidx.appcompat:appcompat:1.6.1' + implementation 'com.google.android.material:material:1.11.0' +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..61ca42f --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,15 @@ + + + + + + + + + + diff --git a/app/src/main/java/com/example/demo/MainActivity.java b/app/src/main/java/com/example/demo/MainActivity.java new file mode 100644 index 0000000..558d98c --- /dev/null +++ b/app/src/main/java/com/example/demo/MainActivity.java @@ -0,0 +1,12 @@ +package com.example.demo; + +import android.app.Activity; +import android.os.Bundle; + +public class MainActivity extends Activity { + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + } +} diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..b5af1b2 --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,13 @@ + + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml new file mode 100644 index 0000000..b2250a8 --- /dev/null +++ b/app/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + Demo + diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..8df2f08 --- /dev/null +++ b/build.gradle @@ -0,0 +1,4 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. +plugins { + id 'com.android.application' version '8.2.0' apply false +} diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..cc18a0c --- /dev/null +++ b/gradle.properties @@ -0,0 +1,3 @@ +org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 +android.useAndroidX=true +android.enableJetifier=true diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..15de902 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..6c34f31 --- /dev/null +++ b/settings.gradle @@ -0,0 +1,16 @@ +pluginManagement { + repositories { + google() + mavenCentral() + gradlePluginPortal() + } +} +dependencyResolutionManagement { + repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) + repositories { + google() + mavenCentral() + } +} +rootProject.name = "Demo" +include ':app'