Skip to content

Commit

Permalink
Enable Proguard for release flavor (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
niehusst committed Nov 21, 2020
1 parent cc79b91 commit 017b48c
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 43 deletions.
13 changes: 7 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ aliases:
- &root_dir
~/code

- &set_api_keys
name: Generate secrets file
- &set_secrets_from_env_vars
# write circleci env vars into local files
name: Generate secrets files
command: |
echo "SPOTIFY_CLIENT_ID="$SPOTIFY_CLIENT_ID > apikey.properties
echo $PARTYQ_KEYSTORE_FILE | base64 --decode > partyq_release.jks
defaults: &defaults
working_directory: *root_dir
Expand All @@ -24,15 +26,14 @@ attach_workspace: &attach_workspace
at: *root_dir



version: 2.1
jobs:
build:
<<: *defaults
steps:
- checkout
- *restore_deps
- run: *set_api_keys
- run: *set_secrets_from_env_vars
- run:
name: Download Dependencies
command: ./gradlew androidDependencies
Expand All @@ -46,7 +47,7 @@ jobs:
- checkout
- *attach_workspace
- *restore_deps
- run: *set_api_keys
- run: *set_secrets_from_env_vars
- run:
name: Lint
command: ./gradlew lint --stacktrace --status
Expand All @@ -58,7 +59,7 @@ jobs:
- checkout
- *attach_workspace
- *restore_deps
- run: *set_api_keys
- run: *set_secrets_from_env_vars
- run:
name: Run Unit Tests
command: ./gradlew test --stacktrace
Expand Down
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,16 @@ captures/

# Keystore files
# Uncomment the following lines if you do not want to check your keystore files in.
#*.jks
#*.keystore
*.jks
*.keystore
keystore.properties

# External native build folder generated in Android Studio 2.2 and later
.externalNativeBuild
.cxx/

# Google Services (e.g. APIs or Firebase)
# google-services.json
google-services.json

# Freeline
freeline.py
Expand Down
85 changes: 62 additions & 23 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,43 @@ android {
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

signingConfigs {
release {
def keystorePropertiesFile = rootProject.file("keystore.properties")
if (keystorePropertiesFile.exists()) {
// local env: load release build info from properties file
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
def keystore_fname = keystoreProperties["PARTYQ_KEYSTORE_FILENAME"]
def keystore_password = keystoreProperties["PARTYQ_KEYSTORE_PASSWORD"]
def key_alias = keystoreProperties["PARTYQ_KEY_ALIAS"]
def key_password = keystoreProperties["PARTYQ_KEY_PASSWORD"]

storeFile file(keystore_fname)
storePassword keystore_password
keyAlias key_alias
keyPassword key_password
} else {
// circleci env: load release build info from env vars
def keystore_fname = System.getenv("PARTYQ_KEYSTORE_FILENAME")
def keystore_password = System.getenv("PARTYQ_KEYSTORE_PASSWORD")
def key_alias = System.getenv("PARTYQ_KEY_ALIAS")
def key_password = System.getenv("PARTYQ_KEY_PASSWORD")

storeFile file(keystore_fname)
storePassword keystore_password
keyAlias key_alias
keyPassword key_password
}
}
}

buildTypes {
release {
minifyEnabled false
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
}

Expand All @@ -31,16 +64,20 @@ android {
}
}

dataBinding {
enabled = true
enabledForTests = true
buildFeatures {
dataBinding = true
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

packagingOptions {
// exclude kotlin coroutines debugger info
exclude "DebugProbesKt.bin"
}

kotlinOptions {
jvmTarget = "1.8"
}
Expand All @@ -50,51 +87,53 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(':spotify-developer-sdk')
implementation "com.google.code.gson:gson:2.8.5"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"

implementation "androidx.annotation:annotation:$androidXAnnotations"
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.core:core-ktx:1.3.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
implementation 'androidx.core:core-ktx:1.3.1'
implementation "androidx.fragment:fragment-ktx:$fragmentVersion"
implementation "com.google.android.material:material:$materialVersion"
implementation "androidx.recyclerview:recyclerview:$recyclerViewVersion"
implementation "androidx.annotation:annotation:$androidXAnnotations"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutinesVersion"
implementation "com.fasterxml.jackson.core:jackson-databind:2.7.3"
implementation "com.github.bumptech.glide:glide:$glideVersion"
implementation "com.google.android.gms:play-services-nearby:17.0.0"
implementation "com.google.android.material:material:$materialVersion"
implementation "com.google.code.gson:gson:2.8.5"
implementation "com.jakewharton.timber:timber:$timberVersion"
implementation 'com.spotify.android:auth:1.1.0'
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation "com.squareup.retrofit2:converter-moshi:2.4.0"
implementation "com.google.android.gms:play-services-nearby:17.0.0"
implementation "com.github.bumptech.glide:glide:$glideVersion"
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutinesVersion"
kapt "com.github.bumptech.glide:compiler:$glideVersion"

// Architecture deps
implementation "androidx.lifecycle:lifecycle-extensions:$archLifecycleVersion"
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation "android.arch.lifecycle:common-java8:1.1.1"
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation "androidx.lifecycle:lifecycle-extensions:$archLifecycleVersion"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$archLifecycleVersion"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$archLifecycleVersion"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$archLifecycleVersion"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$archLifecycleVersion"
implementation "androidx.navigation:navigation-fragment-ktx:$navigationVersion"
implementation "androidx.navigation:navigation-ui-ktx:$navigationVersion"

// Unit test deps
testImplementation "androidx.arch.core:core-testing:$archTestingVersion"
testImplementation "androidx.test:core-ktx:$androidXTestCoreVersion"
testImplementation "androidx.test.ext:junit:$androidXTestExtKotlinRunnerVersion"
testImplementation "io.mockk:mockk:$mockkVersion"
testImplementation "junit:junit:$junitVersion"
testImplementation "androidx.test.ext:junit:$androidXTestExtKotlinRunnerVersion"
testImplementation "androidx.test:core-ktx:$androidXTestCoreVersion"
testImplementation "androidx.arch.core:core-testing:$archTestingVersion"
testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutinesVersion"

// Instrumented test deps
androidTestImplementation "io.mockk:mockk-android:$mockkVersion"
androidTestImplementation "androidx.navigation:navigation-testing:$navigationVersion"
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation "androidx.test:core:$androidXTestCoreVersion"
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation "androidx.test:rules:$testRulesVersion"
androidTestImplementation "androidx.test.espresso:espresso-contrib:$espressoVersion"
androidTestImplementation "androidx.test.espresso:espresso-core:$espressoVersion"
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation "androidx.test:rules:$testRulesVersion"
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation "io.mockk:mockk-android:$mockkVersion"
androidTestImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutinesVersion"
// FragmentScenario (should be test impl, but bug forces to be regular impl)
debugImplementation "androidx.fragment:fragment-testing:$fragmentVersion"
Expand Down
91 changes: 80 additions & 11 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
##
## Copyright 2020 Liam Niehus-Staab
##
## Licensed under the Apache License, Version 2.0 (the "License");
## you may not use this file except in compliance with the License.
## You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
##

# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
Expand All @@ -21,14 +37,67 @@
#-renamesourcefileattribute SourceFile

# for Glide
#-keep public class * implements com.bumptech.glide.module.GlideModule
#-keep class * extends com.bumptech.glide.module.AppGlideModule {
# <init>(...);
#}
#-keep public enum com.bumptech.glide.load.ImageHeaderParser$** {
# **[] $VALUES;
# public *;
#}
#-keep class com.bumptech.glide.load.data.ParcelFileDescriptorRewinder$InternalRewinder {
# *** rewind();
#}
-keep public class * implements com.bumptech.glide.module.GlideModule
-keep class * extends com.bumptech.glide.module.AppGlideModule {
<init>(...);
}
-keep public enum com.bumptech.glide.load.ImageHeaderParser$** {
**[] $VALUES;
public *;
}
-keep class com.bumptech.glide.load.data.ParcelFileDescriptorRewinder$InternalRewinder {
*** rewind();
}

# AndroidX Navigation
-keepnames class androidx.navigation.fragment.NavHostFragment

# Timber
-dontwarn org.jetbrains.annotations.**

# dont get rid of generated databinding classes
-keep class * extends androidx.databinding.DataBinderMapper { *; }

# Required for Retrofit/OkHttp
-dontwarn javax.annotation.**
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
-keepattributes *Annotation*, Signature, Exceptions

##---------------Begin: proguard configuration for Gson ----------
# Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by default, so configure it to keep all of it.
-keepattributes Signature

# For using GSON @Expose annotation
-keepattributes *Annotation*

# Gson specific classes
-dontwarn sun.misc.**
#-keep class com.google.gson.stream.** { *; }

# Application classes that will be serialized/deserialized over Gson
-keep class com.google.gson.examples.android.model.** { <fields>; }

# Prevent proguard from stripping interface information from TypeAdapter, TypeAdapterFactory,
# JsonSerializer, JsonDeserializer instances (so they can be used in @JsonAdapter)
-keep class * extends com.google.gson.TypeAdapter
-keep class * implements com.google.gson.TypeAdapterFactory
-keep class * implements com.google.gson.JsonSerializer
-keep class * implements com.google.gson.JsonDeserializer

# Prevent R8 from leaving Data object members always null
-keepclassmembers,allowobfuscation class * {
@com.google.gson.annotations.SerializedName <fields>;
}
##---------------End: proguard configuration for Gson ----------

# Jackson-databind
-keep class com.fasterxml.jackson.databind.ser.std.StdSerializer { *; }
-keep class com.fasterxml.jackson.databind.deser.std.StdDeserializer { *; }

# keep all network serialized models
-keep class com.niehusst.partyq.network.models.** { *; }


# ignore unimportant warnings
-dontwarn java.lang.instrument.ClassFileTransformer

0 comments on commit 017b48c

Please sign in to comment.