Skip to content
This repository has been archived by the owner on Sep 19, 2019. It is now read-only.

Commit

Permalink
Enable minification and add proguard configs
Browse files Browse the repository at this point in the history
All apk producing modules now have minification enabled.
Code that is exposed to different modules
is now being kept by a proguard.pro file within the
base directory of each project.
  • Loading branch information
keyboardsurfer committed Dec 13, 2017
1 parent 9695094 commit b78449c
Show file tree
Hide file tree
Showing 57 changed files with 421 additions and 89 deletions.
21 changes: 21 additions & 0 deletions README.md
Expand Up @@ -65,6 +65,27 @@ adb shell am start -a android.intent.action.VIEW -c android.intent.category.BROW
cd - # takes you back to the root directory
```

### Code minification & obfuscation

Each sample's `minified` build type has code minification enabled.
In case API surfaces are being exposed to other modules, these surfaces are being explicitly excluded from
the obfuscation process through a proguard configuration file.
Take a look in a module's `build.gradle` file to see what is being done for that module.

#### Usage

From Android Studio
* Open Build Variants
* Change each variant to a "minified" variant
* Run the "instant" configuration of the sample

From the command line
* Assemble a minified build `./gradlew assembleMinified`
* Navigate to `instant/build/outputs/apk/*/minified`
* Run the instant app as described in the above section

Note: For samples containing flavors the paths & variant names will be slightly different.

### Troubleshooting

Refer to the [troubleshooting section](https://developer.android.com/topic/instant-apps/troubleshoot.html)
Expand Down
12 changes: 11 additions & 1 deletion analytics/base/build.gradle
Expand Up @@ -28,8 +28,18 @@ android {
versionCode rootProject.versionCode
versionName rootProject.versionName
}

// Switch between test types by swapping commented out state
testBuildType /* 'debug' */ 'minified'

buildTypes {
release {}
minified {
debuggable true
minifyEnabled true
signingConfig signingConfigs.debug
proguardFiles getDefaultProguardFile('proguard-android.txt'), '../proguard.pro'
}
debug {}
}
}

Expand Down
11 changes: 10 additions & 1 deletion analytics/feature/build.gradle
Expand Up @@ -27,8 +27,17 @@ android {

testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
}

// Switch between test types by swapping commented out state
testBuildType /* 'debug' */ 'minified'

buildTypes {
release {}
minified {
debuggable true
minifyEnabled true
signingConfig signingConfigs.debug
proguardFiles getDefaultProguardFile('proguard-android.txt'), '../proguard.pro'
}
debug {}
}

Expand Down
12 changes: 11 additions & 1 deletion analytics/installed/build.gradle
Expand Up @@ -29,8 +29,18 @@ android {
versionName rootProject.versionName

}

// Switch between test types by swapping commented out state
testBuildType /* 'debug' */ 'minified'

buildTypes {
release {}
minified {
debuggable true
minifyEnabled true
signingConfig signingConfigs.debug
proguardFiles getDefaultProguardFile('proguard-android.txt'), '../proguard.pro'
}
debug {}
}
}

Expand Down
9 changes: 9 additions & 0 deletions analytics/proguard.pro
@@ -0,0 +1,9 @@
-keep class android.support.v7.app.AppCompatActivity {
public void onCreate(...);
}
-keep class com.google.firebase.analytics.FirebaseAnalytics {
public protected *;
}
-keep class com.google.android.instantapps.InstantApps {
public boolean isInstantApp(...);
}
9 changes: 9 additions & 0 deletions configuration-apks/features/build.gradle
Expand Up @@ -42,7 +42,16 @@ android {
}
}

// Switch between test types by swapping commented out state
testBuildType /* 'debug' */ 'minified'

buildTypes {
minified {
debuggable true
minifyEnabled true
signingConfig signingConfigs.debug
proguardFiles getDefaultProguardFile('proguard-android.txt'), '../proguard.pro'
}
debug {}
}

Expand Down
9 changes: 9 additions & 0 deletions configuration-apks/installed/build.gradle
Expand Up @@ -31,7 +31,16 @@ android {
missingDimensionStrategy 'delivery', 'installed'
}

// Switch between test types by swapping commented out state
testBuildType /* 'debug' */ 'minified'

buildTypes {
minified {
debuggable true
signingConfig signingConfigs.debug
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), '../proguard.pro'
}
debug {}
}
}
Expand Down
1 change: 1 addition & 0 deletions configuration-apks/instant/build.gradle
Expand Up @@ -26,6 +26,7 @@ android {
}

buildTypes {
minified {}
debug {}
}
}
Expand Down
3 changes: 3 additions & 0 deletions configuration-apks/proguard.pro
@@ -0,0 +1,3 @@
-keep class android.support.v7.app.AppCompatActivity {
public void onCreate(...);
}
11 changes: 10 additions & 1 deletion cookie-api/features/base/build.gradle
Expand Up @@ -33,6 +33,7 @@ android {
playServices {
// Demonstrates usage of the Cookie API with APILevel < 26
dimension "version"
proguardFiles '../../proguard-playservices.pro'
}
framework {
dimension "version"
Expand All @@ -41,8 +42,16 @@ android {
}
}

// Switch between test types by swapping commented out state
testBuildType /* 'debug' */ 'minified'

buildTypes {
release {}
minified {
debuggable true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), '../../proguard.pro'
signingConfig signingConfigs.debug
}
debug {}
}

Expand Down
9 changes: 8 additions & 1 deletion cookie-api/features/cookie/build.gradle
Expand Up @@ -30,8 +30,15 @@ android {
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
}

