From 910adba1bf2cacca68585649bc24df331dc6208c Mon Sep 17 00:00:00 2001 From: Emmanuel Garcia Date: Tue, 17 Aug 2021 18:26:34 -0700 Subject: [PATCH 1/3] Use Android linter from cmdline-tools --- DEPS | 11 + .../flutter/app/FlutterActivityDelegate.java | 6 +- .../embedding/android/FlutterImageView.java | 1 + .../android/FlutterActivityTest.java | 1 + tools/android_lint/bin/main.dart | 66 +--- tools/android_lint/project.xml | 328 +++++++++--------- 6 files changed, 192 insertions(+), 221 deletions(-) diff --git a/DEPS b/DEPS index 71f40f1585fd7..56173c05dd695 100644 --- a/DEPS +++ b/DEPS @@ -513,6 +513,17 @@ deps = { 'dep_type': 'cipd', }, + 'src/third_party/android_tools/sdk/cmdline-tools': { + 'packages': [ + { + 'package': 'flutter/android/sdk/cmdline-tools', + 'version': 'latest', + } + ], + 'condition': 'download_android_deps', + 'dep_type': 'cipd', + }, + 'src/third_party/android_tools/sdk/licenses': { 'packages': [ { diff --git a/shell/platform/android/io/flutter/app/FlutterActivityDelegate.java b/shell/platform/android/io/flutter/app/FlutterActivityDelegate.java index cdb0db92b8dba..0fe692c49c6c7 100644 --- a/shell/platform/android/io/flutter/app/FlutterActivityDelegate.java +++ b/shell/platform/android/io/flutter/app/FlutterActivityDelegate.java @@ -43,7 +43,7 @@ * The most obvious example of when this may come in handy is if an application wishes to subclass * the Android v4 support library's {@code FragmentActivity}. * - *

Usage:

+ *

Usage: * *

To wire this class up to your activity, simply forward the events defined in {@link * FlutterActivityEvents} from your activity to an instance of this class. Optionally, you can make @@ -425,9 +425,7 @@ private Boolean showSplashScreenUntilFirstFrame() { ActivityInfo activityInfo = activity .getPackageManager() - .getActivityInfo( - activity.getComponentName(), - PackageManager.GET_META_DATA | PackageManager.GET_ACTIVITIES); + .getActivityInfo(activity.getComponentName(), PackageManager.GET_META_DATA); Bundle metadata = activityInfo.metaData; return metadata != null && metadata.getBoolean(SPLASH_SCREEN_META_DATA_KEY); } catch (NameNotFoundException e) { diff --git a/shell/platform/android/io/flutter/embedding/android/FlutterImageView.java b/shell/platform/android/io/flutter/embedding/android/FlutterImageView.java index 4c647142e9e3a..d4f21b835501c 100644 --- a/shell/platform/android/io/flutter/embedding/android/FlutterImageView.java +++ b/shell/platform/android/io/flutter/embedding/android/FlutterImageView.java @@ -99,6 +99,7 @@ private static void logW(String format, Object... args) { } @TargetApi(19) + @SuppressLint("WrongConstant") // RGBA_8888 is a valid constant. @NonNull private static ImageReader createImageReader(int width, int height) { if (width <= 0) { diff --git a/shell/platform/android/test/io/flutter/embedding/android/FlutterActivityTest.java b/shell/platform/android/test/io/flutter/embedding/android/FlutterActivityTest.java index b88460b3cb423..8fc08576111c4 100644 --- a/shell/platform/android/test/io/flutter/embedding/android/FlutterActivityTest.java +++ b/shell/platform/android/test/io/flutter/embedding/android/FlutterActivityTest.java @@ -439,6 +439,7 @@ public void itWithMetadataWithoutSplashScreenResourceKeyDoesNotProvideSplashScre static class FlutterActivityWithProvidedEngine extends FlutterActivity { @Override protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); super.delegate = new FlutterActivityAndFragmentDelegate(this); super.delegate.setupFlutterEngine(); } diff --git a/tools/android_lint/bin/main.dart b/tools/android_lint/bin/main.dart index e71e3d64832d7..aec851f3a52ae 100644 --- a/tools/android_lint/bin/main.dart +++ b/tools/android_lint/bin/main.dart @@ -27,7 +27,6 @@ const LocalProcessManager processManager = LocalProcessManager(); /// Java 1.8. Future main(List args) async { final ArgParser argParser = setupOptions(); - await checkJava1_8(); final int exitCode = await runLint(argParser, argParser.parse(args)); exit(exitCode); } @@ -74,7 +73,7 @@ Future runLint(ArgParser argParser, ArgResults argResults) async { - + '''); for (final FileSystemEntity entity in androidDir.listSync(recursive: true)) { @@ -89,12 +88,11 @@ Future runLint(ArgParser argParser, ArgResults argResults) async { '''); await projectXml.close(); - print('Wrote project.xml, starting lint...'); final List lintArgs = [ - path.join(androidSdkDir.path, 'tools', 'bin', 'lint'), - '--project', - projectXmlPath, + path.join(androidSdkDir.path, 'cmdline-tools', 'bin', 'lint'), + '--project', projectXmlPath, + '--compile-sdk-version', '31', '--showall', '--exitcode', // Set non-zero exit code on errors '-Wall', @@ -106,14 +104,13 @@ Future runLint(ArgParser argParser, ArgResults argResults) async { if (html) { lintArgs.addAll(['--html', argResults['out'] as String]); } - final String? javaHome = await getJavaHome(); + final String javahome = getJavaHome(inArgument); + print('Using JAVA_HOME=$javahome'); final Process lintProcess = await processManager.start( lintArgs, - environment: javaHome != null - ? { - 'JAVA_HOME': javaHome, - } - : null, + environment: { + 'JAVA_HOME': javahome, + }, ); lintProcess.stdout.pipe(stdout); lintProcess.stderr.pipe(stderr); @@ -166,50 +163,11 @@ ArgParser setupOptions() { return argParser; } -/// On macOS, we can try to find Java 1.8. -/// -/// Otherwise, default to whatever JAVA_HOME is already. -Future getJavaHome() async { +String getJavaHome(String src) { if (Platform.isMacOS) { - final ProcessResult result = await processManager.run( - ['/usr/libexec/java_home', '-v', '1.8', '-F'], - ); - if (result.exitCode == 0) { - return (result.stdout as String).trim(); - } - } - return Platform.environment['JAVA_HOME']; -} - -/// Checks that `java` points to Java 1.8. -/// -/// The SDK lint tool may not work with Java > 1.8. -Future checkJava1_8() async { - print('Checking Java version...'); - - if (Platform.isMacOS) { - final ProcessResult result = await processManager.run( - ['/usr/libexec/java_home', '-v', '1.8', '-F'], - ); - if (result.exitCode != 0) { - print('Java 1.8 not available - the linter may not work properly.'); - } - return; - } - final ProcessResult javaResult = await processManager.run( - ['java', '-version'], - ); - if (javaResult.exitCode != 0) { - print('Could not run "java -version". ' - 'Ensure Java is installed and available on your path.'); - print(javaResult.stderr); - } - // `java -version` writes to stderr. - final String javaVersionStdout = javaResult.stderr as String; - if (!javaVersionStdout.contains('"1.8')) { - print('The Android SDK tools may not work properly with your Java version. ' - 'If this process fails, please retry using Java 1.8.'); + return path.normalize('$src/third_party/java/openjdk/Contents/Home/'); } + return path.normalize('$src/third_party/java/openjdk/'); } /// The root directory of this project. diff --git a/tools/android_lint/project.xml b/tools/android_lint/project.xml index 7ac27f2309285..12b7f1b90aa9b 100644 --- a/tools/android_lint/project.xml +++ b/tools/android_lint/project.xml @@ -2,188 +2,190 @@ - + - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - + + + + + - - - - - - + + + + - - - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + From 66a632d2530a9b4f9f83fa90905ddbdf12b1220e Mon Sep 17 00:00:00 2001 From: Emmanuel Garcia Date: Tue, 17 Aug 2021 20:58:48 -0700 Subject: [PATCH 2/3] import --- .../android/io/flutter/embedding/android/FlutterImageView.java | 1 + 1 file changed, 1 insertion(+) diff --git a/shell/platform/android/io/flutter/embedding/android/FlutterImageView.java b/shell/platform/android/io/flutter/embedding/android/FlutterImageView.java index d4f21b835501c..843284c99338c 100644 --- a/shell/platform/android/io/flutter/embedding/android/FlutterImageView.java +++ b/shell/platform/android/io/flutter/embedding/android/FlutterImageView.java @@ -4,6 +4,7 @@ package io.flutter.embedding.android; +import android.annotation.SuppressLint; import android.annotation.TargetApi; import android.content.Context; import android.graphics.Bitmap; From 0655587f13d2392e93c30799b355f5b3bcab85c0 Mon Sep 17 00:00:00 2001 From: Emmanuel Garcia Date: Tue, 17 Aug 2021 21:10:27 -0700 Subject: [PATCH 3/3] Fix test --- .../test/io/flutter/embedding/android/FlutterActivityTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/shell/platform/android/test/io/flutter/embedding/android/FlutterActivityTest.java b/shell/platform/android/test/io/flutter/embedding/android/FlutterActivityTest.java index 8fc08576111c4..29eb3ea93d15e 100644 --- a/shell/platform/android/test/io/flutter/embedding/android/FlutterActivityTest.java +++ b/shell/platform/android/test/io/flutter/embedding/android/FlutterActivityTest.java @@ -15,6 +15,7 @@ import static org.mockito.Mockito.when; import static org.robolectric.Shadows.shadowOf; +import android.annotation.SuppressLint; import android.annotation.TargetApi; import android.content.Context; import android.content.Intent; @@ -438,8 +439,8 @@ public void itWithMetadataWithoutSplashScreenResourceKeyDoesNotProvideSplashScre static class FlutterActivityWithProvidedEngine extends FlutterActivity { @Override + @SuppressLint("MissingSuperCall") protected void onCreate(@Nullable Bundle savedInstanceState) { - super.onCreate(savedInstanceState); super.delegate = new FlutterActivityAndFragmentDelegate(this); super.delegate.setupFlutterEngine(); }