Commit 4d0e6984 authored by Jason Simmons's avatar Jason Simmons

Build tool support for Android x86 targets in 32- or 64-bit modes (#3761)

parent a9993664
d85ead8ec2556739924282e2b3f77ff077a45820 86837edd4ecbe5d28f16a770dff40a239f5b40b7
...@@ -49,23 +49,49 @@ class AndroidDevice extends Device { ...@@ -49,23 +49,49 @@ class AndroidDevice extends Device {
final String modelID; final String modelID;
final String deviceCodeName; final String deviceCodeName;
Map<String, String> _properties;
bool _isLocalEmulator; bool _isLocalEmulator;
TargetPlatform _platform;
String _getProperty(String name) {
if (_properties == null) {
String getpropOutput = runCheckedSync(adbCommandForDevice(<String>['shell', 'getprop']));
RegExp propertyExp = new RegExp(r'\[(.*?)\]: \[(.*?)\]');
_properties = <String, String>{};
for (Match m in propertyExp.allMatches(getpropOutput)) {
_properties[m.group(1)] = m.group(2);
}
}
return _properties[name];
}
@override @override
bool get isLocalEmulator { bool get isLocalEmulator {
if (_isLocalEmulator == null) { if (_isLocalEmulator == null) {
String characteristics = _getProperty('ro.build.characteristics');
_isLocalEmulator = characteristics != null && characteristics.contains('emulator');
}
return _isLocalEmulator;
}
@override
TargetPlatform get platform {
if (_platform == null) {
// http://developer.android.com/ndk/guides/abis.html (x86, armeabi-v7a, ...) // http://developer.android.com/ndk/guides/abis.html (x86, armeabi-v7a, ...)
try { switch (_getProperty('ro.product.cpu.abi')) {
String value = runCheckedSync(adbCommandForDevice( case 'x86_64':
<String>['shell', 'getprop', 'ro.product.cpu.abi'] _platform = TargetPlatform.android_x64;
)); break;
_isLocalEmulator = value.startsWith('x86'); case 'x86':
} catch (error) { _platform = TargetPlatform.android_x86;
_isLocalEmulator = false; break;
default:
_platform = TargetPlatform.android_arm;
break;
} }
} }
return _isLocalEmulator; return _platform;
} }
_AdbLogReader _logReader; _AdbLogReader _logReader;
...@@ -123,9 +149,7 @@ class AndroidDevice extends Device { ...@@ -123,9 +149,7 @@ class AndroidDevice extends Device {
runCheckedSync(<String>[androidSdk.adbPath, 'start-server']); runCheckedSync(<String>[androidSdk.adbPath, 'start-server']);
// Sample output: '22' // Sample output: '22'
String sdkVersion = runCheckedSync( String sdkVersion = _getProperty('ro.build.version.sdk');
adbCommandForDevice(<String>['shell', 'getprop', 'ro.build.version.sdk'])
).trimRight();
int sdkVersionParsed = int.parse(sdkVersion, onError: (String source) => null); int sdkVersionParsed = int.parse(sdkVersion, onError: (String source) => null);
if (sdkVersionParsed == null) { if (sdkVersionParsed == null) {
...@@ -333,9 +357,6 @@ class AndroidDevice extends Device { ...@@ -333,9 +357,6 @@ class AndroidDevice extends Device {
return runCommandAndStreamOutput(command).then((int exitCode) => exitCode == 0); return runCommandAndStreamOutput(command).then((int exitCode) => exitCode == 0);
} }
@override
TargetPlatform get platform => isLocalEmulator ? TargetPlatform.android_x64 : TargetPlatform.android_arm;
@override @override
void clearLogs() { void clearLogs() {
runSync(adbCommandForDevice(<String>['logcat', '-c'])); runSync(adbCommandForDevice(<String>['logcat', '-c']));
......
...@@ -103,6 +103,7 @@ ApplicationPackage getApplicationPackageForPlatform(TargetPlatform platform) { ...@@ -103,6 +103,7 @@ ApplicationPackage getApplicationPackageForPlatform(TargetPlatform platform) {
switch (platform) { switch (platform) {
case TargetPlatform.android_arm: case TargetPlatform.android_arm:
case TargetPlatform.android_x64: case TargetPlatform.android_x64:
case TargetPlatform.android_x86:
return new AndroidApk.fromCurrentDirectory(); return new AndroidApk.fromCurrentDirectory();
case TargetPlatform.ios: case TargetPlatform.ios:
return new IOSApp.fromCurrentDirectory(); return new IOSApp.fromCurrentDirectory();
...@@ -122,6 +123,7 @@ class ApplicationPackageStore { ...@@ -122,6 +123,7 @@ class ApplicationPackageStore {
switch (platform) { switch (platform) {
case TargetPlatform.android_arm: case TargetPlatform.android_arm:
case TargetPlatform.android_x64: case TargetPlatform.android_x64:
case TargetPlatform.android_x86:
android ??= new AndroidApk.fromCurrentDirectory(); android ??= new AndroidApk.fromCurrentDirectory();
return android; return android;
case TargetPlatform.ios: case TargetPlatform.ios:
......
...@@ -41,6 +41,7 @@ String getNameForHostPlatform(HostPlatform platform) { ...@@ -41,6 +41,7 @@ String getNameForHostPlatform(HostPlatform platform) {
enum TargetPlatform { enum TargetPlatform {
android_arm, android_arm,
android_x64, android_x64,
android_x86,
ios, ios,
darwin_x64, darwin_x64,
linux_x64 linux_x64
......
...@@ -192,7 +192,8 @@ class FlutterEngine { ...@@ -192,7 +192,8 @@ class FlutterEngine {
'android-arm', 'android-arm',
'android-arm-profile', 'android-arm-profile',
'android-arm-release', 'android-arm-release',
'android-x64' 'android-x64',
'android-x86',
]; ];
if (Platform.isMacOS) if (Platform.isMacOS)
......
...@@ -261,6 +261,21 @@ class BuildApkCommand extends FlutterCommand { ...@@ -261,6 +261,21 @@ class BuildApkCommand extends FlutterCommand {
} }
} }
// Return the directory name within the APK that is used for native code libraries
// on the given platform.
String getAbiDirectory(TargetPlatform platform) {
switch (platform) {
case TargetPlatform.android_arm:
return 'armeabi-v7a';
case TargetPlatform.android_x64:
return 'x86_64';
case TargetPlatform.android_x86:
return 'x86';
default:
throw new Exception('Unsupported platform.');
}
}
Future<_ApkComponents> _findApkComponents( Future<_ApkComponents> _findApkComponents(
TargetPlatform platform, TargetPlatform platform,
BuildMode buildMode, BuildMode buildMode,
...@@ -274,7 +289,7 @@ Future<_ApkComponents> _findApkComponents( ...@@ -274,7 +289,7 @@ Future<_ApkComponents> _findApkComponents(
components.extraFiles = extraFiles != null ? extraFiles : <String, File>{}; components.extraFiles = extraFiles != null ? extraFiles : <String, File>{};
if (tools.isLocalEngine) { if (tools.isLocalEngine) {
String abiDir = platform == TargetPlatform.android_arm ? 'armeabi-v7a' : 'x86_64'; String abiDir = getAbiDirectory(platform);
String enginePath = tools.engineSrcPath; String enginePath = tools.engineSrcPath;
String buildDir = tools.getEngineArtifactsDirectory(platform, buildMode).path; String buildDir = tools.getEngineArtifactsDirectory(platform, buildMode).path;
...@@ -348,7 +363,7 @@ int _buildApk( ...@@ -348,7 +363,7 @@ int _buildApk(
_AssetBuilder artifactBuilder = new _AssetBuilder(tempDir, 'artifacts'); _AssetBuilder artifactBuilder = new _AssetBuilder(tempDir, 'artifacts');
artifactBuilder.add(classesDex, 'classes.dex'); artifactBuilder.add(classesDex, 'classes.dex');
String abiDir = platform == TargetPlatform.android_arm ? 'armeabi-v7a' : 'x86_64'; String abiDir = getAbiDirectory(platform);
artifactBuilder.add(components.libSkyShell, 'lib/$abiDir/libsky_shell.so'); artifactBuilder.add(components.libSkyShell, 'lib/$abiDir/libsky_shell.so');
for (String relativePath in components.extraFiles.keys) for (String relativePath in components.extraFiles.keys)
......
...@@ -144,10 +144,9 @@ class ToolConfiguration { ...@@ -144,10 +144,9 @@ class ToolConfiguration {
switch (platform) { switch (platform) {
case TargetPlatform.android_arm: case TargetPlatform.android_arm:
type = 'android';
break;
case TargetPlatform.android_x64: case TargetPlatform.android_x64:
type = 'android_sim'; case TargetPlatform.android_x86:
type = 'android';
break; break;
// TODO(devoncarew): We will need an ios vs ios_x86 target (for ios vs. ios_sim). // TODO(devoncarew): We will need an ios vs ios_x86 target (for ios vs. ios_sim).
...@@ -166,6 +165,18 @@ class ToolConfiguration { ...@@ -166,6 +165,18 @@ class ToolConfiguration {
if (isAotBuildMode(mode)) if (isAotBuildMode(mode))
buildOutputPath += '_Deploy'; buildOutputPath += '_Deploy';
// Add a suffix for the target architecture.
switch (platform) {
case TargetPlatform.android_x64:
buildOutputPath += '_x64';
break;
case TargetPlatform.android_x86:
buildOutputPath += '_x86';
break;
default:
break;
}
return new Directory(path.join(engineSrcPath, buildOutputPath)); return new Directory(path.join(engineSrcPath, buildOutputPath));
} else { } else {
String suffix = mode != BuildMode.debug ? '-${getModeName(mode)}' : ''; String suffix = mode != BuildMode.debug ? '-${getModeName(mode)}' : '';
......
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