Skip to content

Commit 17379d2

Browse files
author
Kevin Li
authored
Android 12 compartibility fixes. (#1194)
* Android 12 compartibility fixes. * Update leakCanary dependency.
1 parent 8b7e932 commit 17379d2

File tree

7 files changed

+32
-35
lines changed

7 files changed

+32
-35
lines changed

app/build.gradle

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ android {
1212
applicationId "com.mapbox.mapboxsdk.plugins.testapp"
1313
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1414
vectorDrawables.useSupportLibrary = true
15+
multiDexEnabled = true
1516
}
1617

1718
buildTypes {
@@ -42,19 +43,6 @@ android {
4243
}
4344
}
4445

45-
// Disable Leak Canary for UI and unit test.
46-
configurations.all { config ->
47-
if (config.name.contains('UnitTest') || config.name.contains('AndroidTest')) {
48-
config.resolutionStrategy.eachDependency { details ->
49-
if (details.requested.group == 'com.squareup.leakcanary'
50-
&& details.requested.name == 'leakcanary-android') {
51-
details.useTarget(group: details.requested.group, name: 'leakcanary-android-no-op',
52-
version: details.requested.version)
53-
}
54-
}
55-
}
56-
}
57-
5846
dependencies {
5947
// Kotlin
6048
implementation dependenciesList.kotlin
@@ -64,12 +52,15 @@ dependencies {
6452
exclude group: 'android.arch.lifecycle'
6553
exclude group: 'com.google.android.gms'
6654
})
67-
implementation dependenciesList.mapboxGeocoding
55+
implementation (dependenciesList.mapboxGeocoding, {
56+
exclude group: 'com.squareup.okhttp3'
57+
})
6858
implementation dependenciesList.mapboxTurf
6959

7060
// Architecture
7161
implementation dependenciesList.lifecycleExtensions
7262
implementation dependenciesList.roomRuntime
63+
implementation dependenciesList.androidxMultidex
7364
kapt dependenciesList.roomCompiler
7465

7566
// Google Play Services
@@ -103,8 +94,6 @@ dependencies {
10394

10495
// Leak canary
10596
debugImplementation dependenciesList.leakCanaryDebug
106-
releaseImplementation dependenciesList.leakCanaryRelease
107-
testImplementation dependenciesList.leakCanaryTest
10897

10998
// Plugin modules
11099
implementation project(':plugin-traffic')

app/src/main/AndroidManifest.xml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
xmlns:tools="http://schemas.android.com/tools" package="com.mapbox.mapboxsdk.plugins.testapp">
44

55
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
6+
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
67
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
78

89
<application
@@ -14,7 +15,8 @@
1415
android:supportsRtl="true"
1516
android:theme="@style/AppTheme"
1617
tools:ignore="AllowBackup,GoogleAppIndexingWarning">
17-
<activity android:name=".activity.FeatureOverviewActivity">
18+
<activity android:name=".activity.FeatureOverviewActivity"
19+
android:exported="true">
1820
<intent-filter>
1921
<action android:name="android.intent.action.MAIN"/>
2022
<category android:name="android.intent.category.LAUNCHER"/>
@@ -276,7 +278,8 @@
276278
android:name="com.mapbox.mapboxsdk.plugins.offline.offline.OfflineDownloadService"
277279
android:exported="false"/>
278280

279-
<receiver android:name="com.mapbox.mapboxsdk.plugins.offline.offline.OfflineDownloadStateReceiver">
281+
<receiver android:name="com.mapbox.mapboxsdk.plugins.offline.offline.OfflineDownloadStateReceiver"
282+
android:exported="false">
280283
<intent-filter>
281284
<action android:name="com.mapbox.mapboxsdk.plugins.offline"/>
282285
</intent-filter>

app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/PluginApplication.kt

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
11
package com.mapbox.mapboxsdk.plugins.testapp
22

3-
import android.app.Application
3+
import androidx.multidex.MultiDexApplication
44

55
import com.mapbox.mapboxsdk.Mapbox
6-
import com.squareup.leakcanary.LeakCanary
76

87
import timber.log.Timber
98

10-
class PluginApplication : Application() {
9+
class PluginApplication : MultiDexApplication() {
1110

1211
override fun onCreate() {
1312
super.onCreate()
14-
if (LeakCanary.isInAnalyzerProcess(this)) {
15-
return
16-
}
17-
18-
LeakCanary.install(this)
1913
initializeLogger()
2014
Mapbox.getInstance(this, getString(R.string.mapbox_access_token))
2115
}

gradle/dependencies.gradle

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
]
88

99
version = [
10-
mapboxMapSdk : '9.6.0',
10+
mapboxMapSdk : '9.6.2',
1111
mapboxJava : '5.5.0',
1212
mapboxTurf : '5.5.0',
1313
playLocation : '16.0.0',
@@ -18,7 +18,7 @@
1818
constraintLayout : '1.1.2',
1919
mockito : '2.23.4',
2020
mockk : '1.9.3',
21-
leakCanary : '1.6.3',
21+
leakCanary : '2.7',
2222
timber : '4.7.1',
2323
testRunner : '1.0.2',
2424
espresso : '3.0.2',
@@ -27,7 +27,9 @@
2727
lifecycleLiveData : '1.1.1',
2828
room : '1.1.0',
2929
androidArchCore : '1.1.0',
30-
robolectric : '3.8'
30+
robolectric : '3.8',
31+
androidXCore : '1.5.0',
32+
androidxMultidex : '2.0.1'
3133
]
3234

3335
pluginVersion = [
@@ -56,6 +58,7 @@
5658
autoValuesParcelAdapter: "com.ryanharter.auto.value:auto-value-parcel-adapter:${version.autoValueParcel}",
5759

5860
// support
61+
androidCore : "androidx.core:core:${version.androidXCore}",
5962
supportAnnotation : 'androidx.annotation:annotation:1.0.0',
6063
supportAppcompatV7 : 'androidx.appcompat:appcompat:1.0.0',
6164
supportV4 : 'androidx.legacy:legacy-support-v4:1.0.0',
@@ -69,12 +72,10 @@
6972
lifecycleCompiler : "android.arch.lifecycle:compiler:${version.lifecycleCompiler}",
7073
roomRuntime : 'androidx.room:room-runtime:2.0.0',
7174
roomCompiler : 'androidx.room:room-compiler:2.0.0',
72-
75+
androidxMultidex : "androidx.multidex:multidex:${version.androidxMultidex}",
7376
// square crew
7477
timber : "com.jakewharton.timber:timber:${version.timber}",
7578
leakCanaryDebug : "com.squareup.leakcanary:leakcanary-android:${version.leakCanary}",
76-
leakCanaryRelease : "com.squareup.leakcanary:leakcanary-android-no-op:${version.leakCanary}",
77-
leakCanaryTest : "com.squareup.leakcanary:leakcanary-android-no-op:${version.leakCanary}",
7879

7980
// instrumentation test
8081
testRunner : 'androidx.test.ext:junit:1.1.1',

plugin-offline/src/main/java/com/mapbox/mapboxsdk/plugins/offline/offline/OfflineDownloadStateReceiver.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import android.content.BroadcastReceiver;
55
import android.content.Context;
66
import android.content.Intent;
7+
import android.os.Build;
78

89
import com.mapbox.mapboxsdk.plugins.offline.model.OfflineDownloadOptions;
910

@@ -90,14 +91,18 @@ static Intent createCancelIntent(Context context, OfflineDownloadOptions offline
9091
}
9192

9293
static PendingIntent createNotificationIntent(Context context, OfflineDownloadOptions offlineDownload) {
94+
int flags = PendingIntent.FLAG_UPDATE_CURRENT;
95+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
96+
flags |= PendingIntent.FLAG_IMMUTABLE;
97+
}
9398
Class returnActivity = offlineDownload.notificationOptions().getReturnActivity();
9499
Intent notificationIntent = new Intent(context, returnActivity);
95100
notificationIntent.putExtra(KEY_BUNDLE, offlineDownload);
96101
return PendingIntent.getActivity(
97102
context,
98103
0,
99104
notificationIntent,
100-
PendingIntent.FLAG_UPDATE_CURRENT
105+
flags
101106
);
102107
}
103108
}

plugin-offline/src/main/java/com/mapbox/mapboxsdk/plugins/offline/utils/NotificationUtils.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ public static NotificationCompat.Builder toNotificationBuilder(Context context,
4242
PendingIntent contentIntent,
4343
NotificationOptions options,
4444
Intent cancelIntent) {
45+
int flags = PendingIntent.FLAG_CANCEL_CURRENT;
46+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
47+
flags |= PendingIntent.FLAG_IMMUTABLE;
48+
}
4549
return new NotificationCompat.Builder(context, OfflineConstants.NOTIFICATION_CHANNEL)
4650
.setContentTitle(options.contentTitle())
4751
.setContentText(options.contentText())
@@ -51,7 +55,6 @@ public static NotificationCompat.Builder toNotificationBuilder(Context context,
5155
.setContentIntent(contentIntent)
5256
.addAction(Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP ? 0 : R.drawable.ic_cancel,
5357
options.cancelText(),
54-
PendingIntent.getService(context, offlineDownload.uuid().intValue(), cancelIntent,
55-
PendingIntent.FLAG_CANCEL_CURRENT));
58+
PendingIntent.getService(context, offlineDownload.uuid().intValue(), cancelIntent, flags));
5659
}
5760
}

plugin-scalebar/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ android {
2525

2626
dependencies {
2727
implementation dependenciesList.mapboxMapSdk
28+
implementation dependenciesList.supportAnnotation
29+
implementation dependenciesList.androidCore
2830
javadocDeps dependenciesList.mapboxMapSdk
2931
testImplementation dependenciesList.kotlin
3032
testImplementation dependenciesList.mockk

0 commit comments

Comments
 (0)