diff --git a/packages/flutter_tools/lib/src/android/gradle.dart b/packages/flutter_tools/lib/src/android/gradle.dart index d6d4e41c16..920eea92eb 100644 --- a/packages/flutter_tools/lib/src/android/gradle.dart +++ b/packages/flutter_tools/lib/src/android/gradle.dart @@ -429,7 +429,7 @@ Future _buildGradleProjectV2( command.add('-Pfilesystem-roots=${buildInfo.fileSystemRoots.join('|')}'); if (buildInfo.fileSystemScheme != null) command.add('-Pfilesystem-scheme=${buildInfo.fileSystemScheme}'); - if (buildInfo.buildSharedLibrary && androidSdk.ndk != null) { + if (buildInfo.buildSharedLibrary) { command.add('-Pbuild-shared-library=true'); } if (buildInfo.targetPlatform != null) diff --git a/packages/flutter_tools/lib/src/base/build.dart b/packages/flutter_tools/lib/src/base/build.dart index 0b35c07ab4..418f685c08 100644 --- a/packages/flutter_tools/lib/src/base/build.dart +++ b/packages/flutter_tools/lib/src/base/build.dart @@ -6,7 +6,6 @@ import 'dart:async'; import 'package:meta/meta.dart'; -import '../android/android_sdk.dart'; import '../artifacts.dart'; import '../build_info.dart'; import '../bundle.dart'; @@ -101,19 +100,6 @@ class AOTSnapshotter { if (platform == TargetPlatform.ios) buildSharedLibrary = false; - if (buildSharedLibrary && androidSdk.ndk == null) { - final String explanation = AndroidNdk.explainMissingNdk(androidSdk.directory); - printError( - 'Could not find NDK in Android SDK at ${androidSdk.directory}:\n' - '\n' - ' $explanation\n' - '\n' - 'Unable to build with --build-shared-library\n' - 'To install the NDK, see instructions at https://developer.android.com/ndk/guides/' - ); - return 1; - } - final PackageMap packageMap = PackageMap(packagesPath); final String packageMapError = packageMap.checkValid(); if (packageMapError != null) { @@ -141,11 +127,16 @@ class AOTSnapshotter { } final String assembly = fs.path.join(outputDir.path, 'snapshot_assembly.S'); - if (buildSharedLibrary || platform == TargetPlatform.ios) { + if (platform == TargetPlatform.ios) { // Assembly AOT snapshot. outputPaths.add(assembly); genSnapshotArgs.add('--snapshot_kind=app-aot-assembly'); genSnapshotArgs.add('--assembly=$assembly'); + } else if (buildSharedLibrary) { + final String aotSharedLibrary = fs.path.join(outputDir.path, 'app.so'); + outputPaths.add(aotSharedLibrary); + genSnapshotArgs.add('--snapshot_kind=app-aot-elf'); + genSnapshotArgs.add('--assembly=$aotSharedLibrary'); } else { // Blob AOT snapshot. final String vmSnapshotData = fs.path.join(outputDir.path, 'vm_snapshot_data'); @@ -224,12 +215,6 @@ class AOTSnapshotter { final RunResult result = await _buildIosFramework(iosArch: iosArch, assemblyPath: assembly, outputPath: outputDir.path); if (result.exitCode != 0) return result.exitCode; - } else if (buildSharedLibrary) { - final RunResult result = await _buildAndroidSharedLibrary(assemblyPath: assembly, outputPath: outputDir.path); - if (result.exitCode != 0) { - printError('Failed to build AOT snapshot. Compiler terminated with exit code ${result.exitCode}'); - return result.exitCode; - } } // Compute and record build fingerprint. @@ -273,25 +258,6 @@ class AOTSnapshotter { return linkResult; } - /// Builds an Android shared library at [outputPath]/app.so from the assembly - /// source at [assemblyPath]. - Future _buildAndroidSharedLibrary({ - @required String assemblyPath, - @required String outputPath, - }) async { - // A word of warning: Instead of compiling via two steps, to a .o file and - // then to a .so file we use only one command. When using two commands - // gcc will end up putting a .eh_frame and a .debug_frame into the shared - // library. Without stripping .debug_frame afterwards, unwinding tools - // based upon libunwind use just one and ignore the contents of the other - // (which causes it to not look into the other section and therefore not - // find the correct unwinding information). - final String assemblySo = fs.path.join(outputPath, 'app.so'); - return await runCheckedAsync([androidSdk.ndk.compiler] - ..addAll(androidSdk.ndk.compilerArgs) - ..addAll([ '-shared', '-nostdlib', '-o', assemblySo, assemblyPath ])); - } - /// Compiles a Dart file to kernel. /// /// Returns the output kernel file path, or null on failure.