Skip to content

Commit

Permalink
Add proguard rule
Browse files Browse the repository at this point in the history
  • Loading branch information
a1573595 committed May 8, 2021
1 parent 847661f commit 629d421
Show file tree
Hide file tree
Showing 11 changed files with 113 additions and 3 deletions.
12 changes: 9 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,19 @@ android {
targetSdkVersion 30
versionCode 1
versionName "1.0"

proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'),
'proguard-gson.pro', 'proguard-rules.pro', 'proguard-sqlite.pro',
'proguard-okhttp.pro', 'proguard-retrofit2.pro'

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

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

Expand All @@ -35,7 +41,7 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.recyclerview:recyclerview:1.2.0'
implementation 'com.google.android.material:material:1.4.0-alpha02'
implementation 'com.google.android.material:material:1.4.0-beta01'

implementation 'com.google.android.gms:play-services-maps:17.0.1'
implementation 'com.google.android.gms:play-services-location:18.0.0'
Expand Down
25 changes: 25 additions & 0 deletions app/proguard-gson.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# 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
-keepclassmembers class com.alfred.model.** { *; }

# 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>;
}
2 changes: 2 additions & 0 deletions app/proguard-sqlite.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-keep,includedescriptorclasses class net.sqlcipher.** { *; }
-keep,includedescriptorclasses interface net.sqlcipher.** { *; }
11 changes: 11 additions & 0 deletions app/proguard-square-okhttp.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# JSR 305 annotations are for embedding nullability information.
-dontwarn javax.annotation.**

# A resource is loaded with a relative path so the package of this class must be preserved.
-keepnames class okhttp3.internal.publicsuffix.PublicSuffixDatabase

# Animal Sniffer compileOnly dependency to ensure APIs are compatible with older versions of Java.
-dontwarn org.codehaus.mojo.animal_sniffer.*

# OkHttp platform used only on JVM and when Conscrypt dependency is available.
-dontwarn okhttp3.internal.platform.ConscryptPlatform
29 changes: 29 additions & 0 deletions app/proguard-square-retrofit2.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Retrofit does reflection on generic parameters. InnerClasses is required to use Signature and
# EnclosingMethod is required to use InnerClasses.
-keepattributes Signature, InnerClasses, EnclosingMethod

# Retrofit does reflection on method and parameter annotations.
-keepattributes RuntimeVisibleAnnotations, RuntimeVisibleParameterAnnotations

# Retain service method parameters when optimizing.
-keepclassmembers,allowshrinking,allowobfuscation interface * {
@retrofit2.http.* <methods>;
}

# Ignore annotation used for build tooling.
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement

# Ignore JSR 305 annotations for embedding nullability information.
-dontwarn javax.annotation.**

# Guarded by a NoClassDefFoundError try/catch and only used when on the classpath.
-dontwarn kotlin.Unit

# Top-level functions that can only be used by Kotlin.
-dontwarn retrofit2.KotlinExtensions
-dontwarn retrofit2.KotlinExtensions$*

# With R8 full mode, it sees no subtypes of Retrofit interfaces since they are created with a Proxy
# and replaces all potential values with null. Explicitly keeping the interfaces prevents this.
-if interface * { @retrofit2.http.* <methods>; }
-keep,allowobfuscation interface <1>
10 changes: 10 additions & 0 deletions app/src/main/java/com/a1573595/parkingdemo/main/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@ public void onError(Throwable e) {
};
}

@Override
public void showDownloadFailed() {
binding.tvDataset.setText(R.string.download_failed);
}

@Override
public void showDataConversionFailed() {
binding.tvDataset.setText(R.string.download_failed);
}

private String convertLongToTime(long time) {
Date date = new Date(time);
SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss", Locale.getDefault());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,13 @@ public void onSuccess(@NotNull ResponseBody responseBody) {

deleteDataSet(parkingList);
} catch (Exception ignored) {
view.showDataConversionFailed();
}
}

@Override
public void onError(@NotNull Throwable e) {
view.showDownloadFailed();
}
}));
}
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/com/a1573595/parkingdemo/main/MainView.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ public interface MainView extends BaseView {
void transitionToUpdate();

DisposableSingleObserver<Parking[]> showDataSetInfo();

void showDownloadFailed();

void showDataConversionFailed();
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,43 @@
package com.a1573595.parkingdemo.model.data;

import com.google.gson.annotations.SerializedName;

public class TCMSV_ALLDESC {
@SerializedName("data")
public Data data;

public class Data {
public String UPDATETIME;
@SerializedName("park")
public Result[] park;

public class Result {
@SerializedName("id")
public String id;
@SerializedName("area")
public String area; //
@SerializedName("name")
public String name; //
@SerializedName("summary")
public String summary; //
@SerializedName("address")
public String address; //
@SerializedName("tel")
public String tel; //
@SerializedName("payex")
public String payex; //
public String servicetime; // 營業時間
@SerializedName("tw97x")
public double tw97x; //
@SerializedName("tw97y")
public double tw97y; //
@SerializedName("totalcar")
public int totalcar; //轎車停車位
@SerializedName("totalmotor")
public int totalmotor; //機車停車位
@SerializedName("totalbike")
public int totalbike; //自行車停車位
@SerializedName("totalbus")
public int totalbus; //巴士停車位
public String Pregnancy_First; //孕婦優先車位
public String Handicap_First; //身障優先車位
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-zh-rTW/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@
<string name="update_finish">更新完成</string>
<string name="query_hint">請輸入地址</string>
<string name="press_again_to_exit">再按一次退出</string>
<string name="download_failed">下載失敗</string>
<string name="data_conversion_failed">資料轉換失敗</string>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@
<string name="update_finish">Update finish</string>
<string name="query_hint">Enter address</string>
<string name="press_again_to_exit">Press again to exit</string>
<string name="download_failed">download failed.</string>
<string name="data_conversion_failed">Data conversion failed.</string>
</resources>

0 comments on commit 629d421

Please sign in to comment.