From c8f2a8cd7191c3f816bc01a802b39ce898be9a0d Mon Sep 17 00:00:00 2001 From: Allen Date: Tue, 13 Sep 2022 18:50:58 +0800 Subject: [PATCH 1/7] ref smileapi/awesome-smile#974 --- README.md | 2 +- android-webview/app/build.gradle | 5 +- android-webview/app/proguard-project.txt | 89 +++++++++++++++++++ .../app/src/main/assets/smile.html | 2 +- .../com/smile/android/SmileWebActivity.kt | 2 +- android-webview/build.gradle | 1 + android-webview/gradlew | 2 +- frontend/index.html | 3 +- .../android/app/src/main/assets/index.html | 2 +- react-native/index.html | 2 +- 10 files changed, 100 insertions(+), 10 deletions(-) create mode 100644 android-webview/app/proguard-project.txt diff --git a/README.md b/README.md index 8d61e6c..8aedebd 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ Below steps are also included in the README.md document included in the the Quic > For example, in Mac or Linux machines open up the Terminal, you can use vi and enter the following commands as a Super User: ```bash -sudo touch .env +sudo touch ..env ``` > On Windows machines, Windows will not allow you to create a .env file directly from Windows Explorer since it will not allow file names starting with a ".". To get around this: diff --git a/android-webview/app/build.gradle b/android-webview/app/build.gradle index dbbba65..c0013c4 100644 --- a/android-webview/app/build.gradle +++ b/android-webview/app/build.gradle @@ -18,8 +18,9 @@ android { buildTypes { release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + minifyEnabled true + shrinkResources true + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-project.txt' } } compileOptions { diff --git a/android-webview/app/proguard-project.txt b/android-webview/app/proguard-project.txt new file mode 100644 index 0000000..f7518f5 --- /dev/null +++ b/android-webview/app/proguard-project.txt @@ -0,0 +1,89 @@ +# 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 + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +-keepclassmembers class com.smile.android.SmileWebActivity { + public *; +} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile + +-keep public enum com.bumptech.glide.load.ImageHeaderParser$** { + **[] $VALUES; + public *; +} + + +# 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 + +# Keep annotation default values (e.g., retrofit2.http.Field.encoded). +-keepattributes AnnotationDefault + +# Retain service method parameters when optimizing. +-keepclassmembers,allowshrinking,allowobfuscation interface * { + @retrofit2.http.* ; +} + +# 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.* ; } +-keep,allowobfuscation interface <1> + + + +# With R8 full mode generic signatures are stripped for classes that are not +# kept. Suspend functions are wrapped in continuations where the type argument +# is used. +-keep,allowobfuscation,allowshrinking class kotlin.coroutines.Continuation + + +# okhttp +# 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 and other security providers are available. +-dontwarn okhttp3.internal.platform.** +-dontwarn org.conscrypt.** +-dontwarn org.bouncycastle.** +-dontwarn org.openjsse.** + +-keepattributes *Annotation* + + + diff --git a/android-webview/app/src/main/assets/smile.html b/android-webview/app/src/main/assets/smile.html index 14c1337..0baa66f 100644 --- a/android-webview/app/src/main/assets/smile.html +++ b/android-webview/app/src/main/assets/smile.html @@ -28,7 +28,7 @@ return null; } - const initData = JSON.parse(getInitParamJsonString()); + const data = JSON.parse(getInitParamJsonString()); const smileLinkModal = new SmileLinkModal({ /** * The Link API Host, Sandbox and Production mode are using different API hosts. diff --git a/android-webview/app/src/main/java/com/smile/android/SmileWebActivity.kt b/android-webview/app/src/main/java/com/smile/android/SmileWebActivity.kt index 2d8f967..9cb3609 100644 --- a/android-webview/app/src/main/java/com/smile/android/SmileWebActivity.kt +++ b/android-webview/app/src/main/java/com/smile/android/SmileWebActivity.kt @@ -80,7 +80,7 @@ class SmileWebActivity : AppCompatActivity(), SmileBridgeInterface { */ topProviders = model.topProviders) Log.d("initParam",Gson().toJson(jsModel)) - runOnUiThread {wv.loadUrl("file:///android_asset/smile.html?initParam=${Gson().toJson(jsModel)}")} + runOnUiThread {wv.loadUrl("file:///android_asset/smile.html?initParam=${Gson().toJson(jsModel).trim()}")} } catch (e: Exception) { Log.e("try exception", e.message.toString()) } diff --git a/android-webview/build.gradle b/android-webview/build.gradle index 0103ca0..1671c52 100644 --- a/android-webview/build.gradle +++ b/android-webview/build.gradle @@ -7,6 +7,7 @@ buildscript { dependencies { classpath "com.android.tools.build:gradle:7.0.2" classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10' + classpath 'com.guardsquare:proguard-gradle:7.2.1' // The ProGuard Gradle plugin. } } diff --git a/android-webview/gradlew b/android-webview/gradlew index 4f906e0..b9a336b 100644 --- a/android-webview/gradlew +++ b/android-webview/gradlew @@ -1,4 +1,4 @@ -#!/usr/bin/env sh +#!/usr/bin/.env sh # # Copyright 2015 the original author or authors. diff --git a/frontend/index.html b/frontend/index.html index 21099b6..bea8160 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -14,13 +14,12 @@ + +