Skip to content

Commit

Permalink
reduce the SDK size (#54)
Browse files Browse the repository at this point in the history
* Remove material (1.5MB)

* remove unused imports

* upgrade coroutines

* Upgrade Kotlin from 1.5.x to 1.6.x

* correct kotlin version

* remove exloplayer extension-ima

* remove exloplayer exoplayer-dash

* upgrade libs

* migrate android gradle plugin from 7.0.4 to 7.2.1

* Remove core-ktx(0.1MB)

* remove unused libraries

* remove unused libraries

* Fix errors

* Fix errors

* Fix the build type for a testing lib

* Remove kotlin-stdlib-jdk8

* Remove old codes

* Replace jackson-binding(0.7mb) with gson(0.08mb)

* Remove appcompat
  • Loading branch information
SungjunApp authored Aug 17, 2022
1 parent 5984db7 commit 9bfcd4c
Show file tree
Hide file tree
Showing 23 changed files with 92 additions and 318 deletions.
9 changes: 5 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ android {
}
}
packagingOptions {
exclude 'META-INF/AL2.0'
exclude 'META-INF/LGPL2.1'
resources {
excludes += ['META-INF/AL2.0', 'META-INF/LGPL2.1']
}
}
}

Expand All @@ -68,7 +69,7 @@ dependencies {
*/

testImplementation 'org.json:json:20200518'
testImplementation "com.fasterxml.jackson.core:jackson-databind:$jackson"
testImplementation "com.google.code.gson:gson:$gson"
//testImplementation "com.fasterxml.jackson.module:jackson-module-kotlin:2.9.8"
testImplementation "com.squareup.okhttp3:mockwebserver:$okhttp3"

Expand All @@ -77,7 +78,7 @@ dependencies {

androidTestImplementation 'androidx.test.ext:junit:' + rootProject.extJUnitVersion
androidTestImplementation "androidx.test.ext:junit-ktx:" + rootProject.extJUnitVersion
androidTestImplementation "com.fasterxml.jackson.core:jackson-databind:$jackson"
androidTestImplementation "com.google.code.gson:gson:$gson"
androidTestImplementation 'androidx.test.espresso:espresso-contrib:' + rootProject.espressoVersion
androidTestImplementation "com.jakewharton.espresso:okhttp3-idling-resource:$jakeWhartonOkhttpOdlingResource"

Expand Down
20 changes: 11 additions & 9 deletions app/src/androidTest/java/com/pixlee/pixleeandroidsdk/HMACTest.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.pixlee.pixleeandroidsdk

import com.fasterxml.jackson.databind.ObjectMapper
import com.google.gson.Gson
import com.google.gson.JsonObject
import com.pixlee.pixleesdk.network.HMAC
import org.json.JSONException
import org.junit.Assert
Expand All @@ -15,14 +16,15 @@ class HMACTest {
@Test
@Throws(JSONException::class, InvalidKeyException::class, NoSuchAlgorithmException::class)
fun `test-HMAC-SHA1`() {
val text: String = ObjectMapper().createObjectNode().apply{
this.put("album_id", 12345)
this.put("title", "Testing Photo Upload")
this.put("approved", true)
this.put("email", "[email protected]")
this.put("username", "Submitter Person")
this.put("photo_uri", "https://example.com/test.jpg")
}.toString().replace("\\/", "/")
val text: String = Gson().toJson(JsonObject().apply {
addProperty("album_id", 12345)
addProperty("title", "Testing Photo Upload")
addProperty("approved", true)
addProperty("email", "[email protected]")
addProperty("username", "Submitter Person")
addProperty("photo_uri", "https://example.com/test.jpg")
}).replace("\\/", "/")

val test = HMAC.computeHmac(text, "ABCDEFG")
val targetResult = "epBvDlHbQho/rNDdQVJowWMtGsg="
Assert.assertEquals(targetResult, test)
Expand Down
24 changes: 13 additions & 11 deletions app/src/test/java/com/pixlee/pixleesdk/HMACTest.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.pixlee.pixleesdk

import com.fasterxml.jackson.databind.ObjectMapper
import com.google.gson.Gson
import com.google.gson.JsonObject
import com.pixlee.pixleesdk.network.HMAC
import org.json.JSONException
import org.junit.Assert
Expand All @@ -15,16 +16,17 @@ class HMACTest {
@Test
@Throws(JSONException::class, InvalidKeyException::class, NoSuchAlgorithmException::class)
fun testHMAC() {
val text: String = ObjectMapper().createObjectNode().apply{
this.put("album_id", 12345)
this.put("title", "Testing Photo Upload")
this.put("approved", true)
this.put("email", "[email protected]")
this.put("username", "Submitter Person")
this.put("photo_uri", "https://example.com/test.jpg")
}.toString().replace("\\/", "/")
val test = HMAC.computeHmac(text, "ABCDEFG")
val targetResult = "epBvDlHbQho/rNDdQVJowWMtGsg="
val text: String = Gson().toJson(JsonObject().apply {
addProperty("album_id", 12345)
addProperty("title", "Testing Photo Upload")
addProperty("approved", true)
addProperty("email", "[email protected]")
addProperty("username", "Submitter Person")
addProperty("photo_uri", "https://example.com/test.jpg")
}).replace("\\/", "/")

val test = HMAC.computeHmac(text, "ABCDEFG")
val targetResult = "epBvDlHbQho/rNDdQVJowWMtGsg="
Assert.assertEquals(targetResult, test)
}
}
12 changes: 6 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
buildscript {
ext.kotlin_version = '1.5.20'
ext.coroutines = "1.5.0"
ext.kotlin_version = '1.6.10'
ext.coroutines = "1.5.2"
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.4'
classpath 'com.android.tools.build:gradle:7.2.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand Down Expand Up @@ -44,8 +44,8 @@ ext {

jakeWhartonOkhttpOdlingResource = "1.0.0"

androidxAppcompat = "1.4.1"
androidxConstraint = "2.1.3"
androidxAppcompat = "1.4.2"
androidxConstraint = "2.1.4"
material = "1.5.0"

lifecycle = "2.4.0"
Expand All @@ -63,7 +63,7 @@ ext {
checkerframeworkVersion = '3.13.0'
exoPlayer="2.16.1"
supportLibraryVersion = '27.0.0'
jackson = '2.10.3'
gson = '2.9.1'
junit = '4.13.2'
androidxRunner = '1.4.0'
androidXrules = '1.4.0'
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip
26 changes: 9 additions & 17 deletions pixleesdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,35 +44,34 @@ android {
}
}
}

packagingOptions {
exclude 'META-INF/AL2.0'
exclude 'META-INF/LGPL2.1'
resources {
excludes += ['META-INF/AL2.0', 'META-INF/LGPL2.1']
}
}

}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"

implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutines"
implementation 'androidx.core:core-ktx:1.7.0'
testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutines"

/**
* testing
*/
testImplementation "junit:junit:$junit"
testImplementation 'org.json:json:20200518'
androidTestImplementation "com.fasterxml.jackson.core:jackson-databind:$jackson"
androidTestImplementation "com.google.code.gson:gson:$gson"
androidTestImplementation 'androidx.test.ext:junit-ktx:' + rootProject.extJUnitVersion
androidTestImplementation 'androidx.test.espresso:espresso-contrib:' + rootProject.espressoVersion
androidTestImplementation "com.jakewharton.espresso:okhttp3-idling-resource:$jakeWhartonOkhttpOdlingResource"

implementation "com.fasterxml.jackson.core:jackson-databind:$jackson"
implementation "com.google.code.gson:gson:$gson"

// implementation "androidx.appcompat:appcompat:$androidxAppcompat"

implementation "androidx.appcompat:appcompat:$androidxAppcompat"
implementation "com.google.android.material:material:$material"
/**
* Network
*/
Expand All @@ -93,9 +92,6 @@ dependencies {
* Glide(Image library)
*/
implementation "com.github.bumptech.glide:glide:$glide"
implementation "com.github.bumptech.glide:annotations:$glide"
implementation "com.github.bumptech.glide:okhttp3-integration:$glide"
kapt "com.github.bumptech.glide:compiler:$glide"

/**
* Glide Transformation
Expand All @@ -111,13 +107,9 @@ dependencies {

compileOnly "org.checkerframework:checker-qual:$checkerframeworkVersion"
implementation "com.google.android.exoplayer:exoplayer-core:$exoPlayer"
implementation "com.google.android.exoplayer:exoplayer-dash:$exoPlayer"
implementation "com.google.android.exoplayer:exoplayer-ui:$exoPlayer"
implementation "com.google.android.exoplayer:extension-ima:$exoPlayer"
implementation "com.google.android.exoplayer:extension-cronet:$exoPlayer"

implementation 'androidx.annotation:annotation:1.3.0'


implementation "androidx.recyclerview:recyclerview:1.2.1"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.pixlee.pixleesdk.network;

import android.os.Build;
import android.util.Log;

import com.orhanobut.logger.Logger;
Expand Down Expand Up @@ -116,18 +115,6 @@ public static synchronized OkHttpClient provideOkHttpClient() {
.readTimeout(timeout_read, TimeUnit.SECONDS)
.writeTimeout(timeout_write, TimeUnit.SECONDS);

// enable Tls12 on Pre Lollipop
try {
if (Build.VERSION.SDK_INT < 21) {
TLSSocketFactory tlsSocketFactory = new TLSSocketFactory();
if (tlsSocketFactory.getTrustManager() != null) {
ok.sslSocketFactory(tlsSocketFactory, tlsSocketFactory.getTrustManager());
}
}
} catch (Exception e) {
e.printStackTrace();
}

if (BuildConfig.DEBUG) {
HttpLoggingInterceptor logging = new HttpLoggingInterceptor(new HttpLoggingInterceptor.Logger() {
@Override
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
package com.pixlee.pixleesdk.network.adaptor;

import android.util.Log;

import androidx.annotation.NonNull;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.gson.Gson;
import com.pixlee.pixleesdk.network.annotation.FieldUploadedJson;
import com.squareup.moshi.FromJson;
import com.squareup.moshi.JsonReader;
import com.squareup.moshi.ToJson;

import org.json.JSONException;
import org.json.JSONObject;

public class UploadedJsonAdapter {
Expand All @@ -31,9 +26,7 @@ public JSONObject fromJson(@NonNull final JsonReader reader) throws Exception {
return reader.nextNull();
} else {
try {
ObjectMapper mapper = new ObjectMapper();
String data = mapper.writeValueAsString(reader.readJsonValue());
return new JSONObject(data);
return new JSONObject(new Gson().toJson(reader.readJsonValue()));
} catch (Exception e) {
e.printStackTrace();
}
Expand Down
Loading

0 comments on commit 9bfcd4c

Please sign in to comment.