Commit 7b2367ed authored by Jakob Andersen's avatar Jakob Andersen Committed by GitHub

Remove legacy .apk build. (#8793)

* Remove legacy .apk build.

Print out an error message telling the user to upgrade the project if
it's not Gradle-based. Removed all the obvious traces of the legacy
build.

Added support for Dart VM kernel snapshots in Gradle builds.

Fixed Android installs to verify that the app is actually installed, and
not just rely on the presence of the .sha1 file.
parent 3fc7265a
......@@ -149,6 +149,11 @@ class FlutterPlugin implements Plugin<Project> {
project.compileDebugJavaWithJavac.dependsOn project.flutterBuildX86Jar
}
File kernel
if (project.hasProperty('kernel')) {
kernel = project.file(project.property('kernel'))
}
project.android.applicationVariants.all { variant ->
if (!["debug", "profile", "release"].contains(variant.name)) {
throw new GradleException("Build variant must be one of \"debug\", \"profile\", or \"release\" but was \"${variant.name}\"")
......@@ -161,6 +166,7 @@ class FlutterPlugin implements Plugin<Project> {
localEngine this.localEngine
localEngineSrcPath this.localEngineSrcPath
targetPath target
kernelFile kernel
sourceDir project.file(project.flutter.source)
intermediateDir project.file("${project.buildDir}/${AndroidProject.FD_INTERMEDIATES}/flutter/${variant.name}")
}
......@@ -189,6 +195,8 @@ class FlutterTask extends DefaultTask {
String localEngineSrcPath
@Input
String targetPath
@Optional @InputFile
File kernelFile
File sourceDir
......@@ -282,6 +290,9 @@ class FlutterTask extends DefaultTask {
}
args "build", "flx"
args "--target", targetPath
if (kernelFile != null) {
args "--kernel", kernelFile.absolutePath
}
args "--output-file", "${intermediateDir}/app.flx"
args "--no-include-roboto-fonts"
if (buildMode != "debug") {
......
......@@ -15,7 +15,6 @@ import '../base/process.dart';
import '../base/process_manager.dart';
import '../build_info.dart';
import '../commands/build_apk.dart';
import '../devfs.dart';
import '../device.dart';
import '../globals.dart';
import '../protocol_discovery.dart';
......@@ -263,6 +262,24 @@ class AndroidDevice extends Device {
return true;
}
bool _installLatestApp(ApplicationPackage package) {
if (isAppInstalled(package)) {
if (isLatestBuildInstalled(package)) {
printStatus('Latest build already installed.');
return true;
}
printStatus('Uninstalling old version...');
if (!uninstallApp(package))
printError('Warning: uninstalling old version failed');
}
printTrace('Installing APK.');
if (!installApp(package)) {
printTrace('Error: Failed to install APK.');
return false;
}
return true;
}
@override
Future<LaunchResult> startApp(
ApplicationPackage package,
......@@ -271,7 +288,7 @@ class AndroidDevice extends Device {
String route,
DebuggingOptions debuggingOptions,
Map<String, dynamic> platformArgs,
DevFSContent kernelContent,
String kernelPath,
bool prebuiltApplication: false,
bool applicationNeedsRebuild: false,
}) async {
......@@ -288,8 +305,7 @@ class AndroidDevice extends Device {
await buildApk(targetPlatform,
target: mainPath,
buildMode: debuggingOptions.buildMode,
kernelContent: kernelContent,
applicationNeedsRebuild: applicationNeedsRebuild
kernelPath: kernelPath,
);
// Package has been built, so we can get the updated application ID and
// activity name from the .apk.
......@@ -299,21 +315,8 @@ class AndroidDevice extends Device {
printTrace("Stopping app '${package.name}' on $name.");
await stopApp(package);
if (isLatestBuildInstalled(package)) {
printStatus('Latest build already installed.');
} else {
if (isAppInstalled(package)) {
printStatus('Uninstalling old version...');
if (!uninstallApp(package))
printError('Warning: uninstalling old version failed');
}
printTrace('Installing APK.');
if (!installApp(package)) {
printTrace('Error: Failed to install APK.');
return new LaunchResult.failed();
}
}
if (!_installLatestApp(package))
return new LaunchResult.failed();
final bool traceStartup = platformArgs['trace-startup'] ?? false;
final AndroidApk apk = package;
......
......@@ -141,7 +141,7 @@ File ensureLocalProperties() {
return localProperties;
}
Future<Null> buildGradleProject(BuildMode buildMode, String target) async {
Future<Null> buildGradleProject(BuildMode buildMode, String target, String kernelPath) async {
final File localProperties = ensureLocalProperties();
// Update the local.properties file with the build mode.
// FlutterPlugin v1 reads local.properties to determine build mode. Plugin v2
......@@ -162,7 +162,7 @@ Future<Null> buildGradleProject(BuildMode buildMode, String target) async {
case FlutterPluginVersion.managed:
// Fall through. Managed plugin builds the same way as plugin v2.
case FlutterPluginVersion.v2:
return buildGradleProjectV2(gradle, buildModeName, target);
return buildGradleProjectV2(gradle, buildModeName, target, kernelPath);
}
}
......@@ -185,7 +185,7 @@ Future<Null> buildGradleProjectV1(String gradle) async {
printStatus('Built $gradleAppOutV1 (${getSizeAsMB(apkFile.lengthSync())}).');
}
Future<Null> buildGradleProjectV2(String gradle, String buildModeName, String target) async {
Future<Null> buildGradleProjectV2(String gradle, String buildModeName, String target, String kernelPath) async {
final String assembleTask = "assemble${toTitleCase(buildModeName)}";
// Run 'gradle assemble<BuildMode>'.
......@@ -203,6 +203,8 @@ Future<Null> buildGradleProjectV2(String gradle, String buildModeName, String ta
if (target != null) {
command.add('-Ptarget=$target');
}
if (kernelPath != null)
command.add('-Pkernel=$kernelPath');
command.add(assembleTask);
final int exitcode = await runCommandAndStreamOutput(
command,
......
......@@ -9,8 +9,6 @@ import 'build_info.dart';
import 'globals.dart';
enum Artifact {
chromiumDebugKeyStore,
classesDexJar,
icudtlDat,
libskyShellSo,
dartIoEntriesTxt,
......@@ -26,10 +24,6 @@ enum Artifact {
String _artifactToFileName(Artifact artifact) {
switch (artifact) {
case Artifact.chromiumDebugKeyStore:
return 'chromium-debug.keystore';
case Artifact.classesDexJar:
return 'classes.dex.jar';
case Artifact.icudtlDat:
return 'icudtl.dat';
case Artifact.libskyShellSo:
......@@ -104,8 +98,6 @@ class CachedArtifacts extends Artifacts {
String _getAndroidArtifactPath(Artifact artifact, TargetPlatform platform, BuildMode mode) {
final String engineDir = _getEngineArtifactsPath(platform, mode);
switch (artifact) {
case Artifact.chromiumDebugKeyStore:
case Artifact.classesDexJar:
case Artifact.icudtlDat:
case Artifact.libskyShellSo:
return fs.path.join(engineDir, _artifactToFileName(artifact));
......@@ -207,8 +199,6 @@ class LocalEngineArtifacts extends Artifacts {
@override
String getArtifactPath(Artifact artifact, [TargetPlatform platform, BuildMode mode]) {
switch (artifact) {
case Artifact.chromiumDebugKeyStore:
return fs.path.join(_engineSrcPath, 'build', 'android', 'ant', _artifactToFileName(artifact));
case Artifact.dartIoEntriesTxt:
return fs.path.join(_engineSrcPath, 'dart', 'runtime', 'bin', _artifactToFileName(artifact));
case Artifact.dartVmEntryPointsTxt:
......@@ -216,8 +206,6 @@ class LocalEngineArtifacts extends Artifacts {
return fs.path.join(_engineSrcPath, 'flutter', 'runtime', _artifactToFileName(artifact));
case Artifact.snapshotDart:
return fs.path.join(_engineSrcPath, 'flutter', 'lib', 'snapshot', _artifactToFileName(artifact));
case Artifact.classesDexJar:
return fs.path.join(engineOutPath, 'gen', 'flutter', 'shell', 'platform', 'android', 'android', _artifactToFileName(artifact));
case Artifact.libskyShellSo:
final String abi = _getAbiDirectory(platform);
return fs.path.join(engineOutPath, 'gen', 'flutter', 'shell', 'platform', 'android', 'android', fs.path.join('android', 'libs', abi, _artifactToFileName(artifact)));
......
......@@ -20,6 +20,7 @@ class BuildFlxCommand extends BuildSubCommand {
argParser.addOption('output-file', abbr: 'o', defaultsTo: defaultFlxOutputPath);
argParser.addOption('snapshot', defaultsTo: defaultSnapshotPath);
argParser.addOption('depfile', defaultsTo: defaultDepfilePath);
argParser.addOption('kernel');
argParser.addOption('working-dir', defaultsTo: getAssetBuildDirectory());
argParser.addFlag('include-roboto-fonts', defaultsTo: true);
argParser.addFlag('report-licensed-packages', help: 'Whether to report the names of all the packages that are included in the application\'s LICENSE file.', defaultsTo: false);
......@@ -49,6 +50,7 @@ class BuildFlxCommand extends BuildSubCommand {
depfilePath: argResults['depfile'],
privateKeyPath: argResults['private-key'],
workingDirPath: argResults['working-dir'],
kernelPath: argResults['kernel'],
precompiledSnapshot: argResults['precompiled'],
includeRobotoFonts: argResults['include-roboto-fonts'],
reportLicensedPackages: argResults['report-licensed-packages']
......
......@@ -13,7 +13,6 @@ import 'base/file_system.dart';
import 'base/port_scanner.dart';
import 'base/utils.dart';
import 'build_info.dart';
import 'devfs.dart';
import 'globals.dart';
import 'ios/devices.dart';
import 'ios/simulators.dart';
......@@ -209,7 +208,7 @@ abstract class Device {
String route,
DebuggingOptions debuggingOptions,
Map<String, dynamic> platformArgs,
DevFSContent kernelContent,
String kernelPath,
bool prebuiltApplication: false,
bool applicationNeedsRebuild: false
});
......
......@@ -21,7 +21,6 @@ const String defaultManifestPath = 'pubspec.yaml';
String get defaultFlxOutputPath => fs.path.join(getBuildDirectory(), 'app.flx');
String get defaultSnapshotPath => fs.path.join(getBuildDirectory(), 'snapshot_blob.bin');
String get defaultDepfilePath => fs.path.join(getBuildDirectory(), 'snapshot_blob.bin.d');
String get defaultKernelPath => fs.path.join(getBuildDirectory(), 'kernel_blob.bin');
const String defaultPrivateKeyPath = 'privatekey.der';
const String _kKernelKey = 'kernel_blob.bin';
......@@ -56,26 +55,6 @@ Future<int> createSnapshot({
return runCommandAndStreamOutput(args);
}
/// Build the flx in the build directory and return `localBundlePath` on success.
///
/// Return `null` on failure.
Future<String> buildFlx({
String mainPath: defaultMainPath,
DevFSContent kernelContent,
bool precompiledSnapshot: false,
bool includeRobotoFonts: true
}) async {
await build(
snapshotPath: defaultSnapshotPath,
outputPath: defaultFlxOutputPath,
mainPath: mainPath,
kernelContent: kernelContent,
precompiledSnapshot: precompiledSnapshot,
includeRobotoFonts: includeRobotoFonts
);
return defaultFlxOutputPath;
}
Future<Null> build({
String mainPath: defaultMainPath,
String manifestPath: defaultManifestPath,
......@@ -86,27 +65,17 @@ Future<Null> build({
String workingDirPath,
String packagesPath,
String kernelPath,
DevFSContent kernelContent,
bool precompiledSnapshot: false,
bool includeRobotoFonts: true,
bool reportLicensedPackages: false
}) async {
outputPath ??= defaultFlxOutputPath;
kernelPath ??= defaultKernelPath;
snapshotPath ??= defaultSnapshotPath;
depfilePath ??= defaultDepfilePath;
workingDirPath ??= getAssetBuildDirectory();
packagesPath ??= fs.path.absolute(PackageMap.globalPackagesPath);
File snapshotFile;
File kernelFile;
if (kernelContent != null) {
// TODO(danrubel) in the future, call the VM to generate this file
kernelFile = fs.file(kernelPath);
final IOSink sink = kernelFile.openWrite();
await sink.addStream(kernelContent.contentsAsStream());
sink.close();
}
if (!precompiledSnapshot) {
ensureDirectoryExists(snapshotPath);
......@@ -124,9 +93,13 @@ Future<Null> build({
snapshotFile = fs.file(snapshotPath);
}
DevFSContent kernelContent;
if (kernelPath != null)
kernelContent = new DevFSFileContent(fs.file(kernelPath));
return assemble(
manifestPath: manifestPath,
kernelFile: kernelFile,
kernelContent: kernelContent,
snapshotFile: snapshotFile,
outputPath: outputPath,
privateKeyPath: privateKeyPath,
......@@ -139,7 +112,7 @@ Future<Null> build({
Future<Null> assemble({
String manifestPath,
File kernelFile,
DevFSContent kernelContent,
File snapshotFile,
String outputPath,
String privateKeyPath: defaultPrivateKeyPath,
......@@ -172,8 +145,8 @@ Future<Null> assemble({
// Add all entries from the asset bundle.
zipBuilder.entries.addAll(assetBundle.entries);
if (kernelFile != null)
zipBuilder.entries[_kKernelKey] = new DevFSFileContent(kernelFile);
if (kernelContent != null)
zipBuilder.entries[_kKernelKey] = kernelContent;
if (snapshotFile != null)
zipBuilder.entries[_kSnapshotKey] = new DevFSFileContent(snapshotFile);
......
......@@ -6,7 +6,6 @@ import 'dart:async';
import '../application_package.dart';
import '../build_info.dart';
import '../devfs.dart';
import '../device.dart';
/// Read the log for a particular device.
......@@ -67,7 +66,7 @@ class FuchsiaDevice extends Device {
DebuggingOptions debuggingOptions,
Map<String, dynamic> platformArgs,
bool prebuiltApplication: false,
DevFSContent kernelContent,
String kernelPath,
bool applicationNeedsRebuild: false,
}) => new Future<Null>.error('unimplemented');
......
......@@ -13,7 +13,6 @@ import '../base/port_scanner.dart';
import '../base/process.dart';
import '../base/process_manager.dart';
import '../build_info.dart';
import '../devfs.dart';
import '../device.dart';
import '../doctor.dart';
import '../globals.dart';
......@@ -194,7 +193,7 @@ class IOSDevice extends Device {
DebuggingOptions debuggingOptions,
Map<String, dynamic> platformArgs,
bool prebuiltApplication: false,
DevFSContent kernelContent,
String kernelPath,
bool applicationNeedsRebuild: false,
}) async {
if (!prebuiltApplication) {
......
......@@ -15,7 +15,6 @@ import '../base/platform.dart';
import '../base/process.dart';
import '../base/process_manager.dart';
import '../build_info.dart';
import '../devfs.dart';
import '../device.dart';
import '../flx.dart' as flx;
import '../globals.dart';
......@@ -422,7 +421,7 @@ class IOSSimulator extends Device {
String route,
DebuggingOptions debuggingOptions,
Map<String, dynamic> platformArgs,
DevFSContent kernelContent,
String kernelPath,
bool prebuiltApplication: false,
bool applicationNeedsRebuild: false,
}) async {
......
......@@ -196,11 +196,6 @@ class HotRunner extends ResidentRunner {
final String modeName = getModeName(debuggingOptions.buildMode);
printStatus('Launching ${getDisplayPath(mainPath)} on ${device.name} in $modeName mode...');
// Include kernel code
DevFSContent kernelContent;
if (kernelFilePath != null)
kernelContent = new DevFSFileContent(fs.file(kernelFilePath));
// Start the application.
final Future<LaunchResult> futureResult = device.startApp(
package,
......@@ -210,7 +205,7 @@ class HotRunner extends ResidentRunner {
platformArgs: platformArgs,
route: route,
prebuiltApplication: prebuiltMode,
kernelContent: kernelContent,
kernelPath: kernelFilePath,
applicationNeedsRebuild: shouldBuild || hasDirtyDependencies()
);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment