Skip to content

Fixes compile errors for flutter 3.29.0 #54

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

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 5 additions & 8 deletions google_api_availability/example/android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
plugins {
id "com.android.application"
id "dev.flutter.flutter-gradle-plugin"
}

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
Expand All @@ -6,11 +11,6 @@ if (localPropertiesFile.exists()) {
}
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
Expand All @@ -21,9 +21,6 @@ if (flutterVersionName == null) {
flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
namespace 'com.baseflow.googleapiavailabilityexample'
compileSdkVersion flutter.compileSdkVersion
Expand Down
11 changes: 0 additions & 11 deletions google_api_availability/example/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
buildscript {
repositories {
google()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:7.3.0'
}
}

allprojects {
repositories {
google()
Expand Down
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-7.5-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-all.zip
29 changes: 19 additions & 10 deletions google_api_availability/example/android/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
include ':app'
pluginManagement {
def flutterSdkPath = {
def properties = new Properties()
file("local.properties").withInputStream { properties.load(it) }
def flutterSdkPath = properties.getProperty("flutter.sdk")
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
return flutterSdkPath
}()

def flutterProjectRoot = rootProject.projectDir.parentFile.toPath()
includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")

def plugins = new Properties()
def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins')
if (pluginsFile.exists()) {
pluginsFile.withReader('UTF-8') { reader -> plugins.load(reader) }
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
}

plugins.each { name, path ->
def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile()
include ":$name"
project(":$name").projectDir = pluginDirectory
plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version "8.1.0" apply false
}

include ":app"
6 changes: 3 additions & 3 deletions google_api_availability/scripts/before_build_apks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ echo y | sdkmanager "extras;android;m2repository" >/dev/null
echo y | sdkmanager "extras;google;m2repository" >/dev/null
echo y | sdkmanager "patcher;v4" >/dev/null
sdkmanager --list
wget http://services.gradle.org/distributions/gradle-4.1-bin.zip
unzip -qq gradle-4.1-bin.zip -d $HOME/gradle-4.1
export GRADLE_HOME=$HOME/gradle-4.1
wget http://services.gradle.org/distributions/gradle-8.1-bin.zip
unzip -qq gradle-8.1-bin.zip -d $HOME/gradle-8.1
export GRADLE_HOME=$HOME/gradle-8.1
export PATH=$GRADLE_HOME/bin:$PATH
gradle -v
git clone --single-branch --branch stable https://github.com/flutter/flutter.git $HOME/flutter
Expand Down
6 changes: 6 additions & 0 deletions google_api_availability_android/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 1.0.2

* Fixes compile errors for Flutter 3.29.0 (and above)
* updates compileSDK to 35
* updates gradle version to 8.1

## 1.0.1

* Adds support for the namespace property to support Android Gradle Plugin (AGP) 8.
Expand Down
13 changes: 1 addition & 12 deletions google_api_availability_android/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
group 'com.baseflow.googleapiavailability'
version '1.0-SNAPSHOT'

buildscript {
repositories {
google()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
}
}

rootProject.allprojects {
repositories {
google()
Expand All @@ -27,7 +16,7 @@ android {
namespace 'com.baseflow.googleapiavailability'
}

compileSdkVersion 31
compileSdkVersion 35

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
Expand Down
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-7.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
25 changes: 24 additions & 1 deletion google_api_availability_android/android/settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1,24 @@
rootProject.name = 'google_api_availability'
pluginManagement {
def flutterSdkPath = {
def properties = new Properties()
file("local.properties").withInputStream { properties.load(it) }
def flutterSdkPath = properties.getProperty("flutter.sdk")
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
return flutterSdkPath
}()

includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")

repositories {
google()
mavenCentral()
gradlePluginPortal()
}
}

plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version "8.1.0" apply false
}

include ":app"
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding;
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.PluginRegistry.Registrar;
import io.flutter.plugin.common.PluginRegistry.ViewDestroyListener;
import io.flutter.view.FlutterNativeView;

/**
* GoogleApiAvailabilityPlugin
Expand All @@ -26,57 +23,53 @@ public GoogleApiAvailabilityPlugin() {
}

@Override
public void onAttachedToActivity(ActivityPluginBinding binding) {
methodCallHandler.setActivity(binding.getActivity());
}
public void onAttachedToActivity(ActivityPluginBinding binding) {
if (methodCallHandler != null) {
methodCallHandler.setActivity(binding.getActivity());
}
}

@Override
public void onDetachedFromActivity() {
methodCallHandler.setActivity(null);
}
@Override
public void onDetachedFromActivity() {
if (methodCallHandler != null) {
methodCallHandler.setActivity(null);
}
}

@Override
public void onReattachedToActivityForConfigChanges(@NonNull ActivityPluginBinding binding) {
methodCallHandler.setActivity(binding.getActivity());
}
@Override
public void onReattachedToActivityForConfigChanges(@NonNull ActivityPluginBinding binding) {
if (methodCallHandler != null) {
methodCallHandler.setActivity(binding.getActivity());
}
}

@Override
public void onDetachedFromActivityForConfigChanges() {
methodCallHandler.setActivity(null);
}
@Override
public void onDetachedFromActivityForConfigChanges() {
if (methodCallHandler != null) {
methodCallHandler.setActivity(null);
}
}

@Override
public void onAttachedToEngine(FlutterPluginBinding binding) {
registerPlugin(binding.getApplicationContext(), binding.getBinaryMessenger());
}
@Override
public void onAttachedToEngine(@NonNull FlutterPluginBinding binding) {
registerPlugin(binding.getApplicationContext(), binding.getBinaryMessenger());
}

@Override
public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {
unregisterPlugin();
}

public static void registerWith(Registrar registrar) {
final GoogleApiAvailabilityPlugin plugin = new GoogleApiAvailabilityPlugin();
plugin.registerPlugin(registrar.context(), registrar.messenger());
plugin.methodCallHandler.setActivity(registrar.activity());

registrar.addViewDestroyListener(new ViewDestroyListener() {
@Override
public boolean onViewDestroy(FlutterNativeView view) {
plugin.unregisterPlugin();
return false;
}
});
}

private void registerPlugin(Context context, BinaryMessenger messenger) {
methodCallHandler = new MethodCallHandlerImpl(context, googleApiAvailabilityManager);
channel = new MethodChannel(messenger, "flutter.baseflow.com/google_api_availability_android/methods");
channel.setMethodCallHandler(methodCallHandler);
}

private void unregisterPlugin() {
channel.setMethodCallHandler(null);
channel = null;
if (channel != null) {
channel.setMethodCallHandler(null);
channel = null;
}
}
}
2 changes: 1 addition & 1 deletion google_api_availability_android/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: An Android implementation for the google_api_availability plugin.
repository: https://github.com/baseflow/flutter-google-api-availability/tree/main/google_api_availability_android
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
version: 1.0.1
version: 1.0.2

flutter:
plugin:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class MethodChannelMock {
this.result,
this.delay = Duration.zero,
}) : methodChannel = MethodChannel(channelName) {
TestDefaultBinaryMessengerBinding.instance!.defaultBinaryMessenger
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(methodChannel, _handler);
}

Expand Down
Loading