Skip to content
Open
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
4 changes: 4 additions & 0 deletions packages/local_auth/local_auth_android/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.0.6

* Updates build files from Groovy to Kotlin.

## 2.0.5

* Adds platform-specific setup instructions to README.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group = 'io.flutter.plugins.localauth'
version = '1.0-SNAPSHOT'
group = "io.flutter.plugins.localauth"
version = "1.0-SNAPSHOT"

buildscript {
repositories {
Expand All @@ -8,7 +8,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:8.13.1'
classpath("com.android.tools.build:gradle:8.13.1")
}
}

Expand All @@ -19,37 +19,40 @@ rootProject.allprojects {
}
}

apply plugin: 'com.android.library'
plugins {
id("com.android.library")
}

android {
namespace = "io.flutter.plugins.localauth"
compileSdk = flutter.compileSdkVersion

defaultConfig {
minSdkVersion 24
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
minSdk = 24
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

lintOptions {
lint {
checkAllWarnings = true
warningsAsErrors = true
disable 'AndroidGradlePluginVersion', 'InvalidPackage', 'GradleDependency', 'NewerVersionAvailable'
disable.addAll(setOf("AndroidGradlePluginVersion", "InvalidPackage", "GradleDependency", "NewerVersionAvailable"))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A note here in case future us wonders why it's written this way: the examples I found in official docs did something like:

disable += "AndroidGradlePluginVersion" + "InvalidPackage" + "GradleDependency" + "NewerVersionAvailable"

When I tried that it was clearly doing string concatenation rather than list addition (I got an error about AndroidGradlePluginVersionInvalidPackageGradleDependencyNewerVersionAvailable being an unknown lint to ignore). I'm assuming that's a Gradle version issue or something? This version works, and seemed reasonable.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://developer.android.com/studio/write/lint#gradle was the documentation I found, for posterity.

}


testOptions {
unitTests.includeAndroidResources = true
unitTests.returnDefaultValues = true
unitTests.all {
testLogging {
events "passed", "skipped", "failed", "standardOut", "standardError"
outputs.upToDateWhen {false}
showStandardStreams = true
unitTests {
isIncludeAndroidResources = true
isReturnDefaultValues = true
all {
it.outputs.upToDateWhen { false }
it.testLogging {
events("passed", "skipped", "failed", "standardOut", "standardError")
showStandardStreams = true
}
}
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = "local_auth"
2 changes: 1 addition & 1 deletion packages/local_auth/local_auth_android/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: local_auth_android
description: Android implementation of the local_auth plugin.
repository: https://github.com/flutter/packages/tree/main/packages/local_auth/local_auth_android
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+local_auth%22
version: 2.0.5
version: 2.0.6

environment:
sdk: ^3.9.0
Expand Down
215 changes: 188 additions & 27 deletions script/tool/test/gradle_check_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ void main() {
late Directory packagesDir;
const groovyJavaIncompatabilityIndicator =
'build.gradle must set an explicit Java compatibility version.';
const kotlinJavaIncompatabilityIndicator =
'build.gradle.kts must set an explicit Java compatibility version.';

setUp(() {
final GitDir gitDir;
Expand Down Expand Up @@ -128,6 +130,101 @@ dependencies {
''');
}

/// Writes a fake android/build.gradle.kts file for plugin [package] with the
/// given options.
void writeFakeKotlinPluginBuildGradle(
RepositoryPackage package, {
bool includeLanguageVersion = false,
bool includeSourceCompat = false,
bool includeTargetCompat = false,
bool commentSourceLanguage = false,
bool includeNamespace = true,
bool commentNamespace = false,
bool warningsConfigured = true,
String compileSdk = '36',
bool includeKotlinOptions = true,
bool commentKotlinOptions = false,
bool useDeprecatedJvmTargetStyle = false,
int jvmTargetValue = 17,
int kotlinJvmValue = 17,
}) {
final File buildGradle = package
.platformDirectory(FlutterPlatform.android)
.childFile('build.gradle.kts');
buildGradle.createSync(recursive: true);

const warningConfig = '''
lint {
checkAllWarnings = true
warningsAsErrors = true
disable.addAll(setOf("AndroidGradlePluginVersion", "InvalidPackage", "GradleDependency", "NewerVersionAvailable"))
baseline = file("lint-baseline.xml")
}
''';
final javaSection =
'''
java {
toolchain {
${commentSourceLanguage ? '// ' : ''}languageVersion = JavaLanguageVersion.of(8)
}
}

''';
final sourceCompat =
'${commentSourceLanguage ? '// ' : ''}sourceCompatibility = JavaVersion.VERSION_$jvmTargetValue';
final targetCompat =
'${commentSourceLanguage ? '// ' : ''}targetCompatibility = JavaVersion.VERSION_$jvmTargetValue';
final namespace =
' ${commentNamespace ? '// ' : ''}namespace = "$_defaultFakeNamespace"';
final kotlinJvmTarget = useDeprecatedJvmTargetStyle
? '$jvmTargetValue'
: 'JavaVersion.VERSION_$kotlinJvmValue.toString()';
final kotlinConfig =
'''
${commentKotlinOptions ? '//' : ''}kotlinOptions {
${commentKotlinOptions ? '//' : ''}jvmTarget = $kotlinJvmTarget
${commentKotlinOptions ? '//' : ''}}''';

buildGradle.writeAsStringSync('''
group = "dev.flutter.plugins.fake"
version = "1.0-SNAPSHOT"

buildscript {
repositories {
google()
mavenCentral()
}
}

apply plugin: 'com.android.library'

${includeLanguageVersion ? javaSection : ''}
android {
${includeNamespace ? namespace : ''}
compileSdk = $compileSdk

defaultConfig {
minSdk = 30
}
${warningsConfigured ? warningConfig : ''}
compileOptions {
${includeSourceCompat ? sourceCompat : ''}
${includeTargetCompat ? targetCompat : ''}
}
${includeKotlinOptions ? kotlinConfig : ''}
testOptions {
unitTests {
isIncludeAndroidResources = true
}
}
}

dependencies {
implementation("fake.package:fake:1.0.0")
}
''');
}

/// Writes a fake android/build.gradle file for an example [package] with the
/// given options.
// TODO(stuartmorgan): Once all packages are migrated to Kotlin, remove all
Expand Down Expand Up @@ -542,32 +639,65 @@ flutter {
);
});

test('fails when build.gradle has no java compatibility version', () async {
final RepositoryPackage package = createFakePlugin(
'a_plugin',
packagesDir,
examples: <String>[],
);
writeFakeGroovyPluginBuildGradle(package);
writeFakeManifest(package);
test(
'fails when build.gradle has no java compatibility version - groovy',
() async {
final RepositoryPackage package = createFakePlugin(
'a_plugin',
packagesDir,
examples: <String>[],
);
writeFakeGroovyPluginBuildGradle(package);
writeFakeManifest(package);

Error? commandError;
final List<String> output = await runCapturingPrint(
runner,
<String>['gradle-check'],
errorHandler: (Error e) {
commandError = e;
},
);
Error? commandError;
final List<String> output = await runCapturingPrint(
runner,
<String>['gradle-check'],
errorHandler: (Error e) {
commandError = e;
},
);

expect(commandError, isA<ToolExit>());
expect(
output,
containsAllInOrder(<Matcher>[
contains(groovyJavaIncompatabilityIndicator),
]),
);
});
expect(commandError, isA<ToolExit>());
expect(
output,
containsAllInOrder(<Matcher>[
contains(groovyJavaIncompatabilityIndicator),
]),
);
},
);

test(
'fails when build.gradle has no java compatibility version - kotlin',
() async {
final RepositoryPackage package = createFakePlugin(
'a_plugin',
packagesDir,
examples: <String>[],
);
writeFakeKotlinPluginBuildGradle(package);
writeFakeManifest(package);

Error? commandError;
final List<String> output = await runCapturingPrint(
runner,
<String>['gradle-check'],
errorHandler: (Error e) {
commandError = e;
},
);

expect(commandError, isA<ToolExit>());
expect(
output,
containsAllInOrder(<Matcher>[
contains(kotlinJavaIncompatabilityIndicator),
]),
);
},
);

test(
'fails when sourceCompatibility is provided with out targetCompatibility',
Expand Down Expand Up @@ -774,7 +904,7 @@ flutter {
test('does not require java version in examples - kotlin', () async {
const pluginName = 'a_plugin';
final RepositoryPackage package = createFakePlugin(pluginName, packagesDir);
writeFakeGroovyPluginBuildGradle(package, includeLanguageVersion: true);
writeFakeKotlinPluginBuildGradle(package, includeLanguageVersion: true);
writeFakeManifest(package);
final RepositoryPackage example = package.getExamples().first;
writeFakeKotlinExampleBuildGradles(example, pluginName: pluginName);
Expand Down Expand Up @@ -888,7 +1018,7 @@ flutter {
},
);

test('fails when namespace is missing', () async {
test('fails when namespace is missing - groovy', () async {
final RepositoryPackage package = createFakePlugin(
'a_plugin',
packagesDir,
Expand Down Expand Up @@ -919,6 +1049,37 @@ flutter {
);
});

test('fails when namespace is missing - kotlin', () async {
final RepositoryPackage package = createFakePlugin(
'a_plugin',
packagesDir,
examples: <String>[],
);
writeFakeKotlinPluginBuildGradle(
package,
includeLanguageVersion: true,
includeNamespace: false,
);
writeFakeManifest(package);

Error? commandError;
final List<String> output = await runCapturingPrint(
runner,
<String>['gradle-check'],
errorHandler: (Error e) {
commandError = e;
},
);

expect(commandError, isA<ToolExit>());
expect(
output,
containsAllInOrder(<Matcher>[
contains('build.gradle.kts must set a "namespace"'),
]),
);
});

test('fails when namespace is missing from example - groovy', () async {
const pluginName = 'a_plugin';
final RepositoryPackage package = createFakePlugin(pluginName, packagesDir);
Expand Down Expand Up @@ -953,7 +1114,7 @@ flutter {
test('fails when namespace is missing from example - kotlin', () async {
const pluginName = 'a_plugin';
final RepositoryPackage package = createFakePlugin(pluginName, packagesDir);
writeFakeGroovyPluginBuildGradle(package, includeLanguageVersion: true);
writeFakeKotlinPluginBuildGradle(package, includeLanguageVersion: true);
writeFakeManifest(package);
final RepositoryPackage example = package.getExamples().first;
writeFakeKotlinExampleBuildGradles(
Expand Down
Loading