Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Null safety - New android plugin embedding v2 - Secrets Gradle Plugin for Android #179

Closed
wants to merge 49 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
ef7fdd7
null safety migra
blbhargav Jun 22, 2021
72b0d06
null safety migra
blbhargav Jun 22, 2021
3cb447c
null safety migration completed
blbhargav Jun 22, 2021
2a4d1a6
Type casting errors due to null safety fixed
blbhargav Jun 22, 2021
15d03bd
Type casting errors due to null safety fixed
blbhargav Jun 22, 2021
9fa48d2
Update with null safety, android embeddingV2 and Secrets Gradle Plugi…
davemg3 Oct 25, 2021
57040e8
Android embedding V2 : new plugin android
davemg3 Oct 25, 2021
f88dd84
11/02/2022 adapted LocationResult to address info needed
davemg3 Jan 11, 2022
8ad4695
11/02/2022 adapted LocationResult to address info needed
davemg3 Jan 11, 2022
91b5f03
11/02/2022 adapted LocationResult to parse address details
davemg3 Mar 9, 2022
0771683
11/02/2022 adapted LocationResult to parse address details
davemg3 Mar 9, 2022
0840a91
13/02/2022 adapted LocationResult to parse address details
davemg3 Mar 13, 2022
e24ca70
13/02/2022 adapted LocationResult to parse address details
davemg3 Mar 13, 2022
2a689b3
13/02/2022 adapted LocationResult to parse address details
davemg3 Mar 13, 2022
e98bfb9
13/02/2022 adapted LocationResult to parse address details
davemg3 Mar 13, 2022
9efd721
13/02/2022 adapted LocationResult to parse address details
davemg3 Mar 13, 2022
d42d0b0
13/02/2022 adapted LocationResult to parse address details
davemg3 Mar 13, 2022
675971c
13/02/2022 adapted LocationResult to parse address details
davemg3 Mar 13, 2022
42850fe
13/02/2022 adapted LocationResult to parse address details
davemg3 Mar 13, 2022
a0fb58c
13/02/2022 adapted LocationResult to parse address details
davemg3 Mar 13, 2022
5865569
13/02/2022 adapted LocationResult to parse address details
davemg3 Mar 13, 2022
47d6f78
13/02/2022 adapted LocationResult to parse address details
davemg3 Mar 13, 2022
8154bbb
13/02/2022 adapted LocationResult to parse address details
davemg3 Mar 13, 2022
687d8dd
13/02/2022 adapted LocationResult to parse address details
davemg3 Mar 13, 2022
aa6a655
13/02/2022 adapted LocationResult to parse address details
davemg3 Mar 13, 2022
1fc4a27
13/02/2022 adapted LocationResult to parse address details
davemg3 Mar 13, 2022
7b0794d
13/02/2022 adapted LocationResult to parse address details
davemg3 Mar 13, 2022
cc46339
13/02/2022 adapted LocationResult to parse address details
davemg3 Mar 13, 2022
91cde95
13/02/2022 adapted LocationResult to parse address details
davemg3 Mar 13, 2022
cddca86
13/02/2022 adapted LocationResult to parse address details
davemg3 Mar 13, 2022
ce992d4
13/02/2022 adapted LocationResult to parse address details
davemg3 Mar 13, 2022
2680ec7
13/02/2022 adapted LocationResult to parse address details
davemg3 Mar 13, 2022
3a537ac
13/02/2022 adapted LocationResult to parse address details
davemg3 Mar 13, 2022
b6f653c
13/02/2022 adapted LocationResult to parse address details
davemg3 Mar 13, 2022
528373f
13/02/2022 adapted LocationResult to parse address details
davemg3 Mar 13, 2022
94ad44c
13/02/2022 adapted LocationResult to parse address details
davemg3 Mar 13, 2022
7eb1f11
13/02/2022 adapted LocationResult to parse address details
davemg3 Mar 13, 2022
f12c977
13/02/2022 adapted LocationResult to parse address details
davemg3 Mar 13, 2022
dfe0b43
13/02/2022 adapted LocationResult to parse address details
davemg3 Mar 13, 2022
2af019d
13/02/2022 adapted LocationResult to parse address details
davemg3 Mar 13, 2022
af3aa77
.orEmpty() added on 14/05/22 to call.arguments<String>().orEmpty() in…
davemg3 May 14, 2022
802129f
.orEmpty() added on 14/05/22 to call.arguments<String>().orEmpty() in…
davemg3 May 14, 2022
afc2c03
26/09/22 updated kotlin version and android gradle plugin
davemg3 Sep 25, 2022
432be89
11/11/22 updated provider version
davemg3 Nov 11, 2022
7931cab
20/04/23 updated provider version
davemg3 Apr 20, 2023
cf0006e
20/04/23 updated provider version
davemg3 Apr 20, 2023
ea8d86f
update on 26/05/2023
davemg3 May 25, 2023
a16fdcd
update on 29/05/2023
davemg3 May 29, 2023
bf52fae
update on 20/07/2023
davemg3 Jul 19, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ group 'com.humazed.google_map_location_picker'
version '1.0-SNAPSHOT'

