Skip to content

Commit d3fe052

Browse files
Merge pull request #627 from nimblehq/feature/570-add-pre-release-build-type-to-distribute-release-build-with-chucker
[#570] Add preRelease build type to distribute release build with Chucker
2 parents cb0476b + 001c336 commit d3fe052

File tree

21 files changed

+136
-77
lines changed

21 files changed

+136
-77
lines changed

.cicdtemplate/.github/workflows/deploy_staging_and_production_to_firebase_app_distribution.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,23 +57,23 @@ jobs:
5757
path: app/build/reports/kover/
5858

5959
- name: Build staging APK
60-
run: ./gradlew assembleStagingDebug
60+
run: ./gradlew assembleStagingPreRelease
6161

6262
- name: Deploy staging to Firebase
6363
uses: wzieba/Firebase-Distribution-Github-Action@v1
6464
with:
6565
appId: ${{secrets.FIREBASE_APP_ID_STAGING}}
6666
serviceCredentialsFileContent: ${{ secrets.FIREBASE_SERVICE_ACCOUNT_CREDENTIAL_FILE_CONTENT }}
6767
groups: testers
68-
file: app/build/outputs/apk/staging/debug/app-staging-debug.apk
68+
file: app/build/outputs/apk/staging/preRelease/app-staging-preRelease.apk
6969

7070
- name: Build production APK
71-
run: ./gradlew assembleProductionDebug
71+
run: ./gradlew assembleProductionPreRelease
7272

7373
- name: Deploy production to Firebase
7474
uses: wzieba/Firebase-Distribution-Github-Action@v1
7575
with:
7676
appId: ${{secrets.FIREBASE_APP_ID_PRODUCTION}}
7777
serviceCredentialsFileContent: ${{ secrets.FIREBASE_SERVICE_ACCOUNT_CREDENTIAL_FILE_CONTENT }}
7878
groups: testers
79-
file: app/build/outputs/apk/production/debug/app-production-debug.apk
79+
file: app/build/outputs/apk/production/preRelease/app-production-preRelease.apk

sample-compose/app/build.gradle.kts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ android {
4949
buildConfigField("String", "BASE_API_URL", "\"https://jsonplaceholder.typicode.com/\"")
5050
}
5151

52+
create(BuildType.PRERELEASE) {
53+
initWith(getByName(BuildType.RELEASE))
54+
}
55+
5256
getByName(BuildType.DEBUG) {
5357
// For quickly testing build with proguard, enable this
5458
isMinifyEnabled = false
@@ -139,6 +143,7 @@ dependencies {
139143
implementation(libs.kotlinx.collections.immutable)
140144

141145
debugImplementation(libs.chucker)
146+
preReleaseImplementation(libs.chucker)
142147
releaseImplementation(libs.chucker.noOp)
143148

144149
// Unit test

sample-compose/app/proguard-rules.pro

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,3 @@
1919
# If you keep the line number information, uncomment this to
2020
# hide the original source file name.
2121
#-renamesourcefileattribute SourceFile
22-
23-
# Data class
24-
-keepclassmembers class co.nimblehq.sample.compose.data.remote.models.requests.** { *; }
25-
-keepclassmembers class co.nimblehq.sample.compose.data.remote.models.responses.** { *; }

sample-compose/app/src/main/java/co/nimblehq/sample/compose/di/modules/OkHttpClientModule.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import okhttp3.logging.HttpLoggingInterceptor
1313
import java.util.concurrent.*
1414

1515
private const val READ_TIME_OUT = 30L
16+
private const val BUILD_TYPE_RELEASE = "release"
1617

1718
@Module
1819
@InstallIn(SingletonComponent::class)
@@ -22,7 +23,7 @@ class OkHttpClientModule {
2223
fun provideOkHttpClient(
2324
chuckerInterceptor: ChuckerInterceptor
2425
) = OkHttpClient.Builder().apply {
25-
if (BuildConfig.DEBUG) {
26+
if (!BuildConfig.BUILD_TYPE.equals(BUILD_TYPE_RELEASE, ignoreCase = true)) {
2627
addInterceptor(HttpLoggingInterceptor().apply {
2728
level = HttpLoggingInterceptor.Level.BODY
2829
})

sample-compose/buildSrc/src/main/java/Configurations.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ object Flavor {
66

77
object BuildType {
88
const val DEBUG = "debug"
9+
const val PRERELEASE = "preRelease"
910
const val RELEASE = "release"
1011
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import org.gradle.api.artifacts.Dependency
2+
import org.gradle.api.artifacts.dsl.DependencyHandler
3+
4+
fun DependencyHandler.preReleaseImplementation(dependencyNotation: Any): Dependency? =
5+
add("preReleaseImplementation", dependencyNotation)

sample-compose/data/build.gradle.kts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ android {
1515

1616
buildTypes {
1717
getByName(BuildType.RELEASE) {
18-
isMinifyEnabled = true
19-
proguardFiles(
20-
getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
21-
)
18+
isMinifyEnabled = false
19+
consumerProguardFiles("consumer-rules.pro")
20+
}
21+
22+
create(BuildType.PRERELEASE) {
23+
initWith(getByName(BuildType.RELEASE))
2224
}
2325

2426
getByName(BuildType.DEBUG) {
@@ -59,6 +61,10 @@ dependencies {
5961
api(libs.bundles.moshi)
6062
implementation(libs.moshi)
6163

64+
debugImplementation(libs.chucker)
65+
preReleaseImplementation(libs.chucker)
66+
releaseImplementation(libs.chucker.noOp)
67+
6268
// Testing
6369
testImplementation(libs.bundles.unitTest)
6470
testImplementation(libs.test.core.ktx)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# RETROFIT https://square.github.io/retrofit/
2+
# R8 full mode https://github.com/square/retrofit/issues/3751#issuecomment-1192043644
3+
# Keep generic signature of Call, Response (R8 full mode strips signatures from non-kept items).
4+
-keep,allowobfuscation,allowshrinking interface retrofit2.Call
5+
-keep,allowobfuscation,allowshrinking class retrofit2.Response
6+
# Keep classes for NewRelic instrumentation
7+
# https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile-android/install-configure/configure-proguard-or-dexguard-android-apps/#proguard-library
8+
-keep class retrofit2.** { *; }
9+
-dontwarn retrofit2.**
10+
# To enable the workaround in the [RetrofitDynamicBaseUrlBinder]
11+
-keep class retrofit2.Retrofit { *; }
12+
-keep class okhttp3.HttpUrl { *; }
13+
14+
# With R8 full mode generic signatures are stripped for classes that are not
15+
# kept. Suspend functions are wrapped in continuations where the type argument
16+
# is used.
17+
-keep,allowobfuscation,allowshrinking class kotlin.coroutines.Continuation
18+
19+
# MOSHI https://github.com/square/moshi/tree/master?tab=readme-ov-file#r8--proguard
20+
21+
# OKHTTP https://square.github.io/okhttp/features/r8_proguard/
22+
# Keep classes for NewRelic instrumentation
23+
# https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile-android/install-configure/configure-proguard-or-dexguard-android-apps/#proguard-library
24+
-keep class okhttp3.** { *; }
25+
-dontwarn okhttp3.**
26+
-dontwarn okio.**
27+
# To enable the workaround in the [RequestInterceptor] for [NewRelic.addHTTPHeadersTrackingFor]
28+
-keep class okhttp3.Headers { *; }
29+
30+
# Moshi's models https://medium.com/androiddevelopers/practical-proguard-rules-examples-5640a3907dc9
31+
-keep class co.nimblehq.sample.compose.data.remote.models.requests.** { *; }
32+
-keep class co.nimblehq.sample.compose.data.remote.models.responses.** { *; }
Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,5 @@
1-
# Add project specific ProGuard rules here.
2-
# You can control the set of applied configuration files using the
3-
# proguardFiles setting in build.gradle.kts.
1+
# ProGuard rules for data module
42
#
5-
# For more details, see
6-
# http://developer.android.com/guide/developing/tools/proguard.html
7-
8-
# If your project uses WebView with JS, uncomment the following
9-
# and specify the fully qualified class name to the JavaScript interface
10-
# class:
11-
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12-
# public *;
13-
#}
14-
15-
# Uncomment this to preserve the line number information for
16-
# debugging stack traces.
17-
#-keepattributes SourceFile,LineNumberTable
18-
19-
# If you keep the line number information, uncomment this to
20-
# hide the original source file name.
21-
#-renamesourcefileattribute SourceFile
3+
# Note: This module has minification disabled (isMinifyEnabled = false).
4+
# All ProGuard rules for this module are defined in consumer-rules.pro,
5+
# which is automatically applied to consuming modules (app) during their minification.

sample-compose/data/src/main/java/co/nimblehq/sample/compose/data/extensions/ResponseMapping.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ private fun Throwable.mapError(): Throwable {
2929
is HttpException -> {
3030
val errorResponse = parseErrorResponse(response())
3131
ApiException(
32-
errorResponse?.toModel(),
33-
code(),
34-
message()
32+
error = errorResponse?.toModel(),
33+
httpCode = code(),
34+
httpMessage = message()
3535
)
3636
}
3737
else -> this
@@ -44,9 +44,9 @@ private fun parseErrorResponse(response: Response<*>?): ErrorResponse? {
4444
val moshi = MoshiBuilderProvider.moshiBuilder.build()
4545
val adapter = moshi.adapter(ErrorResponse::class.java)
4646
adapter.fromJson(jsonString.orEmpty())
47-
} catch (exception: IOException) {
47+
} catch (_: IOException) {
4848
null
49-
} catch (exception: JsonDataException) {
49+
} catch (_: JsonDataException) {
5050
null
5151
}
5252
}

0 commit comments

Comments
 (0)