// Switch between test types by swapping commented out state
testBuildType /* 'debug' */ 'minified'

buildTypes {
release {}
minified {
debuggable true
minifyEnabled true
signingConfig signingConfigs.debug
}
debug {}
}

Expand Down
7 changes: 6 additions & 1 deletion cookie-api/installed/build.gradle
Expand Up @@ -29,7 +29,12 @@ android {
}

buildTypes {
release {}
minified {
debuggable true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), '../proguard.pro'
signingConfig signingConfigs.debug
}
debug {}
}

Expand Down
2 changes: 1 addition & 1 deletion cookie-api/instant/build.gradle
Expand Up @@ -28,7 +28,7 @@ android {
}

buildTypes {
release {}
minified {}
debug {}
}

Expand Down
5 changes: 5 additions & 0 deletions cookie-api/proguard-playservices.pro
@@ -0,0 +1,5 @@

-keep class com.google.android.gms.instantapps.PackageManagerCompat { *; }
-keep class com.google.android.gms.instantapps.InstantApps {
public static *** getPackageManagerCompat(***);
}
3 changes: 3 additions & 0 deletions cookie-api/proguard.pro
@@ -0,0 +1,3 @@
-keep class android.support.v7.app.AppCompatActivity {
public void onCreate(...);
}
10 changes: 9 additions & 1 deletion flavors/features/base/build.gradle
Expand Up @@ -27,9 +27,17 @@ android {
versionName rootProject.versionName
}

// Switch between test types by swapping commented out state
testBuildType /* 'debug' */ 'minified'

buildTypes {
minified {
debuggable true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), '../../proguard.pro'
signingConfig signingConfigs.debug
}
debug {}
release {}
}

flavorDimensions "pricing"
Expand Down
9 changes: 8 additions & 1 deletion flavors/features/bye/build.gradle
Expand Up @@ -29,9 +29,16 @@ android {
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
}

// Switch between test types by swapping commented out state
testBuildType /* 'debug' */ 'minified'

buildTypes {
minified {
debuggable true
minifyEnabled true
signingConfig signingConfigs.debug
}
debug {}
release {}
}

flavorDimensions "pricing"
Expand Down
9 changes: 8 additions & 1 deletion flavors/features/hello/build.gradle
Expand Up @@ -29,9 +29,16 @@ android {
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
}

// Switch between test types by swapping commented out state
testBuildType /* 'debug' */ 'minified'

buildTypes {
minified {
debuggable true
minifyEnabled true
signingConfig signingConfigs.debug
}
debug {}
release {}
}

flavorDimensions "pricing"
Expand Down
11 changes: 8 additions & 3 deletions flavors/installed/build.gradle
Expand Up @@ -27,11 +27,16 @@ android {
versionName rootProject.versionName
}

// Switch between test types by swapping commented out state
testBuildType /* 'debug' */ 'minified'

buildTypes {
debug {}
release {
signingConfig = signingConfigs.debug
minified {
debuggable true
minifyEnabled true
signingConfig signingConfigs.debug
}
debug {}
}

flavorDimensions "pricing"
Expand Down
2 changes: 1 addition & 1 deletion flavors/instant/build.gradle
Expand Up @@ -27,7 +27,7 @@ android {
versionName rootProject.versionName
}
buildTypes {
release {}
minified {}
debug {}
}

Expand Down
3 changes: 3 additions & 0 deletions flavors/proguard.pro
@@ -0,0 +1,3 @@
-keep public class android.support.v7.app.AppCompatActivity {
public protected *;
}
11 changes: 10 additions & 1 deletion hello-feature-module/features/base/build.gradle
Expand Up @@ -28,8 +28,17 @@ android {

testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
}

// Switch between test types by swapping commented out state
testBuildType /* 'debug' */ 'minified'

buildTypes {
release {}
minified {
debuggable true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), '../../proguard.pro'
signingConfig signingConfigs.debug
}
debug {}
}

Expand Down
10 changes: 9 additions & 1 deletion hello-feature-module/features/bye/build.gradle
Expand Up @@ -27,8 +27,16 @@ android {

testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
}

// Switch between test types by swapping commented out state
testBuildType /* 'debug' */ 'minified'

buildTypes {
release {}
minified {
debuggable true
minifyEnabled true
signingConfig signingConfigs.debug
}
debug {}
}
}
Expand Down
10 changes: 9 additions & 1 deletion hello-feature-module/features/hello/build.gradle
Expand Up @@ -28,8 +28,16 @@ android {

testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
}

// Switch between test types by swapping commented out state
testBuildType /* 'debug' */ 'minified'

buildTypes {
release {}
minified {
debuggable true
minifyEnabled true
signingConfig signingConfigs.debug
}
debug {}
}
}
Expand Down
9 changes: 8 additions & 1 deletion hello-feature-module/installed/build.gradle
Expand Up @@ -27,8 +27,15 @@ android {
versionCode rootProject.versionCode
versionName rootProject.versionName
}

// Switch between test types by swapping commented out state
testBuildType /* 'debug' */ 'minified'

buildTypes {
release {}
minified {
debuggable true
minifyEnabled true
}
debug {}
}
}
Expand Down
2 changes: 1 addition & 1 deletion hello-feature-module/instant/build.gradle
Expand Up @@ -27,7 +27,7 @@ android {
versionName rootProject.versionName
}
buildTypes {
release {}
minified {}
debug {}
}
}
Expand Down
3 changes: 3 additions & 0 deletions hello-feature-module/proguard.pro
@@ -0,0 +1,3 @@
-keep public class android.support.v7.app.AppCompatActivity {
public protected *;
}

0 comments on commit b78449c

Please sign in to comment.