From 6377dd2e2cf95e7ceb5b9364d6a2370d634061d6 Mon Sep 17 00:00:00 2001 From: Tung Vu <53031642+tung-vu-td@users.noreply.github.com> Date: Thu, 16 May 2024 18:59:43 +0700 Subject: [PATCH] Upgrade jackson 2.17.0 (#84) * Upgrade jackson to 2.17.0. Update CustomizedJSON code * Upgrade to gradle 8.6, AGP to 8.4 * Update circle ci android orb and image * Update sourceCompatibility to 1.8 * Use cimg/android for local test * Fix store test result script * Update mockito-android to 5.12.0 --- .circleci/config.yml | 35 +++++++----- build.gradle | 23 ++++++-- example/build.gradle | 18 +++--- example/src/main/AndroidManifest.xml | 7 ++- .../android/demo/MainActivity.java | 1 - gradle.properties | 4 ++ gradle/wrapper/gradle-wrapper.properties | 2 +- .../treasuredata/android/CustomizedJSON.java | 56 +++++++------------ test-host/build.gradle | 16 +++--- test-host/src/main/AndroidManifest.xml | 6 +- 10 files changed, 90 insertions(+), 78 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 40f6cca3..c4cb70e9 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,7 +3,7 @@ version: 2.1 orbs: - android: circleci/android@2.1.2 + android: circleci/android@2.5.0 _defaults: - &restore_gradle_cache @@ -44,17 +44,26 @@ commands: store_instrument_results: description: "Store instrument test results" steps: + - run: + name: Save test results + command: | + mkdir -p ~/test-results/junit/ + find . -type f -regex ".*/build/outputs/androidTest-results/.*xml" -exec cp {} ~/test-results/junit/ \; + when: always - store_test_results: - path: test-host/build/reports/androidTests/connected + path: ~/test-results - run: - name: Compress Report + name: Compress Instrument Test Report command: tar -cvf instrument-report.tar -C ./test-host/build/reports/androidTests/connected . - store_artifacts: path: instrument-report.tar destination: instrument-report.tar + - run: + name: Compress test-result.pb + command: tar -cvf pb-report.tar -C test-host/build/outputs/androidTest-results/connected . - store_artifacts: - path: test-host/build/outputs/androidTest-results/connected/test-result.pb - destination: test-result.pb + path: pb-report.tar + destination: pb-report.tar run_instrument_tests: description: "Run instrument tests" @@ -83,7 +92,7 @@ commands: jobs: local_tests: docker: - - image: circleci/android:api-30 + - image: cimg/android:2024.04.1 steps: - run_local_tests @@ -91,7 +100,7 @@ jobs: executor: name: android/android-machine resource-class: large - tag: "2023.09.1" + tag: "2024.04.1" steps: - run_instrument_tests: api_level: '34' @@ -100,7 +109,7 @@ jobs: executor: name: android/android-machine resource-class: large - tag: "2022.07.1" + tag: "2024.04.1" steps: - run_instrument_tests: api_level: '33' @@ -109,7 +118,7 @@ jobs: executor: name: android/android-machine resource-class: large - tag: "2022.07.1" + tag: "2024.04.1" steps: - run_instrument_tests: api_level: '32' @@ -118,7 +127,7 @@ jobs: executor: name: android/android-machine resource-class: large - tag: "2022.07.1" + tag: "2024.04.1" steps: - run_instrument_tests: api_level: '31' @@ -127,7 +136,7 @@ jobs: executor: name: android/android-machine resource-class: large - tag: "2022.07.1" + tag: "2024.04.1" steps: - run_instrument_tests: api_level: '30' @@ -136,7 +145,7 @@ jobs: executor: name: android/android-machine resource-class: large - tag: "2022.07.1" + tag: "2024.04.1" steps: - run_instrument_tests: api_level: '29' @@ -145,7 +154,7 @@ jobs: executor: name: android/android-machine resource-class: large - tag: "2022.07.1" + tag: "2024.04.1" steps: - checkout - android/start-emulator-and-run-tests: diff --git a/build.gradle b/build.gradle index d2df6a11..f1797fc5 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,15 @@ +buildscript { + repositories { + mavenCentral() + google() + } + dependencies { + classpath 'com.android.tools.build:gradle:8.4.0' + } +} + plugins { id 'java' -// id 'maven' id 'maven-publish' id 'signing' } @@ -8,7 +17,9 @@ plugins { group = 'com.treasuredata' version = '1.0.0' description = 'Android SDK for Treasure Data Cloud' -sourceCompatibility = '1.7' + +java.sourceCompatibility = JavaVersion.VERSION_1_8 +java.targetCompatibility = JavaVersion.VERSION_1_8 repositories { mavenCentral() @@ -18,14 +29,14 @@ repositories { dependencies { implementation 'org.komamitsu:android-logger-bridge:0.0.2' - implementation 'com.fasterxml.jackson.jr:jackson-jr-objects:2.6.3' + implementation 'com.fasterxml.jackson.jr:jackson-jr-objects:2.17.0' implementation 'com.treasuredata:keen-client-java-core:3.0.0' compileOnly 'com.google.android:android:4.1.1.4' - testImplementation 'com.google.android.gms:play-services-ads:17.1.1' - testImplementation 'junit:junit:4.12' - testImplementation 'org.mockito:mockito-core:1.8.5' +// testImplementation 'com.google.android.gms:play-services-ads:23.0.0' + testImplementation 'junit:junit:4.13.2' + testImplementation 'org.mockito:mockito-core:5.3.1' testImplementation 'com.squareup.okhttp3:mockwebserver:3.6.0' testImplementation 'com.google.android:android:4.1.1.4' } diff --git a/example/build.gradle b/example/build.gradle index 6b8b6868..3972e0be 100644 --- a/example/build.gradle +++ b/example/build.gradle @@ -1,22 +1,21 @@ buildscript { repositories { - jcenter() + mavenCentral() google() } dependencies { - classpath 'com.android.tools.build:gradle:7.2.2' + classpath 'com.android.tools.build:gradle:8.4.0' } } apply plugin: 'com.android.application' android { - compileSdkVersion 30 - defaultConfig { applicationId "com.treasuredata.android.demo" - minSdkVersion 14 - targetSdkVersion 30 + compileSdk 34 + minSdkVersion 21 + targetSdkVersion 34 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" @@ -28,6 +27,7 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' } } + namespace 'com.treasuredata.android.demo' } repositories { @@ -39,10 +39,10 @@ repositories { dependencies { implementation rootProject - implementation 'com.google.android.gms:play-services-ads:17.1.1' - implementation 'com.android.installreferrer:installreferrer:1.1' + implementation 'com.google.android.gms:play-services-ads:23.0.0' + implementation 'com.android.installreferrer:installreferrer:2.2' - testImplementation 'junit:junit:4.12' + testImplementation 'junit:junit:4.13.2' androidTestImplementation 'com.android.support.test:runner:1.0.2' } \ No newline at end of file diff --git a/example/src/main/AndroidManifest.xml b/example/src/main/AndroidManifest.xml index 26e2b223..c34eb8fb 100644 --- a/example/src/main/AndroidManifest.xml +++ b/example/src/main/AndroidManifest.xml @@ -1,6 +1,5 @@ - + @@ -20,6 +19,7 @@ android:banner="@drawable/banner"> @@ -32,6 +32,9 @@ + diff --git a/example/src/main/java/com/treasuredata/android/demo/MainActivity.java b/example/src/main/java/com/treasuredata/android/demo/MainActivity.java index 88886b94..80634c75 100644 --- a/example/src/main/java/com/treasuredata/android/demo/MainActivity.java +++ b/example/src/main/java/com/treasuredata/android/demo/MainActivity.java @@ -26,7 +26,6 @@ public class MainActivity extends Activity { private static final String TAG = MainActivity.class.getSimpleName(); private String eventTable = "event_table"; private String eventDatabase = "event_db"; - private String serverSideUploadTimestampColumn; private String recordUUIDColumn; private String aaidColumn; diff --git a/gradle.properties b/gradle.properties index 8b6e7346..675c7067 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,3 +13,7 @@ #Wed Feb 15 01:31:42 ICT 2023 android.useAndroidX=true android.enableJetifier=true +#android.disableAutomaticComponentCreation=true +android.defaults.buildfeatures.buildconfig=true +android.nonTransitiveRClass=false +android.nonFinalResIds=false diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 5fb3c495..9f23d7b8 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,6 +3,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip android.useAndroidX=true android.enableJetifier=true \ No newline at end of file diff --git a/src/main/java/com/treasuredata/android/CustomizedJSON.java b/src/main/java/com/treasuredata/android/CustomizedJSON.java index eecbfa27..765ed9c4 100644 --- a/src/main/java/com/treasuredata/android/CustomizedJSON.java +++ b/src/main/java/com/treasuredata/android/CustomizedJSON.java @@ -4,7 +4,7 @@ import com.fasterxml.jackson.core.TreeCodec; import com.fasterxml.jackson.jr.ob.JSON; import com.fasterxml.jackson.jr.ob.impl.JSONWriter; -import com.fasterxml.jackson.jr.ob.impl.TypeDetector; +import com.fasterxml.jackson.jr.ob.impl.ValueWriterLocator; import java.io.IOException; import java.text.SimpleDateFormat; @@ -14,16 +14,19 @@ public class CustomizedJSON extends JSON { private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); private static class CustomizedJSONWriter extends JSONWriter { - public CustomizedJSONWriter(int features, TypeDetector td, TreeCodec tc) { - super(features, td, tc); + public CustomizedJSONWriter() + { + super(); } - public CustomizedJSONWriter(CustomizedJSONWriter customizedJSONWriter, JsonGenerator jg) + protected CustomizedJSONWriter(CustomizedJSONWriter base, int features, + ValueWriterLocator loc, TreeCodec tc, + JsonGenerator g) { - super(customizedJSONWriter, jg); + super(base, features, loc, tc, g); } - private String getFormatedDate(Date date) { + private String getFormattedDate(Date date) { String dateStr; synchronized (SimpleDateFormat.class) { dateStr = DATE_FORMAT.format(date); @@ -31,48 +34,29 @@ private String getFormatedDate(Date date) { return dateStr; } - // Workaround of https://github.com/FasterXML/jackson-jr/pull/31 - // Let's remove this override after it's merged. - @Override - public void writeField(String fieldName, Object value) throws IOException { - if (value == null) { - super.writeField(fieldName, null); - return; - } - - int type = _typeDetector.findFullType(value.getClass()); - switch (type) { - case TypeDetector.SER_UUID: - case TypeDetector.SER_URL: - case TypeDetector.SER_URI: - writeStringLikeField(fieldName, value.toString(), type); - return; + public JSONWriter perOperationInstance(int features, + ValueWriterLocator loc, TreeCodec tc, + JsonGenerator g) + { + if (getClass() != CustomizedJSONWriter.class) { // sanity check + throw new IllegalStateException("Sub-classes MUST override perOperationInstance(...)"); } - super.writeField(fieldName, value); + return new CustomizedJSONWriter(this, features, loc, tc, g); } @Override protected void writeDateValue(Date v) throws IOException { - writeStringValue(getFormatedDate(v)); + writeStringValue(getFormattedDate(v)); } @Override protected void writeDateField(String fieldName, Date v) throws IOException { - writeStringField(fieldName, getFormatedDate(v)); - } - - @Override - public JSONWriter perOperationInstance(JsonGenerator jg) - { - if (getClass() != CustomizedJSONWriter.class) { // sanity check - throw new IllegalStateException("Sub-classes MUST override perOperationInstance(...)"); - } - return new CustomizedJSONWriter(this, jg); + writeStringField(fieldName, getFormattedDate(v)); } } @Override - protected JSONWriter _defaultWriter(int features, TreeCodec tc) { - return new CustomizedJSONWriter(features, TypeDetector.forWriter(features), tc); + protected JSONWriter _defaultWriter() { + return new CustomizedJSONWriter(); } } diff --git a/test-host/build.gradle b/test-host/build.gradle index 8deee030..0ec12245 100644 --- a/test-host/build.gradle +++ b/test-host/build.gradle @@ -1,21 +1,21 @@ buildscript { repositories { - jcenter() + mavenCentral() google() } dependencies { - classpath 'com.android.tools.build:gradle:7.2.2' + classpath 'com.android.tools.build:gradle:8.4.0' } } apply plugin: 'com.android.application' android { - compileSdkVersion 30 defaultConfig { applicationId "com.treasuredata.android.test" - minSdkVersion 16 - targetSdkVersion 30 + compileSdk 34 + minSdkVersion 21 + targetSdkVersion 34 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" @@ -26,6 +26,7 @@ android { proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } + namespace 'com.treasuredata.android.test' } repositories { @@ -41,13 +42,12 @@ dependencies { implementation 'androidx.appcompat:appcompat:1.2.0' -// implementation 'com.google.android.gms:play-services-ads:17.1.1' - implementation 'com.google.android.gms:play-services-ads:20.0.0' + implementation 'com.google.android.gms:play-services-ads:23.0.0' implementation 'com.treasuredata:keen-client-java-core:3.0.0' androidTestImplementation 'junit:junit:4.12' - androidTestImplementation 'org.mockito:mockito-android:2.28.2' + androidTestImplementation 'org.mockito:mockito-android:5.12.0' androidTestImplementation "androidx.test:runner:1.5.2" androidTestImplementation "androidx.test.espresso:espresso-core:3.5.1" } diff --git a/test-host/src/main/AndroidManifest.xml b/test-host/src/main/AndroidManifest.xml index cb32fd3b..b83d1241 100644 --- a/test-host/src/main/AndroidManifest.xml +++ b/test-host/src/main/AndroidManifest.xml @@ -1,5 +1,4 @@ - + @@ -12,5 +11,8 @@ +