diff --git a/.github/workflows/ci-release.yml b/.github/workflows/ci-release.yml index b92a80cd..6fd77809 100644 --- a/.github/workflows/ci-release.yml +++ b/.github/workflows/ci-release.yml @@ -37,7 +37,7 @@ jobs: - name: build working-directory: ./dgca-verifier-app-android run: |- - ./gradlew --no-daemon build + ./gradlew --no-daemon build -PCONFIG_FILE_NAME="verifier-context.jsonc" - name: sign-tst working-directory: ./dgca-verifier-app-android run: |- diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 66fcf14a..1e601981 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,4 +39,4 @@ jobs: - name: build working-directory: ./dgca-verifier-app-android run: |- - ./gradlew --no-daemon build + ./gradlew --no-daemon build -PCONFIG_FILE_NAME="verifier-context.jsonc" diff --git a/README.md b/README.md index f79c93a4..a03f12ec 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,11 @@ android-app |___dgc-certlogic-android ``` +- To build project - it's required to add config json file to application assets folder. Structure of the file should be similar to: +'app/src/acc/assets/verifier-context.jsonc' or 'app/src/tst/assets/verifier-context.jsonc', depending on chosen flavor. +After related file has been added - it's name should be passed via gradle properties: +gradlew -PCONFIG_FILE_NAME="config.json" + #### Android Studio based build This project uses the Gradle build system. To build this project, use the `gradlew build` command or use "Run" in Android Studio. diff --git a/app/build.gradle b/app/build.gradle index 81007754..0ef8e255 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -41,6 +41,11 @@ android { versionCode Config.versionCode versionName Config.versionName + // It's required to provide config json files, and path to it. + // Examples based on different flavors could be found here: 'app/src/acc/assets/verifier-context.jsonc' or 'app/src/tst/assets/verifier-context.jsonc' + + buildConfigField "String", "CONFIG_FILE_NAME", "\"$CONFIG_FILE_NAME\"" + testInstrumentationRunner Config.androidTestInstrumentation } diff --git a/app/src/main/java/dgca/verifier/app/android/DgcaApplication.kt b/app/src/main/java/dgca/verifier/app/android/DgcaApplication.kt index ac066d99..bd7d6760 100644 --- a/app/src/main/java/dgca/verifier/app/android/DgcaApplication.kt +++ b/app/src/main/java/dgca/verifier/app/android/DgcaApplication.kt @@ -26,8 +26,12 @@ import android.app.Application import androidx.hilt.work.HiltWorkerFactory import androidx.work.* import dagger.hilt.android.HiltAndroidApp +import dgca.verifier.app.android.data.ConfigRepository import dgca.verifier.app.android.worker.* +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.launch import timber.log.Timber +import java.io.FileNotFoundException import java.util.concurrent.TimeUnit import javax.inject.Inject import kotlin.reflect.KClass @@ -38,6 +42,9 @@ class DgcaApplication : Application(), Configuration.Provider { @Inject lateinit var workerFactory: HiltWorkerFactory + @Inject + lateinit var configDataSource: ConfigRepository + override fun getWorkManagerConfiguration(): Configuration { return Configuration.Builder() .setWorkerFactory(workerFactory) @@ -50,6 +57,14 @@ class DgcaApplication : Application(), Configuration.Provider { Timber.plant(Timber.DebugTree()) } + GlobalScope.launch { + try { + configDataSource.local().getConfig() + } catch (fileNotFoundException: FileNotFoundException) { + throw IllegalStateException("It's required to provide config json files. As an example may be used 'app/src/acc/assets/verifier-context.jsonc' or 'app/src/tst/assets/verifier-context.jsonc' files") + } + } + WorkManager.getInstance(this).apply { schedulePeriodicWorker(WORKER_CONFIGS) schedulePeriodicWorker(WORKER_RULES) diff --git a/app/src/main/java/dgca/verifier/app/android/data/local/LocalConfigDataSource.kt b/app/src/main/java/dgca/verifier/app/android/data/local/LocalConfigDataSource.kt index b86d56a3..da6358ef 100644 --- a/app/src/main/java/dgca/verifier/app/android/data/local/LocalConfigDataSource.kt +++ b/app/src/main/java/dgca/verifier/app/android/data/local/LocalConfigDataSource.kt @@ -25,6 +25,7 @@ package dgca.verifier.app.android.data.local import android.content.Context import com.fasterxml.jackson.databind.ObjectMapper import dagger.hilt.android.qualifiers.ApplicationContext +import dgca.verifier.app.android.BuildConfig import dgca.verifier.app.android.data.Config import timber.log.Timber import java.io.* @@ -38,7 +39,6 @@ class LocalConfigDataSource @Inject constructor( private lateinit var config: Config companion object { - const val DEFAULT_CONFIG_FILE = "verifier-context.jsonc" const val CONFIG_FILE = "config.json" } @@ -76,7 +76,7 @@ class LocalConfigDataSource @Inject constructor( } private fun defaultConfig(): Config = - context.assets.open(DEFAULT_CONFIG_FILE).bufferedReader().use { + context.assets.open(BuildConfig.CONFIG_FILE_NAME).bufferedReader().use { objectMapper.readValue(it.readText(), Config::class.java) } } \ No newline at end of file