Skip to content

Instantly share code, notes, and snippets.

@carlrobert-sonymobile
Last active September 25, 2018 12:48
Show Gist options
  • Save carlrobert-sonymobile/f8fb438185727633b8e73d61a1de0cf3 to your computer and use it in GitHub Desktop.
Save carlrobert-sonymobile/f8fb438185727633b8e73d61a1de0cf3 to your computer and use it in GitHub Desktop.
Android Nearby Connections, Android P, androidx
From 1ff97d13cdaaa65dec384870e086fc1431bad590 Mon Sep 17 00:00:00 2001
From: Robert Storlind <robert.storlind@sonymobile.com>
Date: Sun, 8 Jul 2018 10:59:21 +0200
Subject: [PATCH] Android 28 and androidx (yay)
Minimal migration. Not verified
---
connections/rockpaperscissors/app/build.gradle | 16 ++++++++++------
.../apps/rockpaperscissors/MainActivity.java | 16 +++++++++-------
connections/rockpaperscissors/build.gradle | 2 +-
connections/rockpaperscissors/gradle.properties | 2 ++
.../gradle/wrapper/gradle-wrapper.properties | 4 ++--
5 files changed, 24 insertions(+), 16 deletions(-)
diff --git a/connections/rockpaperscissors/app/build.gradle b/connections/rockpaperscissors/app/build.gradle
index 5c75cf0..efd4373 100644
--- a/connections/rockpaperscissors/app/build.gradle
+++ b/connections/rockpaperscissors/app/build.gradle
@@ -1,12 +1,11 @@
apply plugin: 'com.android.application'
android {
- compileSdkVersion 27
- buildToolsVersion '27.0.3'
+ compileSdkVersion 28
defaultConfig {
applicationId "com.google.location.nearby.apps.rockpaperscissors"
- minSdkVersion 21
- targetSdkVersion 27
+ minSdkVersion 23
+ targetSdkVersion 28
versionCode 1
versionName "1.0"
}
@@ -19,7 +18,12 @@ android {
}
dependencies {
- implementation 'com.android.support:support-v4:27.1.1'
- implementation 'com.android.support:appcompat-v7:27.1.1'
+ implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'com.google.android.gms:play-services-nearby:15.0.1'
}
+
+gradle.projectsEvaluated {
+ tasks.withType(JavaCompile) {
+ options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
+ }
+}
diff --git a/connections/rockpaperscissors/app/src/main/java/com/google/location/nearby/apps/rockpaperscissors/MainActivity.java b/connections/rockpaperscissors/app/src/main/java/com/google/location/nearby/apps/rockpaperscissors/MainActivity.java
index 21a84c5..c29d386 100644
--- a/connections/rockpaperscissors/app/src/main/java/com/google/location/nearby/apps/rockpaperscissors/MainActivity.java
+++ b/connections/rockpaperscissors/app/src/main/java/com/google/location/nearby/apps/rockpaperscissors/MainActivity.java
@@ -6,11 +6,11 @@ import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Bundle;
-import android.support.annotation.CallSuper;
-import android.support.annotation.NonNull;
-import android.support.annotation.Nullable;
-import android.support.v4.content.ContextCompat;
-import android.support.v7.app.AppCompatActivity;
+import androidx.annotation.CallSuper;
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.core.content.ContextCompat;
+import androidx.appcompat.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
@@ -249,14 +249,16 @@ public class MainActivity extends AppCompatActivity {
private void startDiscovery() {
// Note: Discovery may fail. To keep this demo simple, we don't handle failures.
connectionsClient.startDiscovery(
- getPackageName(), endpointDiscoveryCallback, new DiscoveryOptions(STRATEGY));
+ getPackageName(), endpointDiscoveryCallback,
+ new DiscoveryOptions.Builder().setStrategy(STRATEGY).build());
}
/** Broadcasts our presence using Nearby Connections so other players can find us. */
private void startAdvertising() {
// Note: Advertising may fail. To keep this demo simple, we don't handle failures.
connectionsClient.startAdvertising(
- codeName, getPackageName(), connectionLifecycleCallback, new AdvertisingOptions(STRATEGY));
+ codeName, getPackageName(), connectionLifecycleCallback,
+ new AdvertisingOptions.Builder().setStrategy(STRATEGY).build());
}
/** Wipes all game state and updates the UI accordingly. */
diff --git a/connections/rockpaperscissors/build.gradle b/connections/rockpaperscissors/build.gradle
index 8270afd..07b964b 100644
--- a/connections/rockpaperscissors/build.gradle
+++ b/connections/rockpaperscissors/build.gradle
@@ -6,7 +6,7 @@ buildscript {
google()
}
dependencies {
- classpath 'com.android.tools.build:gradle:3.2.0-beta02'
+ classpath 'com.android.tools.build:gradle:3.3.0-alpha11'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
diff --git a/connections/rockpaperscissors/gradle.properties b/connections/rockpaperscissors/gradle.properties
index aac7c9b..30d2ba9 100644
--- a/connections/rockpaperscissors/gradle.properties
+++ b/connections/rockpaperscissors/gradle.properties
@@ -10,6 +10,8 @@
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx1536m
+android.useAndroidX=true
+android.enableJetifier=true
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
diff --git a/connections/rockpaperscissors/gradle/wrapper/gradle-wrapper.properties b/connections/rockpaperscissors/gradle/wrapper/gradle-wrapper.properties
index 7b77d5d..dda9559 100644
--- a/connections/rockpaperscissors/gradle/wrapper/gradle-wrapper.properties
+++ b/connections/rockpaperscissors/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
-#Sat Jul 07 22:54:28 CEST 2018
+#Tue Sep 25 13:30:15 CEST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-4.10-all.zip
--
2.17.1.windows.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment