diff --git a/.fleet/run.json b/.fleet/run.json new file mode 100644 index 0000000..2d7ab20 --- /dev/null +++ b/.fleet/run.json @@ -0,0 +1,64 @@ +{ + "configurations": [ + { + "type": "cargo", + "name": "Cargo test", + "cargoArgs": [ + "test" + ], + }, + { + "type": "cargo", + "name": "Cargo test feature encryption", + "cargoArgs": [ + "test" + ], + "cargoExtraArgs": [ + "--features", + "encryption" + ], + }, + + { + "type": "command", + "name": "Build All", + "program": "./build.sh", + }, + { + "type": "command", + "name": "Build Android", + "program": "./build_android.sh", + }, + { + "type": "command", + "name": "Build Apple", + "program": "./build_apple.sh", + }, + { + "type": "gradle", + "workingDir": "./android/", + "name": "Gradle Build", + "tasks": [ + "assembleDebug" + ], + }, + { + "type": "gradle", + "workingDir": "./android/", + "name": "Gradle Connected Android Test", + "tasks": [ + "connectedAndroidTest" + ], + }, + { + "type": "command", + "name": "Swift Test", + "workingDir": "./ios/MMKV/", + "program": "swift", + "args": [ + "test" + ], + }, + + ] +} \ No newline at end of file diff --git a/.fleet/settings.json b/.fleet/settings.json new file mode 100644 index 0000000..23fd35f --- /dev/null +++ b/.fleet/settings.json @@ -0,0 +1,3 @@ +{ + "editor.formatOnSave": true +} \ No newline at end of file diff --git a/.github/workflows/android-publish.yml b/.github/workflows/android-publish.yml index 033ba9d..cf60168 100644 --- a/.github/workflows/android-publish.yml +++ b/.github/workflows/android-publish.yml @@ -1,50 +1,50 @@ name: Publish Android package -on: - release: +on: + release: types: [published] -jobs: - build: +jobs: + build: runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 + steps: + - uses: actions/checkout@v4 - - name: set up JDK 17 - uses: actions/setup-java@v3 - with: - java-version: '17' - distribution: 'temurin' - cache: 'gradle' + - name: set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + cache: 'gradle' - - name: Decode Keystore - env: - ENCODED_KEYSTORE: ${{ secrets.KEYSTORE }} - GPG_SECRET: ${{ secrets.GPG_SECRET }} - run: | - echo ${ENCODED_KEYSTORE} | base64 -d > ./android/app/keystore.jks - echo ${GPG_SECRET} | base64 -d | gpg --dearmor > ./android/secret.gpg + - name: Decode Keystore + env: + ENCODED_KEYSTORE: ${{ secrets.KEYSTORE }} + GPG_SECRET: ${{ secrets.GPG_SECRET }} + run: | + echo ${ENCODED_KEYSTORE} | base64 -d > ./android/app/keystore.jks + echo ${GPG_SECRET} | base64 -d | gpg --dearmor > ./android/secret.gpg - - name: Android publish - env: - SIGN_KEY_STORE_PATH: keystore.jks - SIGN_STORE_PASSWORD: ${{ secrets.SIGN_STORE_PASSWORD }} - SIGN_KEY_ALIAS: ${{ secrets.SIGN_KEY_ALIAS }} - SIGN_KEY_PASSWORD: ${{ secrets.SIGN_KEY_PASSWORD }} - SONATYPEUSERNAME: ${{ secrets.SONATYPEUSERNAME }} - SONATYPEPASSWORD: ${{ secrets.SONATYPEPASSWORD }} - GPG_KEY_ID: ${{ secrets.GPG_KEY_ID }} - GPG_PWD: ${{ secrets.GPG_PWD }} - run: | - cd ./android - echo SIGN_KEY_STORE_PATH=keystore.jks >> local.properties - echo SIGN_STORE_PASSWORD=${SIGN_STORE_PASSWORD} >> local.properties - echo SIGN_KEY_ALIAS=${SIGN_KEY_ALIAS} >> local.properties - echo SIGN_KEY_PASSWORD=${SIGN_KEY_PASSWORD} >> local.properties - echo sonatypeUsername=${SONATYPEUSERNAME} >> local.properties - echo sonatypePassword=${SONATYPEPASSWORD} >> local.properties - echo signing.keyId=${GPG_KEY_ID} >> local.properties - echo signing.password=${GPG_PWD} >> local.properties - echo signing.secretKeyRingFile=../secret.gpg >> local.properties - chmod +x gradlew - ./gradlew clean - ./gradlew publish + - name: Android publish + env: + SIGN_KEY_STORE_PATH: keystore.jks + SIGN_STORE_PASSWORD: ${{ secrets.SIGN_STORE_PASSWORD }} + SIGN_KEY_ALIAS: ${{ secrets.SIGN_KEY_ALIAS }} + SIGN_KEY_PASSWORD: ${{ secrets.SIGN_KEY_PASSWORD }} + SONATYPEUSERNAME: ${{ secrets.SONATYPEUSERNAME }} + SONATYPEPASSWORD: ${{ secrets.SONATYPEPASSWORD }} + GPG_KEY_ID: ${{ secrets.GPG_KEY_ID }} + GPG_PWD: ${{ secrets.GPG_PWD }} + run: | + cd ./android + echo SIGN_KEY_STORE_PATH=keystore.jks >> local.properties + echo SIGN_STORE_PASSWORD=${SIGN_STORE_PASSWORD} >> local.properties + echo SIGN_KEY_ALIAS=${SIGN_KEY_ALIAS} >> local.properties + echo SIGN_KEY_PASSWORD=${SIGN_KEY_PASSWORD} >> local.properties + echo sonatypeUsername=${SONATYPEUSERNAME} >> local.properties + echo sonatypePassword=${SONATYPEPASSWORD} >> local.properties + echo signing.keyId=${GPG_KEY_ID} >> local.properties + echo signing.password=${GPG_PWD} >> local.properties + echo signing.secretKeyRingFile=../secret.gpg >> local.properties + chmod +x gradlew + ./gradlew clean + ./gradlew publish diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index 134f15f..d365f76 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -1,51 +1,55 @@ name: Android Build Check -on: - push: +on: + push: branches: [ "main", "develop" ] - pull_request: + pull_request: branches: [ "main", "develop" ] -jobs: - build: +jobs: + build: runs-on: macos-latest - steps: - - uses: actions/checkout@v4 - - - name: set up JDK 17 - uses: actions/setup-java@v3 - with: - java-version: '17' - distribution: 'temurin' - cache: 'gradle' - - - name: Decode Keystore - env: - ENCODED_KEYSTORE: ${{ secrets.KEYSTORE }} - run: echo ${ENCODED_KEYSTORE} | base64 -d > ./android/app/keystore.jks - - - name: Build with Gradle - env: - SIGN_KEY_STORE_PATH: keystore.jks - SIGN_STORE_PASSWORD: ${{ secrets.SIGN_STORE_PASSWORD }} - SIGN_KEY_ALIAS: ${{ secrets.SIGN_KEY_ALIAS }} - SIGN_KEY_PASSWORD: ${{ secrets.SIGN_KEY_PASSWORD }} - run: | - cd ./android - echo SIGN_KEY_STORE_PATH=keystore.jks >> local.properties - echo SIGN_STORE_PASSWORD=${SIGN_STORE_PASSWORD} >> local.properties - echo SIGN_KEY_ALIAS=${SIGN_KEY_ALIAS} >> local.properties - echo SIGN_KEY_PASSWORD=${SIGN_KEY_PASSWORD} >> local.properties - chmod +x gradlew - ./gradlew clean - ./gradlew assembleDebug - - - name: Android test - uses: reactivecircus/android-emulator-runner@v2 - with: - api-level: 34 - target: google_apis_playstore - arch: x86_64 - script: cd ./android; ./gradlew connectedAndroidTest + steps: + - uses: actions/checkout@v4 + + - name: set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + cache: 'gradle' + + - name: Decode Keystore + env: + ENCODED_KEYSTORE: ${{ secrets.KEYSTORE }} + run: echo ${ENCODED_KEYSTORE} | base64 -d > ./android/app/keystore.jks + + - name: Build with Gradle + env: + SIGN_KEY_STORE_PATH: keystore.jks + SIGN_STORE_PASSWORD: ${{ secrets.SIGN_STORE_PASSWORD }} + SIGN_KEY_ALIAS: ${{ secrets.SIGN_KEY_ALIAS }} + SIGN_KEY_PASSWORD: ${{ secrets.SIGN_KEY_PASSWORD }} + SONATYPEUSERNAME: ${{ secrets.SONATYPEUSERNAME }} + SONATYPEPASSWORD: ${{ secrets.SONATYPEPASSWORD }} + run: | + cd ./android + echo SIGN_KEY_STORE_PATH=keystore.jks >> local.properties + echo SIGN_STORE_PASSWORD=${SIGN_STORE_PASSWORD} >> local.properties + echo SIGN_KEY_ALIAS=${SIGN_KEY_ALIAS} >> local.properties + echo SIGN_KEY_PASSWORD=${SIGN_KEY_PASSWORD} >> local.properties + echo sonatypeUsername=${SONATYPEUSERNAME} >> local.properties + echo sonatypePassword=${SONATYPEPASSWORD} >> local.properties + chmod +x gradlew + ./gradlew clean + ./gradlew assembleDebug + + - name: Android test + uses: reactivecircus/android-emulator-runner@v2 + with: + api-level: 34 + target: google_apis_playstore + arch: x86_64 + script: cd ./android; ./gradlew connectedAndroidTest diff --git a/.github/workflows/rust-publish.yml b/.github/workflows/rust-publish.yml index 670510c..7d8e79b 100644 --- a/.github/workflows/rust-publish.yml +++ b/.github/workflows/rust-publish.yml @@ -1,17 +1,17 @@ name: Publish Rust package -on: - release: +on: + release: types: [published] -env: +env: CARGO_TERM_COLOR: always -jobs: - build: +jobs: + build: runs-on: ubuntu-latest - steps: + steps: - uses: actions/checkout@v4 - name: Cargo publish run: cargo publish --token ${CARGO_REGISTRY_TOKEN} - env: + env: CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index fba0930..91521f5 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -1,26 +1,26 @@ name: Cargo Test -on: - push: +on: + push: branches: [ "main", "develop" ] - pull_request: + pull_request: branches: [ "main", "develop" ] -env: +env: CARGO_TERM_COLOR: always -jobs: - build: +jobs: + build: runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Build default - run: cargo build --verbose - - name: Build feature encryption - run: cargo build --features encryption --verbose - - name: Run default tests - run: cargo test --verbose - - name: Run feature encryption tests - run: cargo test --features encryption --verbose + steps: + - uses: actions/checkout@v4 + - name: Build default + run: cargo build --verbose + - name: Build feature encryption + run: cargo build --features encryption --verbose + - name: Run default tests + run: cargo test --verbose + - name: Run feature encryption tests + run: cargo test --features encryption --verbose diff --git a/.github/workflows/swift.yml b/.github/workflows/swift.yml index feb7e8d..6c1697c 100644 --- a/.github/workflows/swift.yml +++ b/.github/workflows/swift.yml @@ -1,17 +1,17 @@ name: Swift Test -on: - push: +on: + push: branches: [ "main", "develop" ] - pull_request: + pull_request: branches: [ "main", "develop" ] -jobs: - build: +jobs: + build: runs-on: macos-latest - steps: + steps: - uses: swift-actions/setup-swift@v1 - uses: actions/checkout@v4 - name: Build diff --git a/.space/Dockerfile b/.space/Dockerfile new file mode 100644 index 0000000..d8adf67 --- /dev/null +++ b/.space/Dockerfile @@ -0,0 +1,123 @@ +FROM ubuntu:20.04 + +ENV LANG=C.UTF-8 + +MAINTAINER Kexuan Yang + +# Support various rvm, nvm etc stuff which requires executing profile scripts (-l) +SHELL ["/bin/bash", "-lc"] +CMD ["/bin/bash", "-l"] + +# Set debconf to run non-interactively +RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections + +RUN apt-get update && apt-get install -y apt-utils apt-transport-https software-properties-common + +# Newest git +RUN apt-add-repository ppa:git-core/ppa -y && apt-get update + +RUN set -ex -o pipefail && apt-get install -y \ + # Useful utilities \ + curl unzip wget socat man-db rsync moreutils vim lsof ssh \ + # git \ + git \ + # JVM \ + openjdk-17-jdk-headless \ + # Android \ + build-essential libssl-dev libreadline-dev libcurl4 \ + binutils gnupg2 libc6-dev libcurl4-openssl-dev libedit2 \ + libgcc-9-dev libpython3.8 libsqlite3-0 libstdc++-9-dev \ + libxml2-dev libz3-dev pkg-config tzdata zlib1g-dev \ + && apt-get clean \ + && rm -r /var/lib/apt/lists/* + +ENV JAVA_HOME="/usr/lib/jvm/java-17-openjdk-amd64" + +# Android +ARG sdk_version=commandlinetools-linux-6200805_latest.zip +ARG android_home=/opt/android/sdk +ARG android_api=android-34 +ARG android_build_tools=34.0.0 +ARG android_ndk=false +ARG ndk_version=26.1.10909125 +ARG cmake=3.22.1 +RUN mkdir -p ${android_home} && \ + wget --quiet --output-document=/tmp/${sdk_version} https://dl.google.com/android/repository/${sdk_version} && \ + unzip -q /tmp/${sdk_version} -d ${android_home} && \ + rm /tmp/${sdk_version} + +ENV ANDROID_HOME=${android_home} +ENV PATH=${ANDROID_HOME}/emulator:${ANDROID_HOME}/tools:${ANDROID_HOME}/tools/bin:${ANDROID_HOME}/platform-tools:${PATH} + +RUN mkdir ~/.android && echo '### User Sources for Android SDK Manager' > ~/.android/repositories.cfg +RUN yes | sdkmanager --sdk_root=$ANDROID_HOME --licenses +RUN sdkmanager --sdk_root=$ANDROID_HOME --install \ + "platform-tools" \ + "build-tools;${android_build_tools}" \ + "platforms;${android_api}" +RUN if [ "$android_ndk" = true ] ; \ + then \ + echo "Installing Android NDK ($ndk_version, cmake: $cmake)"; \ + sdkmanager --sdk_root="$ANDROID_HOME" --install \ + "ndk;${ndk_version}" \ + "cmake;${cmake}" ; \ + else \ + echo "Skipping NDK installation"; \ + fi +# End Android + +# Swift +ARG SWIFT_SIGNING_KEY=A62AE125BBBFBB96A6E042EC925CC1CCED3D1561 +ARG SWIFT_PLATFORM=ubuntu20.04 +ARG SWIFT_BRANCH=swift-5.9.1-release +ARG SWIFT_VERSION=swift-5.9.1-RELEASE +ARG SWIFT_WEBROOT=https://download.swift.org + +ENV SWIFT_SIGNING_KEY=$SWIFT_SIGNING_KEY \ + SWIFT_PLATFORM=$SWIFT_PLATFORM \ + SWIFT_BRANCH=$SWIFT_BRANCH \ + SWIFT_VERSION=$SWIFT_VERSION \ + SWIFT_WEBROOT=$SWIFT_WEBROOT + +RUN set -e; \ + ARCH_NAME="$(dpkg --print-architecture)"; \ + url=; \ + case "${ARCH_NAME##*-}" in \ + 'amd64') \ + OS_ARCH_SUFFIX=''; \ + ;; \ + 'arm64') \ + OS_ARCH_SUFFIX='-aarch64'; \ + ;; \ + *) echo >&2 "error: unsupported architecture: '$ARCH_NAME'"; exit 1 ;; \ + esac; \ + SWIFT_WEBDIR="$SWIFT_WEBROOT/$SWIFT_BRANCH/$(echo $SWIFT_PLATFORM | tr -d .)$OS_ARCH_SUFFIX" \ + && SWIFT_BIN_URL="$SWIFT_WEBDIR/$SWIFT_VERSION/$SWIFT_VERSION-$SWIFT_PLATFORM$OS_ARCH_SUFFIX.tar.gz" \ + && SWIFT_SIG_URL="$SWIFT_BIN_URL.sig" \ + # - Download the GPG keys, Swift toolchain, and toolchain signature, and verify. + && export GNUPGHOME="$(mktemp -d)" \ + && curl -fsSL "$SWIFT_BIN_URL" -o swift.tar.gz "$SWIFT_SIG_URL" -o swift.tar.gz.sig \ + && gpg --batch --quiet --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys "$SWIFT_SIGNING_KEY" \ + && gpg --batch --verify swift.tar.gz.sig swift.tar.gz \ + # - Unpack the toolchain, set libs permissions, and clean up. + && tar -xzf swift.tar.gz --directory / --strip-components=1 \ + && chmod -R o+r /usr/lib/swift \ + && rm -rf "$GNUPGHOME" swift.tar.gz.sig swift.tar.gz +# End Swift + +ENV RUSTUP_HOME=/usr/local/rustup \ + CARGO_HOME=/usr/local/cargo \ + PATH=/usr/local/cargo/bin:$PATH +RUN set -eux \ + && curl https://sh.rustup.rs -sSf | sh -s -- -y --no-modify-path --profile minimal \ + && chmod -R a+w $RUSTUP_HOME $CARGO_HOME + +RUN echo "############################### Versions #####################################" && \ + java -version && \ + javac -version && \ + echo "" && \ + cargo --version && \ + rustc --version && \ + echo "" && \ + swift --version && \ + echo "############################### Versions #####################################" diff --git a/.space/mmkv.devfile.yaml b/.space/mmkv.devfile.yaml new file mode 100644 index 0000000..e0d3eea --- /dev/null +++ b/.space/mmkv.devfile.yaml @@ -0,0 +1,57 @@ +schemaVersion: 2.2.0 +metadata: + name: 'MMKV dev env configuration' +attributes: + space: + # regular, large, xlarge + instanceType: large + # a default IDE for the project + editor: + # (Required) IDE type: Idea, WebStorm, PyCharm, + # RubyMine, CLion, Fleet, GoLand, PhpStorm + type: Fleet + # Space uses JetBrains Toolbox App to install IDEs to a dev environment. + # updateChannel defines IDE version release stage: Release, EAP + updateChannel: EAP + # JVM configuration (appends to the default .vmoptions file) + vmoptions: + - '-Xms2048m' + - '-Xmx4096m' + # a warm-up snapshot + warmup: + # create a snapshot every Sunday (only for main branch) + startOn: + - type: schedule + cron: '0 2 * * SUN' + # run additional warmup script (IDE indexes will be built anyway) + script: + ./scripts/warmup.sh + requiredSecrets: + - name: ENCODED_ANDROID_KEYSTORE + description: 'Encoded Android keystore' + - name: SIGN_KEY_ALIAS + description: 'Android sign key alias' + - name: SIGN_KEY_PASSWORD + description: 'Android sign pwd' + - name: SIGN_STORE_PASSWORD + description: 'Android keystore pwd' + - name: GPG_SECRET + description: 'Encoded GPG key' + - name: GPG_KEY_ID + description: 'GPG key id' + - name: GPG_PWD + description: 'GPG pwd' + - name: SONATYPEUSERNAME + description: 'sonatype username' + - name: SONATYPEPASSWORD + description: 'sonatype pwd' +components: + - name: image-build + image: + # (Required) + imageName: mmkv-dev-image:latest + dockerfile: + # (Required) path to Dockerfile relative to projectRoot + uri: .space/Dockerfile + args: + - 'android_ndk=false' diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index 0e6d95f..28569ef 100644 --- a/android/app/build.gradle.kts +++ b/android/app/build.gradle.kts @@ -1,23 +1,12 @@ +import BuildUtil.loadProperities import org.gradle.api.artifacts.Configuration -import java.io.FileInputStream -import java.util.Properties plugins { id("com.android.application") id("org.jetbrains.kotlin.android") } -val propFile = File(rootProject.rootDir, "local.properties") -if (propFile.exists()) { - val prop = Properties().apply { - FileInputStream(propFile).use { - load(it) - } - } - prop.forEach { - ext.set(it.key as String, it.value as String) - } -} +project.loadProperities() android { namespace = "net.yangkx.mmkv.demo" diff --git a/android/buildSrc/src/main/java/BuildUtil.kt b/android/buildSrc/src/main/java/BuildUtil.kt new file mode 100644 index 0000000..d1fba38 --- /dev/null +++ b/android/buildSrc/src/main/java/BuildUtil.kt @@ -0,0 +1,87 @@ +import org.gradle.api.Project +import org.gradle.kotlin.dsl.extra +import java.io.File +import java.io.FileInputStream +import java.util.Properties +import kotlin.io.path.absolutePathString +import kotlin.io.path.writeText + +object BuildUtil { + + fun Project.loadProperities() { + loadProperityFile() + if (System.getenv("ENCODED_ANDROID_KEYSTORE")?.isNotEmpty() == true) { + prepareSignKey() + } + if (System.getenv("GPG_SECRET")?.isNotEmpty() == true) { + prepareGpgKey() + } + } + + private fun Project.loadProperityFile() { + val propFile = File(rootProject.rootDir, "local.properties") + if (propFile.exists()) { + val prop = Properties().apply { + FileInputStream(propFile).use { + load(it) + } + } + prop.forEach { + extra.set(it.key as String, it.value as String) + } + } + } + + private fun Project.prepareSignKey() { + val keyStorePath = "/usr/local/keystore.jks" + val file = File(keyStorePath) + if (!file.exists()) { + decodeBase64(System.getenv("ENCODED_ANDROID_KEYSTORE"), keyStorePath) + } + extra.set("SIGN_KEY_STORE_PATH", keyStorePath) + extra.set("SIGN_STORE_PASSWORD", System.getenv("SIGN_STORE_PASSWORD")) + extra.set("SIGN_KEY_ALIAS", System.getenv("SIGN_KEY_ALIAS")) + extra.set("SIGN_KEY_PASSWORD", System.getenv("SIGN_KEY_PASSWORD")) + } + + private fun Project.prepareGpgKey() { + val gpgPath = "/usr/local/secret.gpg" + val gpgFile = File(gpgPath) + if (!gpgFile.exists()) { + val tmpPath = decodeBase64(System.getenv("GPG_SECRET")) + project.exec { + commandLine = listOf( + "gpg", + "-o", + gpgPath, + "--dearmor", + tmpPath, + ) + } + } + extra.set("sonatypeUsername", System.getenv("SONATYPEUSERNAME")) + extra.set("sonatypePassword", System.getenv("SONATYPEPASSWORD")) + extra.set("signing.secretKeyRingFile", "/usr/local/secret.gpg") + extra.set("signing.keyId", System.getenv("GPG_KEY_ID")) + extra.set("signing.password", System.getenv("GPG_PWD")) + } + + private fun Project.decodeBase64(content: String, targetPath: String? = null): String { + val sourceFile = kotlin.io.path.createTempFile() + sourceFile.writeText(content) + val outFile = if (targetPath == null) { + File(kotlin.io.path.createTempFile().absolutePathString()) + } else { + File(targetPath) + } + exec { + commandLine = listOf( + "base64", + "-d", + sourceFile.absolutePathString() + ) + standardOutput = outFile.outputStream() + } + return outFile.absolutePath + } +} \ No newline at end of file diff --git a/android/library-encrypt/build.gradle.kts b/android/library-encrypt/build.gradle.kts index ad8d469..c9ad8aa 100644 --- a/android/library-encrypt/build.gradle.kts +++ b/android/library-encrypt/build.gradle.kts @@ -1,6 +1,5 @@ -import java.io.FileInputStream +import BuildUtil.loadProperities import java.net.URI -import java.util.Properties plugins { id("com.android.library") @@ -9,16 +8,7 @@ plugins { id("signing") } -val propFile = File(rootProject.rootDir, "local.properties") -val prop = Properties() -if (propFile.exists()) { - FileInputStream(propFile).use { - prop.load(it) - } - prop.forEach { - ext.set(it.key as String, it.value as String) - } -} +project.loadProperities() android { namespace = "net.yangkx.mmkv" @@ -99,8 +89,8 @@ publishing { Configuration.publishUrl ) credentials { - username = prop["sonatypeUsername"] as String? - password = prop["sonatypePassword"] as String? + username = project.ext.get("sonatypeUsername") as String? + password = project.ext.get("sonatypePassword") as String? } } } diff --git a/android/library/build.gradle.kts b/android/library/build.gradle.kts index e221364..38d2af6 100644 --- a/android/library/build.gradle.kts +++ b/android/library/build.gradle.kts @@ -1,6 +1,5 @@ -import java.io.FileInputStream +import BuildUtil.loadProperities import java.net.URI -import java.util.Properties plugins { id("com.android.library") @@ -9,16 +8,7 @@ plugins { id("signing") } -val propFile = File(rootProject.rootDir, "local.properties") -val prop = Properties() -if (propFile.exists()) { - FileInputStream(propFile).use { - prop.load(it) - } - prop.forEach { - ext.set(it.key as String, it.value as String) - } -} +project.loadProperities() android { namespace = "net.yangkx.mmkv" @@ -99,8 +89,8 @@ publishing { Configuration.publishUrl ) credentials { - username = prop["sonatypeUsername"] as String? - password = prop["sonatypePassword"] as String? + username = project.ext.get("sonatypeUsername") as String? + password = project.ext.get("sonatypePassword") as String? } } }