buildscript {
ext.kotlin_version = '1.3.31'
ext.kotlin_version = '1.7.10'
repositories {
google()
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
classpath "com.android.tools.build:gradle:7.3.0"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand All @@ -25,13 +25,13 @@ apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 28
compileSdkVersion 30

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
minSdkVersion 16
minSdkVersion 23
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
lintOptions {
Expand Down
Binary file modified android/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
package com.humazed.google_map_location_picker

import android.app.Activity
import android.content.pm.PackageInfo
import android.content.pm.PackageManager
import androidx.annotation.UiThread
import androidx.annotation.NonNull

import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.common.MethodChannel.MethodCallHandler
import io.flutter.plugin.common.MethodChannel.Result
import io.flutter.plugin.common.PluginRegistry.Registrar
import io.flutter.embedding.engine.plugins.activity.ActivityAware
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding
import android.content.pm.PackageManager
import java.math.BigInteger
import java.security.MessageDigest
import android.content.pm.PackageInfo

class GoogleMapLocationPickerPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
private lateinit var channel : MethodChannel
private var activityBinding: ActivityPluginBinding? = null

class GoogleMapLocationPickerPlugin(act: Activity) : MethodCallHandler {
var activity: Activity = act

companion object {
@JvmStatic
fun registerWith(registrar: Registrar) {
val channel = MethodChannel(registrar.messenger(), "google_map_location_picker")
channel.setMethodCallHandler(GoogleMapLocationPickerPlugin(registrar.activity()))
}
override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
channel = MethodChannel(flutterPluginBinding.binaryMessenger, "google_map_location_picker")
channel.setMethodCallHandler(this)
}

@UiThread
override fun onMethodCall(call: MethodCall, result: Result) {
if (call.method == "getPlatformVersion") {
result.success("Android ${android.os.Build.VERSION.RELEASE}")
override fun onMethodCall(@NonNull call: MethodCall, @NonNull result: Result) {
if(activityBinding == null) {
result.notImplemented()
return
}
if (call.method == "getSigningCertSha1") {
try {
val info: PackageInfo = activity.packageManager.getPackageInfo(call.arguments<String>(), PackageManager.GET_SIGNATURES)
//.orEmpty() added on 14/05/22 by mg to call.arguments<String>().orEmpty()
val info: PackageInfo = activityBinding!!.activity.packageManager.getPackageInfo(call.arguments<String>().orEmpty(), PackageManager.GET_SIGNATURES)
for (signature in info.signatures) {
val md: MessageDigest = MessageDigest.getInstance("SHA1")
md.update(signature.toByteArray())
Expand All @@ -49,4 +49,22 @@ class GoogleMapLocationPickerPlugin(act: Activity) : MethodCallHandler {
result.notImplemented()
}
}
}

override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) {
channel.setMethodCallHandler(null)
}

override fun onAttachedToActivity(binding: ActivityPluginBinding) {
activityBinding = binding
}

override fun onDetachedFromActivity() {
activityBinding = null
}

override fun onDetachedFromActivityForConfigChanges() {
}

override fun onReattachedToActivityForConfigChanges(binding: ActivityPluginBinding) {
}
}
1 change: 1 addition & 0 deletions example/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
.pub-cache/
.pub/
/build/
/lib/api_keys.dart

# Android related
**/android/**/gradle-wrapper.jar
Expand Down
15 changes: 10 additions & 5 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
plugins {
id("com.android.application")
id("kotlin-android")
id("com.google.android.libraries.mapsplatform.secrets-gradle-plugin")
}

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
Expand All @@ -21,12 +27,11 @@ if (flutterVersionName == null) {
flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'

apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 28
compileSdkVersion 31

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
Expand All @@ -39,8 +44,8 @@ android {
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.humazed.google_map_location_picker_example"
minSdkVersion 16
targetSdkVersion 28
minSdkVersion 23
targetSdkVersion 31
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
Expand Down
16 changes: 10 additions & 6 deletions example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher"
android:label="google_map_location_picker_example"
tools:ignore="GoogleAppIndexingWarning">
<activity
android:name=".MainActivity"
android:name="io.flutter.embedding.android.FlutterActivity"
android:exported="true"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:launchMode="singleTop"
Expand All @@ -38,11 +39,14 @@
</intent-filter>
</activity>

<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<!-- <meta-data-->
<!-- android:name="com.google.android.gms.version"-->
<!-- android:value="1" />-->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/GOOGLE_MAPS_API_KEY" />
android:value="${MAPS_API_KEY}" />
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
</manifest>

This file was deleted.

18 changes: 18 additions & 0 deletions example/android/app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Theme applied to the Android Window while the process is starting -->
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
<!-- Show a splash screen on the activity. Automatically removed when
Flutter draws its first frame -->
<item name="android:windowBackground">@drawable/launch_background</item>
</style>
<!-- Theme applied to the Android Window as soon as the process has started.
This theme determines the color of the Android Window while your
Flutter UI initializes, as well as behind your Flutter UI while its
running.
This Theme is only used starting with V2 of Flutter's Android embedding. -->
<style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
<item name="android:windowBackground">@android:color/white</item>
</style>
</resources>
5 changes: 3 additions & 2 deletions example/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
buildscript {
ext.kotlin_version = '1.3.61'
ext.kotlin_version = '1.5.0'
repositories {
google()
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.6.3'
classpath "com.android.tools.build:gradle:7.0.2"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "com.google.android.libraries.mapsplatform.secrets-gradle-plugin:secrets-gradle-plugin:2.0.0"
}
}

Expand Down
2 changes: 1 addition & 1 deletion example/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
13 changes: 13 additions & 0 deletions example/ios/Flutter/flutter_export_environment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh
# This is a generated file; do not edit or check into version control.
export "FLUTTER_ROOT=/Users/davidbeville/Programming/flutter"
export "FLUTTER_APPLICATION_PATH=/Users/davidbeville/AndroidStudioProjects/google_map_location_picker/example"
export "COCOAPODS_PARALLEL_CODE_SIGN=true"
export "FLUTTER_TARGET=lib/main.dart"
export "FLUTTER_BUILD_DIR=build"
export "FLUTTER_BUILD_NAME=1.0.0"
export "FLUTTER_BUILD_NUMBER=1.0.0"
export "DART_OBFUSCATION=false"
export "TRACK_WIDGET_CREATION=true"
export "TREE_SHAKE_ICONS=false"
export "PACKAGE_CONFIG=.dart_tool/package_config.json"
32 changes: 16 additions & 16 deletions example/lib/generated/i18n.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import 'package:flutter/material.dart';
class S implements WidgetsLocalizations {
const S();

static S current;
static S? current;

static const GeneratedLocalizationsDelegate delegate =
GeneratedLocalizationsDelegate();

static S of(BuildContext context) => Localizations.of<S>(context, S);
static S? of(BuildContext context) => Localizations.of<S>(context, S);

@override
TextDirection get textDirection => TextDirection.ltr;
Expand All @@ -33,7 +33,7 @@ class $en extends S {
const $en();
}

class GeneratedLocalizationsDelegate extends LocalizationsDelegate<S> {
class GeneratedLocalizationsDelegate extends LocalizationsDelegate<S?> {
const GeneratedLocalizationsDelegate();

List<Locale> get supportedLocales {
Expand All @@ -44,8 +44,8 @@ class GeneratedLocalizationsDelegate extends LocalizationsDelegate<S> {
}

LocaleListResolutionCallback listResolution(
{Locale fallback, bool withCountry = true}) {
return (List<Locale> locales, Iterable<Locale> supported) {
{Locale? fallback, bool withCountry = true}) {
return (List<Locale>? locales, Iterable<Locale> supported) {
if (locales == null || locales.isEmpty) {
return fallback ?? supported.first;
} else {
Expand All @@ -55,29 +55,29 @@ class GeneratedLocalizationsDelegate extends LocalizationsDelegate<S> {
}

LocaleResolutionCallback resolution(
{Locale fallback, bool withCountry = true}) {
return (Locale locale, Iterable<Locale> supported) {
{Locale? fallback, bool withCountry = true}) {
return (Locale? locale, Iterable<Locale> supported) {
return _resolve(locale, fallback, supported, withCountry);
};
}

@override
Future<S> load(Locale locale) {
final String lang = getLang(locale);
Future<S?> load(Locale locale) {
final String? lang = getLang(locale);
if (lang != null) {
switch (lang) {
case "ar":
S.current = const $ar();
return SynchronousFuture<S>(S.current);
return SynchronousFuture<S?>(S.current);
case "en":
S.current = const $en();
return SynchronousFuture<S>(S.current);
return SynchronousFuture<S?>(S.current);
default:
// NO-OP.
}
}
S.current = const S();
return SynchronousFuture<S>(S.current);
return SynchronousFuture<S?>(S.current);
}

@override
Expand All @@ -89,7 +89,7 @@ class GeneratedLocalizationsDelegate extends LocalizationsDelegate<S> {
///
/// Internal method to resolve a locale from a list of locales.
///
Locale _resolve(Locale locale, Locale fallback, Iterable<Locale> supported,
Locale _resolve(Locale? locale, Locale? fallback, Iterable<Locale> supported,
bool withCountry) {
if (locale == null || !_isSupported(locale, withCountry)) {
return fallback ?? supported.first;
Expand Down Expand Up @@ -125,7 +125,7 @@ class GeneratedLocalizationsDelegate extends LocalizationsDelegate<S> {
// If no country requirement is requested, check if this locale has no country.
if (true != withCountry &&
(supportedLocale.countryCode == null ||
supportedLocale.countryCode.isEmpty)) {
supportedLocale.countryCode!.isEmpty)) {
return true;
}
}
Expand All @@ -134,8 +134,8 @@ class GeneratedLocalizationsDelegate extends LocalizationsDelegate<S> {
}
}

String getLang(Locale l) => l == null
String? getLang(Locale l) => l == null
? null
: l.countryCode != null && l.countryCode.isEmpty
: l.countryCode != null && l.countryCode!.isEmpty
? l.languageCode
: l.toString();
Loading