From ed5b780ee66b2df8a74a3a2f3e32e71d03d7cb51 Mon Sep 17 00:00:00 2001 From: Matthieu <24-artectrex@users.noreply.shinice.net> Date: Mon, 25 Jan 2021 20:41:00 +0100 Subject: [PATCH] Release, and minify apk/use proguard properly --- app/build.gradle | 13 ++++--- app/proguard-rules.pro | 83 +++++++++++++++++++++++++++++++++--------- build.gradle | 2 +- 3 files changed, 73 insertions(+), 25 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 9291c188..ce707c1b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -24,8 +24,8 @@ android { applicationId "com.h.pixeldroid" minSdkVersion 23 targetSdkVersion 30 - versionCode 9 - versionName "1.0.alpha8" + versionCode 10 + versionName "1.0.alpha9" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunnerArguments clearPackageData: 'true' @@ -46,8 +46,10 @@ android { testCoverageEnabled true } release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + minifyEnabled true + shrinkResources true + useProguard true + proguardFiles 'proguard-rules.pro' } } testOptions { @@ -64,7 +66,6 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" /** * AndroidX dependencies: @@ -80,7 +81,7 @@ dependencies { implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0" implementation 'androidx.navigation:navigation-fragment-ktx:2.3.2' implementation 'androidx.navigation:navigation-ui-ktx:2.3.2' - implementation 'androidx.paging:paging-runtime-ktx:3.0.0-alpha11' + implementation 'androidx.paging:paging-runtime-ktx:3.0.0-alpha12' implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.2.0' implementation 'androidx.lifecycle:lifecycle-viewmodel-savedstate:2.2.0' implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.2.0" diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index f1b42451..126f20d8 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -1,21 +1,68 @@ -# Add project specific ProGuard rules here. -# You can control the set of applied configuration files using the -# proguardFiles setting in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html +# proguard file largely copied from Tusky's +# GENERAL OPTIONS (inspired from AOSP's proguard-android-optimize.txt) -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} +# turn on all optimizations except those that are known to cause problems on Android +-optimizations !code/simplification/cast,!field/*,!class/merging/* +-optimizationpasses 6 +-allowaccessmodification +-dontpreverify -# Uncomment this to preserve the line number information for -# debugging stack traces. -#-keepattributes SourceFile,LineNumberTable +-dontusemixedcaseclassnames +-dontskipnonpubliclibraryclasses +-keepattributes *Annotation* -# If you keep the line number information, uncomment this to -# hide the original source file name. -#-renamesourcefileattribute SourceFile +# For native methods, see http://proguard.sourceforge.net/manual/examples.html#native +-keepclasseswithmembernames class * { + native ; +} +# keep setters in Views so that animations can still work. +# see http://proguard.sourceforge.net/manual/examples.html#beans +-keepclassmembers public class * extends android.view.View { + void set*(***); + *** get*(); +} +# We want to keep methods in Activity that could be used in the XML attribute onClick +-keepclassmembers class * extends android.app.Activity { + public void *(android.view.View); +} +# For enumeration classes, see http://proguard.sourceforge.net/manual/examples.html#enumerations +-keepclassmembers enum * { + public static **[] values(); + public static ** valueOf(java.lang.String); +} +-keepclassmembers class * implements android.os.Parcelable { + public static final ** CREATOR; +} + +# APP SPECIFIC OPTIONS + +# keep members of our model classes, they are used in json de/serialization +-keepclassmembers class com.h.pixeldroid.utils.api.objects.* { *; } + +-keep public enum com.h.pixeldroid.utils.api.objects.*$** { + **[] $VALUES; + public *; +} + +# preserve line numbers for crash reporting +-keepattributes SourceFile,LineNumberTable +-renamesourcefileattribute SourceFile + +# remove all logging from production apk +-assumenosideeffects class android.util.Log { + public static *** getStackTraceString(...); + public static *** d(...); + public static *** w(...); + public static *** v(...); + public static *** i(...); +} +-assumenosideeffects class java.lang.String { + public static java.lang.String format(...); +} + +# remove some kotlin overhead +-assumenosideeffects class kotlin.jvm.internal.Intrinsics { + static void checkParameterIsNotNull(java.lang.Object, java.lang.String); + static void checkExpressionValueIsNotNull(java.lang.Object, java.lang.String); + static void throwUninitializedPropertyAccessException(java.lang.String); +} \ No newline at end of file diff --git a/build.gradle b/build.gradle index 1b6312c6..efd6d745 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:4.1.1' + classpath 'com.android.tools.build:gradle:4.1.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // NOTE: Do not place your application dependencies here; they belong