From d6c3a4b65eb71cf81fb66ebbe8cdfebc4870bb46 Mon Sep 17 00:00:00 2001 From: diego Date: Thu, 18 Jul 2019 15:16:11 -0300 Subject: [PATCH 1/5] fix androidX legacy dependencies... this is a hacky way to detect when to use the legacy dependecies from androidX. --- android/build.gradle | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 8e2c769..992c1df 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -46,7 +46,13 @@ dependencies { compileOnly "com.facebook.react:react-native:+" implementation "com.google.android.libraries.places:places:1.1.0" - implementation "com.android.support:appcompat-v7:${supportLibVersion}" - implementation "com.android.support:support-v4:${supportLibVersion}" implementation "com.google.code.findbugs:jsr305:3.0.2" + + if (rootProject.findProperty("android.useAndroidX")) { + implementation "androidx.appcompat:appcompat:1.0.2" + implementation "androidx.legacy:legacy-support-v4:1.0.0" + } else { + implementation "com.android.support:appcompat-v7:${supportLibVersion}" + implementation "com.android.support:support-v4:${supportLibVersion}" + } } \ No newline at end of file From 224fd4cc1d479288e918e436950eed20b1cc1378 Mon Sep 17 00:00:00 2001 From: diego Date: Thu, 8 Aug 2019 15:01:43 -0300 Subject: [PATCH 2/5] fix-leak-off-api-key-by-loading-from-manifest-xml --- android/build.gradle | 10 +++-- .../rngoogleplaces/RNGooglePlacesModule.java | 38 ++++++++++++++++--- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 992c1df..e184916 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -9,14 +9,12 @@ def safeExtGet(prop, fallback) { rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback } - android { compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION) defaultConfig { minSdkVersion safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION) targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION) - resValue "string", "places_api_key", (System.env.RNGP_ANDROID_API_KEY ? "$System.env.RNGP_ANDROID_API_KEY" : (rootProject.findProperty("RNGP_ANDROID_API_KEY") ?: "INSERT_KEY_HERE")) } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 @@ -48,7 +46,13 @@ dependencies { implementation "com.google.android.libraries.places:places:1.1.0" implementation "com.google.code.findbugs:jsr305:3.0.2" - if (rootProject.findProperty("android.useAndroidX")) { + Properties prop = new Properties(); + InputStream input = null; + + input = new FileInputStream("gradle.properties"); + prop.load(input); + + if (prop.getProperty("android.useAndroidX")) { implementation "androidx.appcompat:appcompat:1.0.2" implementation "androidx.legacy:legacy-support-v4:1.0.0" } else { diff --git a/android/src/main/java/com/arttitude360/reactnative/rngoogleplaces/RNGooglePlacesModule.java b/android/src/main/java/com/arttitude360/reactnative/rngoogleplaces/RNGooglePlacesModule.java index b65868f..83464fe 100644 --- a/android/src/main/java/com/arttitude360/reactnative/rngoogleplaces/RNGooglePlacesModule.java +++ b/android/src/main/java/com/arttitude360/reactnative/rngoogleplaces/RNGooglePlacesModule.java @@ -1,17 +1,18 @@ package com.arttitude360.reactnative.rngoogleplaces; import android.app.Activity; +import android.content.pm.ApplicationInfo; +import android.content.Context; import android.content.Intent; import android.content.IntentSender; -import android.os.Bundle; import android.text.TextUtils; import android.util.Log; import android.Manifest.permission; import android.content.pm.PackageManager; -import android.support.annotation.Nullable; -import android.support.annotation.RequiresPermission; -import android.support.v4.content.ContextCompat; -import android.support.v4.app.ActivityCompat; +import androidx.annotation.Nullable; +import androidx.annotation.RequiresPermission; +import androidx.core.content.ContextCompat; +import androidx.core.app.ActivityCompat; import static android.Manifest.permission.ACCESS_FINE_LOCATION; import static android.Manifest.permission.ACCESS_WIFI_STATE; @@ -72,11 +73,31 @@ public class RNGooglePlacesModule extends ReactContextBaseJavaModule implements public static int AUTOCOMPLETE_REQUEST_CODE = 360; public static String REACT_CLASS = "RNGooglePlaces"; + // usage: + // String user = getMetadata(this, “user); + + public static String getMetadata(Context context, String name) { + String value = null; + + try { + ApplicationInfo appInfo = context.getPackageManager().getApplicationInfo( + context.getPackageName(), PackageManager.GET_META_DATA); + if (appInfo.metaData != null) { + value = appInfo.metaData.getString(name); + } + } catch (PackageManager.NameNotFoundException e) { + // if we can’t find it in the manifest, just return null + } catch (Exception e) { + // i don't know what I'm doing... + // silly, don't bubble exception to another contexts. + } + return value; + } public RNGooglePlacesModule(ReactApplicationContext reactContext) { super(reactContext); - String apiKey = reactContext.getApplicationContext().getString(R.string.places_api_key); + String apiKey = findApiKey(reactContext.getApplicationContext(),"com.arttitude360.reactnative.rngoogleplaces.API_KEY"); // Setup Places Client if (!Places.isInitialized() && !apiKey.equals("")) { @@ -89,6 +110,11 @@ public RNGooglePlacesModule(ReactApplicationContext reactContext) { this.reactContext.addActivityEventListener(this); } + private String findApiKey(Context context, String fieldName) { + String apiKey = getMetadata(context, fieldName); + return apiKey; + } + @Override public String getName() { return REACT_CLASS; From 6f2f760eccf973dcad592b10afd47c0b27a3ec52 Mon Sep 17 00:00:00 2001 From: Diego jimenes <30362135+diegojimenes@users.noreply.github.com> Date: Sun, 22 Sep 2019 14:58:24 -0300 Subject: [PATCH 3/5] new approach for setting google places key --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 4d5aefc..5111fd3 100644 --- a/README.md +++ b/README.md @@ -121,18 +121,18 @@ on top of the file. ##### Auto Linking With Your Project - This was done automatically for you when you ran `react-native link react-native-google-places`. Or you can run the command now if you have not already. -- In your `AndroidManifest.xml` file, request the following permissions: +- In your `AndroidManifest.xml` file, request the following permissions and add your API key: ```xml -``` - -- In your `/android/gradle.properties` file, add your API key, **read about a better way to secure this below** -```groovy -RNGP_ANDROID_API_KEY=Insert_API_KEY_here + + ... + + ... + ``` ##### Manual Linking With Your Project (Android) From 8f2c38837769501d5091d31569a75cbafd876ead Mon Sep 17 00:00:00 2001 From: Diego jimenes <30362135+diegojimenes@users.noreply.github.com> Date: Sun, 22 Sep 2019 14:58:24 -0300 Subject: [PATCH 4/5] Revert "new approach for setting google places key" This reverts commit 6f2f760eccf973dcad592b10afd47c0b27a3ec52. --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 8b0f99b..eb0b880 100644 --- a/README.md +++ b/README.md @@ -121,18 +121,18 @@ on top of the file. ##### Auto Linking With Your Project - This was done automatically for you when you ran `react-native link react-native-google-places`. Or you can run the command now if you have not already. -- In your `AndroidManifest.xml` file, request the following permissions and add your API key: +- In your `AndroidManifest.xml` file, request the following permissions: ```xml +``` + +- In your `/android/gradle.properties` file, add your API key, **read about a better way to secure this below** - - ... - - ... - +```groovy +RNGP_ANDROID_API_KEY=Insert_API_KEY_here ``` ##### Manual Linking With Your Project (Android) From 80725510da36b88e408abe39a71a7512b5d8c245 Mon Sep 17 00:00:00 2001 From: diego jimenes Date: Sun, 22 Sep 2019 15:28:02 -0300 Subject: [PATCH 5/5] Revert "fix-leak-off-api-key-by-loading-from-manifest-xml" This reverts commit 224fd4cc1d479288e918e436950eed20b1cc1378. --- android/build.gradle | 14 +++++-- .../rngoogleplaces/RNGooglePlacesModule.java | 38 +++---------------- 2 files changed, 17 insertions(+), 35 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index c512fee..c325c22 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -9,12 +9,14 @@ def safeExtGet(prop, fallback) { rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback } + android { compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION) defaultConfig { minSdkVersion safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION) targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION) + resValue "string", "places_api_key", (System.env.RNGP_ANDROID_API_KEY ? "$System.env.RNGP_ANDROID_API_KEY" : (rootProject.findProperty("RNGP_ANDROID_API_KEY") ?: "INSERT_KEY_HERE")) } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 @@ -44,7 +46,13 @@ dependencies { implementation "com.facebook.react:react-native:+" implementation "com.google.android.libraries.places:places:1.1.0" - implementation "com.android.support:appcompat-v7:${supportLibVersion}" - implementation "com.android.support:support-v4:${supportLibVersion}" implementation "com.google.code.findbugs:jsr305:3.0.2" -} + + if (rootProject.findProperty("android.useAndroidX")) { + implementation "androidx.appcompat:appcompat:1.0.2" + implementation "androidx.legacy:legacy-support-v4:1.0.0" + } else { + implementation "com.android.support:appcompat-v7:${supportLibVersion}" + implementation "com.android.support:support-v4:${supportLibVersion}" + } +} \ No newline at end of file diff --git a/android/src/main/java/com/arttitude360/reactnative/rngoogleplaces/RNGooglePlacesModule.java b/android/src/main/java/com/arttitude360/reactnative/rngoogleplaces/RNGooglePlacesModule.java index 83464fe..b65868f 100644 --- a/android/src/main/java/com/arttitude360/reactnative/rngoogleplaces/RNGooglePlacesModule.java +++ b/android/src/main/java/com/arttitude360/reactnative/rngoogleplaces/RNGooglePlacesModule.java @@ -1,18 +1,17 @@ package com.arttitude360.reactnative.rngoogleplaces; import android.app.Activity; -import android.content.pm.ApplicationInfo; -import android.content.Context; import android.content.Intent; import android.content.IntentSender; +import android.os.Bundle; import android.text.TextUtils; import android.util.Log; import android.Manifest.permission; import android.content.pm.PackageManager; -import androidx.annotation.Nullable; -import androidx.annotation.RequiresPermission; -import androidx.core.content.ContextCompat; -import androidx.core.app.ActivityCompat; +import android.support.annotation.Nullable; +import android.support.annotation.RequiresPermission; +import android.support.v4.content.ContextCompat; +import android.support.v4.app.ActivityCompat; import static android.Manifest.permission.ACCESS_FINE_LOCATION; import static android.Manifest.permission.ACCESS_WIFI_STATE; @@ -73,31 +72,11 @@ public class RNGooglePlacesModule extends ReactContextBaseJavaModule implements public static int AUTOCOMPLETE_REQUEST_CODE = 360; public static String REACT_CLASS = "RNGooglePlaces"; - // usage: - // String user = getMetadata(this, “user); - - public static String getMetadata(Context context, String name) { - String value = null; - - try { - ApplicationInfo appInfo = context.getPackageManager().getApplicationInfo( - context.getPackageName(), PackageManager.GET_META_DATA); - if (appInfo.metaData != null) { - value = appInfo.metaData.getString(name); - } - } catch (PackageManager.NameNotFoundException e) { - // if we can’t find it in the manifest, just return null - } catch (Exception e) { - // i don't know what I'm doing... - // silly, don't bubble exception to another contexts. - } - return value; - } public RNGooglePlacesModule(ReactApplicationContext reactContext) { super(reactContext); - String apiKey = findApiKey(reactContext.getApplicationContext(),"com.arttitude360.reactnative.rngoogleplaces.API_KEY"); + String apiKey = reactContext.getApplicationContext().getString(R.string.places_api_key); // Setup Places Client if (!Places.isInitialized() && !apiKey.equals("")) { @@ -110,11 +89,6 @@ public RNGooglePlacesModule(ReactApplicationContext reactContext) { this.reactContext.addActivityEventListener(this); } - private String findApiKey(Context context, String fieldName) { - String apiKey = getMetadata(context, fieldName); - return apiKey; - } - @Override public String getName() { return REACT_CLASS;