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

update Android CI & Add Android publish action #4

Merged
merged 1 commit into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 6 additions & 5 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ jobs:
ENCODED_STRING: ${{ secrets.KEYSTORE }}
run: echo $ENCODED_STRING | base64 -di > ./android/app/keystore.jks

- name: Grant execute permission for gradlew
run: cd ./android; chmod +x gradlew

- name: Build with Gradle
run: cd ./android; ./gradlew build
run: |
cd ./android
chmod +x gradlew
./gradlew clean
./gradlew --info assembleDebug
env:
SIGN_KEY_STORE_PATH: keystore.jks
SIGN_KEY_ALIAS: ${{ secrets.SIGN_KEY_ALIAS }}
SIGN_KEY_PASSWORD: ${{ secrets.SIGN_KEY_PASSWORD }}
SIGN_STORE_PASSWORD: ${{ secrets.SIGN_STORE_PASSWORD }}
SIGN_STORE_PASSWORD: ${{ secrets.SIGN_STORE_PASSWORD }}
18 changes: 17 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,20 @@ jobs:
- name: Cargo publish
run: cargo publish --token ${CARGO_REGISTRY_TOKEN}
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
- name: Android publish
env:
sonatypeUsername: ${{ secrets.SONATYPEUSERNAME }}
sonatypePassword: ${{ secrets.SONATYPEPASSWORD }}
signingKeyId: ${{ secrets.GPG_KEY_ID }}
signingPwd: ${{ secrets.GPG_PWD }}
signingSecret: ${{ secrets.GPG_SECRET }}
run: |
cd ./android
echo ${signingSecret} | gpg --dearmor > secret.gpg
echo sonatypeUsername=${sonatypeUsername} >> local.properties
echo sonatypePassword=${sonatypePassword} >> local.properties
echo signing.keyId=${signingKeyId} >> local.properties
echo signing.secretKeyRingFile=secret.gpg >> local.properties
chmod +x gradlew
./gradlew --info publish
16 changes: 14 additions & 2 deletions android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ if (propFile.exists()) {
}

android {
namespace = "net.yangkx.mmkv"
namespace = "net.yangkx.mmkv.demo"
compileSdk = 33

defaultConfig {
applicationId = "net.yangkx.mmkv"
applicationId = "net.yangkx.mmkv.demo"
minSdk = 21
targetSdk = 33
versionCode = 1
Expand All @@ -54,6 +54,14 @@ android {
)
signingConfig = signingConfigs.getByName("release")
}
create("staging") {
isMinifyEnabled = true
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
signingConfig = signingConfigs.getByName("release")
}
debug {
signingConfig = signingConfigs.getByName("release")
}
Expand Down Expand Up @@ -81,6 +89,8 @@ android {

val defaultDebugImplementation: Configuration by configurations.creating
val encryptionDebugImplementation: Configuration by configurations.creating
val defaultStagingImplementation: Configuration by configurations.creating
val encryptionStagingImplementation: Configuration by configurations.creating
val defaultReleaseImplementation: Configuration by configurations.creating
val encryptionReleaseImplementation: Configuration by configurations.creating

Expand All @@ -89,6 +99,8 @@ dependencies {
implementation("androidx.appcompat:appcompat:1.6.1")
defaultDebugImplementation(project(":library"))
encryptionDebugImplementation(project(":library-encrypt"))
defaultStagingImplementation(Deps.mmkv_snapshot)
encryptionStagingImplementation(Deps.mmkv_encrypt_snapshot)
defaultReleaseImplementation(Deps.mmkv)
encryptionReleaseImplementation(Deps.mmkv_encrypt)
}
5 changes: 2 additions & 3 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
xmlns:tools="http://schemas.android.com/tools">

<application
android:name=".MyApplication"
android:allowBackup="true"
android:name="net.yangkx.mmkv.MyApplication"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
Expand All @@ -14,7 +13,7 @@
android:theme="@style/Theme.MMKV"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:name="net.yangkx.mmkv.MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
2 changes: 1 addition & 1 deletion android/app/src/main/java/net/yangkx/mmkv/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import android.os.Bundle
import android.text.method.ScrollingMovementMethod
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import net.yangkx.mmkv.databinding.ActivityMainBinding
import net.yangkx.mmkv.demo.databinding.ActivityMainBinding
import net.yangkx.mmkv.log.LogLevel
import net.yangkx.mmkv.log.Logger
import kotlin.random.Random
Expand Down
23 changes: 15 additions & 8 deletions android/buildSrc/src/main/java/Configuration.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
object Configuration {
const val versionStr = "0.2.8"
// const val libVersion = versionStr + "-SNAPSHOT"
const val libVersion = versionStr
val snapshotVersion = version + "-SNAPSHOT"
val releaseVersion = version
val libVersion: String
get() = if (System.getenv("CI")?.toBoolean() ?: false){
releaseVersion
} else {
snapshotVersion
}
const val groupId = "net.yangkx"
const val description = "Library uses file-based mmap to store key-values"
private const val releasesRepoUrl = "https://s01.oss.sonatype.org/content/repositories/releases/"
private const val snapshotsRepoUrl = "https://s01.oss.sonatype.org/content/repositories/snapshots/"
val publishUrl = if (libVersion.endsWith("-SNAPSHOT")) {
snapshotsRepoUrl
} else {
val publishUrl = if (System.getenv("CI")?.toBoolean() ?: false) {
releasesRepoUrl
} else {
snapshotsRepoUrl
}
val licenceApache = "The Apache License, Version 2.0" to "http://www.apache.org/licenses/LICENSE-2.0.txt"
val licenceMit = "The MIT License" to "https://opensource.org/licenses/MIT"
Expand All @@ -19,6 +24,8 @@ object Configuration {

object Deps {
val kotlin = "androidx.core:core-ktx:1.10.1"
val mmkv = "net.yangkx:mmkv:${Configuration.libVersion}"
val mmkv_encrypt = "net.yangkx:mmkv-encrypt:${Configuration.libVersion}"
val mmkv_snapshot = "net.yangkx:mmkv:${Configuration.snapshotVersion}"
val mmkv_encrypt_snapshot = "net.yangkx:mmkv-encrypt:${Configuration.snapshotVersion}"
val mmkv = "net.yangkx:mmkv:${Configuration.releaseVersion}"
val mmkv_encrypt = "net.yangkx:mmkv-encrypt:${Configuration.releaseVersion}"
}
1 change: 1 addition & 0 deletions android/buildSrc/src/main/java/Version.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const val version = "0.2.8"
2 changes: 1 addition & 1 deletion android/library-encrypt/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ publishing {
val artifactId = "mmkv-encrypt"
publications {
register<MavenPublication>("release") {
groupId = "net.yangkx"
groupId = Configuration.groupId
this.artifactId = artifactId
this.version = Configuration.libVersion

Expand Down
3 changes: 1 addition & 2 deletions android/library-encrypt/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.yangkx.mmkv">
<manifest>
</manifest>
3 changes: 1 addition & 2 deletions android/library/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,11 @@ dependencies {

publishing {
val artifactId = "mmkv"
val version = Configuration.libVersion
publications {
register<MavenPublication>("release") {
groupId = Configuration.groupId
this.artifactId = artifactId
this.version = version
this.version = Configuration.libVersion

afterEvaluate {
from(components["release"])
Expand Down
3 changes: 1 addition & 2 deletions android/library/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.yangkx.mmkv">
<manifest>
</manifest>