From 8c219bd69237c486ce79e024d54e3da715bc2366 Mon Sep 17 00:00:00 2001 From: Kevin Li Date: Mon, 16 Aug 2021 19:17:08 +0800 Subject: [PATCH 1/2] Android 12 compartibility fixes. --- app/build.gradle | 6 +++++- app/src/main/AndroidManifest.xml | 7 +++++-- .../mapboxsdk/plugins/testapp/PluginApplication.kt | 10 ++-------- gradle/dependencies.gradle | 11 +++++++---- .../offline/offline/OfflineDownloadStateReceiver.java | 7 ++++++- .../plugins/offline/utils/NotificationUtils.java | 7 +++++-- plugin-scalebar/build.gradle | 2 ++ 7 files changed, 32 insertions(+), 18 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 7992706c0..0f9bd1292 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -12,6 +12,7 @@ android { applicationId "com.mapbox.mapboxsdk.plugins.testapp" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true + multiDexEnabled = true } buildTypes { @@ -64,12 +65,15 @@ dependencies { exclude group: 'android.arch.lifecycle' exclude group: 'com.google.android.gms' }) - implementation dependenciesList.mapboxGeocoding + implementation (dependenciesList.mapboxGeocoding, { + exclude group: 'com.squareup.okhttp3' + }) implementation dependenciesList.mapboxTurf // Architecture implementation dependenciesList.lifecycleExtensions implementation dependenciesList.roomRuntime + implementation dependenciesList.androidxMultidex kapt dependenciesList.roomCompiler // Google Play Services diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index ad9056ac3..1ec2d39df 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -3,6 +3,7 @@ xmlns:tools="http://schemas.android.com/tools" package="com.mapbox.mapboxsdk.plugins.testapp"> + - + @@ -276,7 +278,8 @@ android:name="com.mapbox.mapboxsdk.plugins.offline.offline.OfflineDownloadService" android:exported="false"/> - + diff --git a/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/PluginApplication.kt b/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/PluginApplication.kt index d3bd2c3fa..8e6b76127 100644 --- a/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/PluginApplication.kt +++ b/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/PluginApplication.kt @@ -1,21 +1,15 @@ package com.mapbox.mapboxsdk.plugins.testapp -import android.app.Application +import androidx.multidex.MultiDexApplication import com.mapbox.mapboxsdk.Mapbox -import com.squareup.leakcanary.LeakCanary import timber.log.Timber -class PluginApplication : Application() { +class PluginApplication : MultiDexApplication() { override fun onCreate() { super.onCreate() - if (LeakCanary.isInAnalyzerProcess(this)) { - return - } - - LeakCanary.install(this) initializeLogger() Mapbox.getInstance(this, getString(R.string.mapbox_access_token)) } diff --git a/gradle/dependencies.gradle b/gradle/dependencies.gradle index 2d6817645..e06204e25 100644 --- a/gradle/dependencies.gradle +++ b/gradle/dependencies.gradle @@ -7,7 +7,7 @@ ] version = [ - mapboxMapSdk : '9.6.0', + mapboxMapSdk : '9.6.2', mapboxJava : '5.5.0', mapboxTurf : '5.5.0', playLocation : '16.0.0', @@ -18,7 +18,7 @@ constraintLayout : '1.1.2', mockito : '2.23.4', mockk : '1.9.3', - leakCanary : '1.6.3', + leakCanary : '2.7', timber : '4.7.1', testRunner : '1.0.2', espresso : '3.0.2', @@ -27,7 +27,9 @@ lifecycleLiveData : '1.1.1', room : '1.1.0', androidArchCore : '1.1.0', - robolectric : '3.8' + robolectric : '3.8', + androidXCore : '1.5.0', + androidxMultidex : '2.0.1' ] pluginVersion = [ @@ -56,6 +58,7 @@ autoValuesParcelAdapter: "com.ryanharter.auto.value:auto-value-parcel-adapter:${version.autoValueParcel}", // support + androidCore : "androidx.core:core:${version.androidXCore}", supportAnnotation : 'androidx.annotation:annotation:1.0.0', supportAppcompatV7 : 'androidx.appcompat:appcompat:1.0.0', supportV4 : 'androidx.legacy:legacy-support-v4:1.0.0', @@ -69,7 +72,7 @@ lifecycleCompiler : "android.arch.lifecycle:compiler:${version.lifecycleCompiler}", roomRuntime : 'androidx.room:room-runtime:2.0.0', roomCompiler : 'androidx.room:room-compiler:2.0.0', - + androidxMultidex : "androidx.multidex:multidex:${version.androidxMultidex}", // square crew timber : "com.jakewharton.timber:timber:${version.timber}", leakCanaryDebug : "com.squareup.leakcanary:leakcanary-android:${version.leakCanary}", diff --git a/plugin-offline/src/main/java/com/mapbox/mapboxsdk/plugins/offline/offline/OfflineDownloadStateReceiver.java b/plugin-offline/src/main/java/com/mapbox/mapboxsdk/plugins/offline/offline/OfflineDownloadStateReceiver.java index b641bd11d..8aaa7ee47 100644 --- a/plugin-offline/src/main/java/com/mapbox/mapboxsdk/plugins/offline/offline/OfflineDownloadStateReceiver.java +++ b/plugin-offline/src/main/java/com/mapbox/mapboxsdk/plugins/offline/offline/OfflineDownloadStateReceiver.java @@ -4,6 +4,7 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; +import android.os.Build; import com.mapbox.mapboxsdk.plugins.offline.model.OfflineDownloadOptions; @@ -90,6 +91,10 @@ static Intent createCancelIntent(Context context, OfflineDownloadOptions offline } static PendingIntent createNotificationIntent(Context context, OfflineDownloadOptions offlineDownload) { + int flags = PendingIntent.FLAG_UPDATE_CURRENT; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + flags |= PendingIntent.FLAG_IMMUTABLE; + } Class returnActivity = offlineDownload.notificationOptions().getReturnActivity(); Intent notificationIntent = new Intent(context, returnActivity); notificationIntent.putExtra(KEY_BUNDLE, offlineDownload); @@ -97,7 +102,7 @@ static PendingIntent createNotificationIntent(Context context, OfflineDownloadOp context, 0, notificationIntent, - PendingIntent.FLAG_UPDATE_CURRENT + flags ); } } diff --git a/plugin-offline/src/main/java/com/mapbox/mapboxsdk/plugins/offline/utils/NotificationUtils.java b/plugin-offline/src/main/java/com/mapbox/mapboxsdk/plugins/offline/utils/NotificationUtils.java index df3519d51..d998d2c64 100644 --- a/plugin-offline/src/main/java/com/mapbox/mapboxsdk/plugins/offline/utils/NotificationUtils.java +++ b/plugin-offline/src/main/java/com/mapbox/mapboxsdk/plugins/offline/utils/NotificationUtils.java @@ -42,6 +42,10 @@ public static NotificationCompat.Builder toNotificationBuilder(Context context, PendingIntent contentIntent, NotificationOptions options, Intent cancelIntent) { + int flags = PendingIntent.FLAG_CANCEL_CURRENT; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + flags |= PendingIntent.FLAG_IMMUTABLE; + } return new NotificationCompat.Builder(context, OfflineConstants.NOTIFICATION_CHANNEL) .setContentTitle(options.contentTitle()) .setContentText(options.contentText()) @@ -51,7 +55,6 @@ public static NotificationCompat.Builder toNotificationBuilder(Context context, .setContentIntent(contentIntent) .addAction(Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP ? 0 : R.drawable.ic_cancel, options.cancelText(), - PendingIntent.getService(context, offlineDownload.uuid().intValue(), cancelIntent, - PendingIntent.FLAG_CANCEL_CURRENT)); + PendingIntent.getService(context, offlineDownload.uuid().intValue(), cancelIntent, flags)); } } \ No newline at end of file diff --git a/plugin-scalebar/build.gradle b/plugin-scalebar/build.gradle index dd454b29f..0e00035ce 100644 --- a/plugin-scalebar/build.gradle +++ b/plugin-scalebar/build.gradle @@ -25,6 +25,8 @@ android { dependencies { implementation dependenciesList.mapboxMapSdk + implementation dependenciesList.supportAnnotation + implementation dependenciesList.androidCore javadocDeps dependenciesList.mapboxMapSdk testImplementation dependenciesList.kotlin testImplementation dependenciesList.mockk From aa30a7b4b85d812519c7f20b03d7b4894ea25ddf Mon Sep 17 00:00:00 2001 From: Kevin Li Date: Mon, 16 Aug 2021 19:39:46 +0800 Subject: [PATCH 2/2] Update leakCanary dependency. --- app/build.gradle | 15 --------------- gradle/dependencies.gradle | 2 -- 2 files changed, 17 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 0f9bd1292..305e9949d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -43,19 +43,6 @@ android { } } -// Disable Leak Canary for UI and unit test. -configurations.all { config -> - if (config.name.contains('UnitTest') || config.name.contains('AndroidTest')) { - config.resolutionStrategy.eachDependency { details -> - if (details.requested.group == 'com.squareup.leakcanary' - && details.requested.name == 'leakcanary-android') { - details.useTarget(group: details.requested.group, name: 'leakcanary-android-no-op', - version: details.requested.version) - } - } - } -} - dependencies { // Kotlin implementation dependenciesList.kotlin @@ -107,8 +94,6 @@ dependencies { // Leak canary debugImplementation dependenciesList.leakCanaryDebug - releaseImplementation dependenciesList.leakCanaryRelease - testImplementation dependenciesList.leakCanaryTest // Plugin modules implementation project(':plugin-traffic') diff --git a/gradle/dependencies.gradle b/gradle/dependencies.gradle index e06204e25..905498742 100644 --- a/gradle/dependencies.gradle +++ b/gradle/dependencies.gradle @@ -76,8 +76,6 @@ // square crew timber : "com.jakewharton.timber:timber:${version.timber}", leakCanaryDebug : "com.squareup.leakcanary:leakcanary-android:${version.leakCanary}", - leakCanaryRelease : "com.squareup.leakcanary:leakcanary-android-no-op:${version.leakCanary}", - leakCanaryTest : "com.squareup.leakcanary:leakcanary-android-no-op:${version.leakCanary}", // instrumentation test testRunner : 'androidx.test.ext:junit:1.1.1',