Skip to content

Commit

Permalink
Standardize how Java8 is set in gradle files (flutter#80600)
Browse files Browse the repository at this point in the history
  • Loading branch information
Emmanuel Garcia authored Apr 20, 2021
1 parent 0c1652f commit 42f21fd
Show file tree
Hide file tree
Showing 42 changed files with 326 additions and 29 deletions.
5 changes: 5 additions & 0 deletions dev/benchmarks/complex_layout/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 30

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

defaultConfig {
minSdkVersion 16
targetSdkVersion 30
Expand Down
5 changes: 5 additions & 0 deletions dev/benchmarks/macrobenchmarks/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 30

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

defaultConfig {
applicationId "com.example.macrobenchmarks"
minSdkVersion 16
Expand Down
5 changes: 5 additions & 0 deletions dev/benchmarks/microbenchmarks/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 30

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

defaultConfig {
minSdkVersion 16
targetSdkVersion 30
Expand Down
17 changes: 10 additions & 7 deletions dev/benchmarks/multiple_flutters/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,18 @@ android {
self {
}
}

compileSdkVersion 30

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

kotlinOptions {
jvmTarget = '1.8'
}

defaultConfig {
applicationId "dev.flutter.multipleflutters"
minSdkVersion 24
Expand All @@ -31,13 +41,6 @@ android {
signingConfig debug.signingConfig
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}

dependencies {
Expand Down
5 changes: 5 additions & 0 deletions dev/benchmarks/platform_views_layout/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 30

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

defaultConfig {
minSdkVersion 16
targetSdkVersion 30
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 30

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

defaultConfig {
minSdkVersion 16
targetSdkVersion 30
Expand Down
5 changes: 5 additions & 0 deletions dev/benchmarks/test_apps/stocks/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 30

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

defaultConfig {
applicationId "io.flutter.examples.stocks"
minSdkVersion 16
Expand Down
2 changes: 1 addition & 1 deletion dev/devicelab/bin/tasks/build_aar_module_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ Future<void> main() async {
} catch (e) {
return TaskResult.failure(e.toString());
} finally {
rmTree(tempDir);
// rmTree(tempDir);
}
});
}
106 changes: 106 additions & 0 deletions dev/devicelab/bin/tasks/gradle_java8_compile_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:io';

import 'package:flutter_devicelab/framework/apk_utils.dart';
import 'package:flutter_devicelab/framework/framework.dart';
import 'package:flutter_devicelab/framework/task_result.dart';
import 'package:flutter_devicelab/framework/utils.dart';
import 'package:path/path.dart' as path;

Future<void> main() async {
await task(() async {
try {
await runPluginProjectTest((FlutterPluginProject pluginProject) async {

section('check main plugin file exists');
final File pluginMainKotlinFile = File(
path.join(
pluginProject.rootPath,
'android',
'src',
'main',
'kotlin',
path.join(
'com',
'example',
'aaa',
'AaaPlugin.kt',
),
),
);

if (!pluginMainKotlinFile.existsSync()) {
throw TaskResult.failure('Expected ${pluginMainKotlinFile.path} to exist, but it doesn\'t');
}

section('add java 8 feature');
pluginMainKotlinFile.writeAsStringSync(r'''
package com.example.aaa
import android.util.Log
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 java.util.HashMap
/** AaaPlugin */
class AaaPlugin: FlutterPlugin, MethodCallHandler {
init {
val map: HashMap<String, String> = HashMap<String, String>()
// getOrDefault is a JAVA8 feature.
Log.d("AaaPlugin", map.getOrDefault("foo", "baz"))
}
/// The MethodChannel that will the communication between Flutter and native Android
///
/// This local reference serves to register the plugin with the Flutter Engine and unregister it
/// when the Flutter Engine is detached from the Activity
private lateinit var channel : MethodChannel
override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
channel = MethodChannel(flutterPluginBinding.binaryMessenger, "aaa")
channel.setMethodCallHandler(this)
}
override fun onMethodCall(@NonNull call: MethodCall, @NonNull result: Result) {
if (call.method == "getPlatformVersion") {
result.success("Android ${android.os.Build.VERSION.RELEASE}")
} else {
result.notImplemented()
}
}
override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) {
channel.setMethodCallHandler(null)
}
}
''');

section('Compiles');
await inDirectory(pluginProject.exampleAndroidPath, () {
return flutter(
'build',
options: <String>[
'apk',
'--debug',
'--target-platform=android-arm'
],
);
});

});
return TaskResult.success(null);
} on TaskResult catch (taskResult) {
return taskResult;
} catch (e) {
return TaskResult.failure(e.toString());
}
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,19 @@ apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 30

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

kotlinOptions {
jvmTarget = '1.8'
}

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.abstract_method_smoke_test"
Expand All @@ -55,10 +59,6 @@ android {
signingConfig signingConfigs.debug
}
}

kotlinOptions {
jvmTarget = "1.8"
}
}

flutter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
compileSdkVersion 30

compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

defaultConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 30

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

kotlinOptions {
jvmTarget = '1.8'
}

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
compileSdkVersion 30

compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

defaultConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 30

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

defaultConfig {
minSdkVersion 16
targetSdkVersion 30
Expand Down
5 changes: 5 additions & 0 deletions dev/integration_tests/android_views/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 30

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "io.flutter.integration.platformviews"
Expand Down
5 changes: 5 additions & 0 deletions dev/integration_tests/channels/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 30

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

defaultConfig {
minSdkVersion 16
targetSdkVersion 30
Expand Down
5 changes: 5 additions & 0 deletions dev/integration_tests/external_ui/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 30

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

defaultConfig {
applicationId "io.flutter.externalui"
minSdkVersion 16
Expand Down
5 changes: 5 additions & 0 deletions dev/integration_tests/flavors/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 30

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

defaultConfig {
applicationId "com.yourcompany.flavors"
minSdkVersion 16
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 30

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

defaultConfig {
applicationId "io.flutter.demo.gallery"
minSdkVersion 16
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 30

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

defaultConfig {
applicationId "com.yourcompany.flavors"
minSdkVersion 21
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 30

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "io.flutter.integration.platformviews"
Expand Down
Loading

0 comments on commit 42f21fd

Please sign in to comment.