From 8b606e91b053652cd8589cd465a99e337063bbcf Mon Sep 17 00:00:00 2001 From: Priyank Patel Date: Tue, 18 Feb 2020 13:24:30 -0500 Subject: [PATCH] feat(android): Enable AndroidX and use AndroidX dependencies (#2045) --- .circleci/config.yml | 2 +- android-template/app/build.gradle | 8 ++++---- .../app/src/main/AndroidManifest.xml | 2 +- .../app/src/main/res/layout/activity_main.xml | 4 ++-- android-template/gradle.properties | 4 ++++ android/capacitor/build.gradle | 14 ++++++------- .../java/com/getcapacitor/BridgeActivity.java | 4 +++- .../main/java/com/getcapacitor/Dialogs.java | 4 ++-- .../main/java/com/getcapacitor/Plugin.java | 6 ++++-- .../java/com/getcapacitor/plugin/Browser.java | 12 ++++++----- .../java/com/getcapacitor/plugin/Camera.java | 4 +++- .../java/com/getcapacitor/plugin/Modals.java | 20 +------------------ .../com/getcapacitor/plugin/Permissions.java | 5 +++-- .../plugin/PushNotifications.java | 4 ++-- .../java/com/getcapacitor/plugin/Share.java | 3 ++- .../plugin/background/BackgroundTask.java | 4 ++-- .../background/BackgroundTaskService.java | 4 +++- .../plugin/camera/CameraUtils.java | 3 ++- .../LocalNotificationManager.java | 14 ++++++++----- .../getcapacitor/plugin/util/AssetUtil.java | 4 +++- .../ui/ModalsBottomSheetDialogFragment.java | 11 ++++++---- .../main/res/layout/bridge_layout_main.xml | 4 ++-- android/gradle.properties | 4 ++++ .../app/src/main/res/layout/activity_main.xml | 4 ++-- example/android/gradle.properties | 4 ++++ plugin-template/android/gradle.properties | 4 ++++ .../main/res/layout/bridge_layout_main.xml | 4 ++-- 27 files changed, 90 insertions(+), 70 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 31cacf956..e5c091c58 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -47,7 +47,7 @@ jobs: steps: - checkout - run: - command: ./gradlew clean build -b capacitor/build.gradle + command: ./gradlew clean build -b capacitor/build.gradle -Pandroid.useAndroidX=true -Pandroid.enableJetifier=true working_directory: /tmp/workspace/android workflows: diff --git a/android-template/app/build.gradle b/android-template/app/build.gradle index d930d899c..3d25b4adc 100644 --- a/android-template/app/build.gradle +++ b/android-template/app/build.gradle @@ -8,7 +8,7 @@ android { targetSdkVersion 29 versionCode 1 versionName "1.0" - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { release { @@ -29,11 +29,11 @@ repositories { dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') - implementation 'com.android.support:appcompat-v7:28.0.0' + implementation 'androidx.appcompat:appcompat:1.0.0' implementation project(':capacitor-android') testImplementation 'junit:junit:4.12' - androidTestImplementation 'com.android.support.test:runner:1.0.2' - androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' + androidTestImplementation 'androidx.test.ext:junit:1.1.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0' implementation project(':capacitor-cordova-android-plugins') } diff --git a/android-template/app/src/main/AndroidManifest.xml b/android-template/app/src/main/AndroidManifest.xml index de4589027..9e28b68d4 100644 --- a/android-template/app/src/main/AndroidManifest.xml +++ b/android-template/app/src/main/AndroidManifest.xml @@ -32,7 +32,7 @@ diff --git a/android-template/app/src/main/res/layout/activity_main.xml b/android-template/app/src/main/res/layout/activity_main.xml index 03c6eedd9..b5ad13870 100644 --- a/android-template/app/src/main/res/layout/activity_main.xml +++ b/android-template/app/src/main/res/layout/activity_main.xml @@ -1,5 +1,5 @@ - - + diff --git a/android-template/gradle.properties b/android-template/gradle.properties index aac7c9b46..2dbcb0710 100644 --- a/android-template/gradle.properties +++ b/android-template/gradle.properties @@ -15,3 +15,7 @@ org.gradle.jvmargs=-Xmx1536m # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true + +# Supports AndroidX +android.useAndroidX=true +android.enableJetifier=true \ No newline at end of file diff --git a/android/capacitor/build.gradle b/android/capacitor/build.gradle index c7ac7b382..3710c0c0a 100644 --- a/android/capacitor/build.gradle +++ b/android/capacitor/build.gradle @@ -21,7 +21,7 @@ android { targetSdkVersion 29 versionCode 1 versionName "1.0" - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { release { @@ -42,15 +42,15 @@ repositories { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation 'com.android.support:appcompat-v7:28.0.0' - implementation 'com.android.support:support-compat:28.0.0' - implementation 'com.android.support:design:28.0.0' - implementation 'com.android.support:customtabs:28.0.0' + implementation 'androidx.appcompat:appcompat:1.0.0' + implementation 'androidx.core:core:1.2.0' + implementation 'com.google.android.material:material:1.1.0-rc02' + implementation 'androidx.browser:browser:1.2.0' implementation 'com.google.firebase:firebase-messaging:18.0.0' implementation 'com.google.android.gms:play-services-location:16.0.0' testImplementation 'junit:junit:4.12' - androidTestImplementation 'com.android.support.test:runner:1.0.2' - androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' + androidTestImplementation 'androidx.test.ext:junit:1.1.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0' implementation 'org.apache.cordova:framework:7.0.0' } diff --git a/android/capacitor/src/main/java/com/getcapacitor/BridgeActivity.java b/android/capacitor/src/main/java/com/getcapacitor/BridgeActivity.java index 2df2882ea..302326d18 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/BridgeActivity.java +++ b/android/capacitor/src/main/java/com/getcapacitor/BridgeActivity.java @@ -4,9 +4,11 @@ import android.content.Context; import android.content.Intent; import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; import android.util.Log; import android.webkit.WebView; + +import androidx.appcompat.app.AppCompatActivity; + import com.getcapacitor.android.R; import com.getcapacitor.cordova.MockCordovaInterfaceImpl; import com.getcapacitor.cordova.MockCordovaWebViewImpl; diff --git a/android/capacitor/src/main/java/com/getcapacitor/Dialogs.java b/android/capacitor/src/main/java/com/getcapacitor/Dialogs.java index 97bbf2e14..8022e7c68 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/Dialogs.java +++ b/android/capacitor/src/main/java/com/getcapacitor/Dialogs.java @@ -6,10 +6,10 @@ import android.content.DialogInterface; import android.os.Handler; import android.os.Looper; -import android.support.v4.app.ActivityCompat; -import android.support.v7.app.AppCompatActivity; import android.widget.EditText; +import androidx.appcompat.app.AppCompatActivity; + import com.getcapacitor.ui.ModalsBottomSheetDialogFragment; import org.json.JSONException; diff --git a/android/capacitor/src/main/java/com/getcapacitor/Plugin.java b/android/capacitor/src/main/java/com/getcapacitor/Plugin.java index 94e325b8e..76af8b86d 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/Plugin.java +++ b/android/capacitor/src/main/java/com/getcapacitor/Plugin.java @@ -6,9 +6,11 @@ import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.os.Bundle; -import android.support.v4.app.ActivityCompat; -import android.support.v7.app.AppCompatActivity; import android.util.Log; + +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.app.ActivityCompat; + import org.json.JSONException; import org.json.JSONObject; diff --git a/android/capacitor/src/main/java/com/getcapacitor/plugin/Browser.java b/android/capacitor/src/main/java/com/getcapacitor/plugin/Browser.java index d10698b6a..ceb8112f2 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/plugin/Browser.java +++ b/android/capacitor/src/main/java/com/getcapacitor/plugin/Browser.java @@ -5,12 +5,14 @@ import android.graphics.Color; import android.net.Uri; import android.os.Bundle; -import android.support.customtabs.CustomTabsCallback; -import android.support.customtabs.CustomTabsClient; -import android.support.customtabs.CustomTabsIntent; -import android.support.customtabs.CustomTabsServiceConnection; -import android.support.customtabs.CustomTabsSession; import android.util.Log; + +import androidx.browser.customtabs.CustomTabsCallback; +import androidx.browser.customtabs.CustomTabsClient; +import androidx.browser.customtabs.CustomTabsIntent; +import androidx.browser.customtabs.CustomTabsServiceConnection; +import androidx.browser.customtabs.CustomTabsSession; + import com.getcapacitor.JSArray; import com.getcapacitor.JSObject; import com.getcapacitor.NativePlugin; diff --git a/android/capacitor/src/main/java/com/getcapacitor/plugin/Camera.java b/android/capacitor/src/main/java/com/getcapacitor/plugin/Camera.java index 6a4a5e091..f8eed9732 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/plugin/Camera.java +++ b/android/capacitor/src/main/java/com/getcapacitor/plugin/Camera.java @@ -10,9 +10,11 @@ import android.os.Bundle; import android.os.Environment; import android.provider.MediaStore; -import android.support.v4.content.FileProvider; import android.util.Base64; import android.util.Log; + +import androidx.core.content.FileProvider; + import com.getcapacitor.Dialogs; import com.getcapacitor.FileUtils; import com.getcapacitor.JSObject; diff --git a/android/capacitor/src/main/java/com/getcapacitor/plugin/Modals.java b/android/capacitor/src/main/java/com/getcapacitor/plugin/Modals.java index 21f1eb25f..828e38efb 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/plugin/Modals.java +++ b/android/capacitor/src/main/java/com/getcapacitor/plugin/Modals.java @@ -1,20 +1,7 @@ package com.getcapacitor.plugin; -import android.annotation.SuppressLint; import android.app.Activity; -import android.app.Dialog; -import android.graphics.Color; -import android.support.annotation.NonNull; -import android.support.design.widget.BottomSheetBehavior; -import android.support.design.widget.BottomSheetDialogFragment; -import android.support.design.widget.CoordinatorLayout; -import android.util.Log; -import android.view.View; -import android.view.Window; -import android.widget.LinearLayout; -import android.widget.TextView; - -import com.getcapacitor.Bridge; + import com.getcapacitor.Dialogs; import com.getcapacitor.JSArray; import com.getcapacitor.JSObject; @@ -24,11 +11,6 @@ import com.getcapacitor.PluginMethod; import com.getcapacitor.ui.ModalsBottomSheetDialogFragment; -import org.json.JSONException; -import org.json.JSONObject; - -import java.util.List; - /** * Common popup modals */ diff --git a/android/capacitor/src/main/java/com/getcapacitor/plugin/Permissions.java b/android/capacitor/src/main/java/com/getcapacitor/plugin/Permissions.java index 9d9efc147..59ae8e20e 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/plugin/Permissions.java +++ b/android/capacitor/src/main/java/com/getcapacitor/plugin/Permissions.java @@ -2,8 +2,9 @@ import android.Manifest; import android.content.pm.PackageManager; -import android.support.v4.app.NotificationManagerCompat; -import android.support.v4.content.ContextCompat; + +import androidx.core.app.NotificationManagerCompat; +import androidx.core.content.ContextCompat; import com.getcapacitor.JSObject; import com.getcapacitor.NativePlugin; diff --git a/android/capacitor/src/main/java/com/getcapacitor/plugin/PushNotifications.java b/android/capacitor/src/main/java/com/getcapacitor/plugin/PushNotifications.java index 279568744..6e7462115 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/plugin/PushNotifications.java +++ b/android/capacitor/src/main/java/com/getcapacitor/plugin/PushNotifications.java @@ -10,11 +10,11 @@ import android.os.Build; import android.os.Bundle; import android.service.notification.StatusBarNotification; -import android.support.v4.app.NotificationCompat; +import androidx.core.app.NotificationCompat; import android.net.Uri; - import android.util.Log; + import com.getcapacitor.Bridge; import com.getcapacitor.JSArray; import com.getcapacitor.JSObject; diff --git a/android/capacitor/src/main/java/com/getcapacitor/plugin/Share.java b/android/capacitor/src/main/java/com/getcapacitor/plugin/Share.java index d9c5d3753..70d8ab877 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/plugin/Share.java +++ b/android/capacitor/src/main/java/com/getcapacitor/plugin/Share.java @@ -2,9 +2,10 @@ import android.content.Intent; import android.net.Uri; -import android.support.v4.content.FileProvider; import android.webkit.MimeTypeMap; +import androidx.core.content.FileProvider; + import com.getcapacitor.NativePlugin; import com.getcapacitor.Plugin; import com.getcapacitor.PluginCall; diff --git a/android/capacitor/src/main/java/com/getcapacitor/plugin/background/BackgroundTask.java b/android/capacitor/src/main/java/com/getcapacitor/plugin/background/BackgroundTask.java index 3be2d0391..c08c88a65 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/plugin/background/BackgroundTask.java +++ b/android/capacitor/src/main/java/com/getcapacitor/plugin/background/BackgroundTask.java @@ -5,8 +5,8 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; -import android.support.v4.content.LocalBroadcastManager; -import android.util.Log; + +import androidx.localbroadcastmanager.content.LocalBroadcastManager; import com.getcapacitor.Bridge; import com.getcapacitor.JSObject; diff --git a/android/capacitor/src/main/java/com/getcapacitor/plugin/background/BackgroundTaskService.java b/android/capacitor/src/main/java/com/getcapacitor/plugin/background/BackgroundTaskService.java index 95ed6d202..460da214f 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/plugin/background/BackgroundTaskService.java +++ b/android/capacitor/src/main/java/com/getcapacitor/plugin/background/BackgroundTaskService.java @@ -2,8 +2,10 @@ import android.app.IntentService; import android.content.Intent; -import android.support.v4.content.LocalBroadcastManager; import android.util.Log; + +import androidx.localbroadcastmanager.content.LocalBroadcastManager; + import com.getcapacitor.LogUtils; public class BackgroundTaskService extends IntentService { diff --git a/android/capacitor/src/main/java/com/getcapacitor/plugin/camera/CameraUtils.java b/android/capacitor/src/main/java/com/getcapacitor/plugin/camera/CameraUtils.java index e39025301..d1f41d4d8 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/plugin/camera/CameraUtils.java +++ b/android/capacitor/src/main/java/com/getcapacitor/plugin/camera/CameraUtils.java @@ -3,9 +3,10 @@ import android.app.Activity; import android.net.Uri; import android.os.Environment; -import android.support.v4.content.FileProvider; import android.util.Log; +import androidx.core.content.FileProvider; + import com.getcapacitor.LogUtils; import java.io.File; diff --git a/android/capacitor/src/main/java/com/getcapacitor/plugin/notification/LocalNotificationManager.java b/android/capacitor/src/main/java/com/getcapacitor/plugin/notification/LocalNotificationManager.java index 20289a40c..e128c69f7 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/plugin/notification/LocalNotificationManager.java +++ b/android/capacitor/src/main/java/com/getcapacitor/plugin/notification/LocalNotificationManager.java @@ -10,12 +10,14 @@ import android.net.Uri; import android.os.Build; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.v4.app.NotificationCompat; -import android.support.v4.app.NotificationManagerCompat; -import android.support.v4.app.RemoteInput; import android.util.Log; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.core.app.NotificationCompat; +import androidx.core.app.NotificationManagerCompat; +import androidx.core.app.RemoteInput; + import com.getcapacitor.JSObject; import com.getcapacitor.LogUtils; import com.getcapacitor.PluginCall; @@ -27,6 +29,8 @@ import java.util.Date; import java.util.List; +import static androidx.core.app.NotificationCompat.VISIBILITY_PRIVATE; + /** * Contains implementations for all notification actions */ diff --git a/android/capacitor/src/main/java/com/getcapacitor/plugin/util/AssetUtil.java b/android/capacitor/src/main/java/com/getcapacitor/plugin/util/AssetUtil.java index 78392b795..d38664649 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/plugin/util/AssetUtil.java +++ b/android/capacitor/src/main/java/com/getcapacitor/plugin/util/AssetUtil.java @@ -8,8 +8,10 @@ import android.graphics.BitmapFactory; import android.net.Uri; import android.os.StrictMode; -import android.support.v4.content.FileProvider; import android.util.Log; + +import androidx.core.content.FileProvider; + import com.getcapacitor.LogUtils; import java.io.File; diff --git a/android/capacitor/src/main/java/com/getcapacitor/ui/ModalsBottomSheetDialogFragment.java b/android/capacitor/src/main/java/com/getcapacitor/ui/ModalsBottomSheetDialogFragment.java index 4a3c3c3e1..f3ef5b610 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/ui/ModalsBottomSheetDialogFragment.java +++ b/android/capacitor/src/main/java/com/getcapacitor/ui/ModalsBottomSheetDialogFragment.java @@ -3,18 +3,21 @@ import android.annotation.SuppressLint; import android.app.Dialog; import android.graphics.Color; -import android.support.annotation.NonNull; -import android.support.design.widget.BottomSheetBehavior; -import android.support.design.widget.BottomSheetDialogFragment; -import android.support.design.widget.CoordinatorLayout; import android.util.Log; import android.view.View; import android.view.Window; import android.widget.LinearLayout; import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.coordinatorlayout.widget.CoordinatorLayout; + import com.getcapacitor.JSArray; import com.getcapacitor.JSObject; import com.getcapacitor.LogUtils; +import com.google.android.material.bottomsheet.BottomSheetBehavior; +import com.google.android.material.bottomsheet.BottomSheetDialogFragment; + import org.json.JSONException; import org.json.JSONObject; diff --git a/android/capacitor/src/main/res/layout/bridge_layout_main.xml b/android/capacitor/src/main/res/layout/bridge_layout_main.xml index 1a6f336cd..12f0b8fc8 100644 --- a/android/capacitor/src/main/res/layout/bridge_layout_main.xml +++ b/android/capacitor/src/main/res/layout/bridge_layout_main.xml @@ -1,5 +1,5 @@ - - + diff --git a/android/gradle.properties b/android/gradle.properties index aac7c9b46..2dbcb0710 100644 --- a/android/gradle.properties +++ b/android/gradle.properties @@ -15,3 +15,7 @@ org.gradle.jvmargs=-Xmx1536m # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true + +# Supports AndroidX +android.useAndroidX=true +android.enableJetifier=true \ No newline at end of file diff --git a/example/android/app/src/main/res/layout/activity_main.xml b/example/android/app/src/main/res/layout/activity_main.xml index 980b7ade8..f5d388877 100644 --- a/example/android/app/src/main/res/layout/activity_main.xml +++ b/example/android/app/src/main/res/layout/activity_main.xml @@ -1,5 +1,5 @@ - - + diff --git a/example/android/gradle.properties b/example/android/gradle.properties index aac7c9b46..2dbcb0710 100644 --- a/example/android/gradle.properties +++ b/example/android/gradle.properties @@ -15,3 +15,7 @@ org.gradle.jvmargs=-Xmx1536m # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true + +# Supports AndroidX +android.useAndroidX=true +android.enableJetifier=true \ No newline at end of file diff --git a/plugin-template/android/gradle.properties b/plugin-template/android/gradle.properties index aac7c9b46..2dbcb0710 100644 --- a/plugin-template/android/gradle.properties +++ b/plugin-template/android/gradle.properties @@ -15,3 +15,7 @@ org.gradle.jvmargs=-Xmx1536m # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true + +# Supports AndroidX +android.useAndroidX=true +android.enableJetifier=true \ No newline at end of file diff --git a/plugin-template/android/src/main/res/layout/bridge_layout_main.xml b/plugin-template/android/src/main/res/layout/bridge_layout_main.xml index b69e589a9..56fec1546 100644 --- a/plugin-template/android/src/main/res/layout/bridge_layout_main.xml +++ b/plugin-template/android/src/main/res/layout/bridge_layout_main.xml @@ -1,5 +1,5 @@ - - +