Commit b38a6cbb authored by Michael Goderbauer's avatar Michael Goderbauer Committed by GitHub

Replace jarsigner with apksigner (#8154)

parent 15af4a04
...@@ -102,7 +102,7 @@ Instructions to update the Android Tools version that the bots download by execu ...@@ -102,7 +102,7 @@ Instructions to update the Android Tools version that the bots download by execu
The following packages are currently installed: The following packages are currently installed:
* Android SDK Tools * Android SDK Tools
* Android SDK platform-tools * Android SDK platform-tools
* Android SDK Build-tools 23.0.1 * Android SDK Build-tools 24.0.3
* Android 6.0 (API 23) * Android 6.0 (API 23)
* SDK Platform 23 * SDK Platform 23
* Extras * Extras
......
0d320c50b0ed188c7e1182388e2beb623a1d307d efeebca78800d6855e15a22c6087a54766d1d4e9
fa5ea0ca1e0c7c2e40914f3202c7545de4dbca9c 7eb88931c39c05a3b140da769e67c216d45db2b9
e5715e2cc0d5644a241a4b3281bfada92bc145c2 4b0d8fa0dcacd537330149332a28e033edfd3ca8
...@@ -24,6 +24,7 @@ const String kAndroidHome = 'ANDROID_HOME'; ...@@ -24,6 +24,7 @@ const String kAndroidHome = 'ANDROID_HOME';
// $ANDROID_HOME/build-tools/22.0.1/aapt // $ANDROID_HOME/build-tools/22.0.1/aapt
// $ANDROID_HOME/build-tools/23.0.2/aapt // $ANDROID_HOME/build-tools/23.0.2/aapt
// $ANDROID_HOME/build-tools/24.0.0-preview/aapt // $ANDROID_HOME/build-tools/24.0.0-preview/aapt
// $ANDROID_HOME/build-tools/25.0.2/apksigner
// $ANDROID_HOME/platforms/android-22/android.jar // $ANDROID_HOME/platforms/android-22/android.jar
// $ANDROID_HOME/platforms/android-23/android.jar // $ANDROID_HOME/platforms/android-23/android.jar
...@@ -225,6 +226,8 @@ class AndroidSdkVersion implements Comparable<AndroidSdkVersion> { ...@@ -225,6 +226,8 @@ class AndroidSdkVersion implements Comparable<AndroidSdkVersion> {
String get zipalignPath => getBuildToolsPath('zipalign'); String get zipalignPath => getBuildToolsPath('zipalign');
String get apksignerPath => getBuildToolsPath('apksigner');
List<String> validateSdkWellFormed() { List<String> validateSdkWellFormed() {
if (_exists(androidJarPath) != null) if (_exists(androidJarPath) != null)
return <String>[_exists(androidJarPath)]; return <String>[_exists(androidJarPath)];
...@@ -238,6 +241,9 @@ class AndroidSdkVersion implements Comparable<AndroidSdkVersion> { ...@@ -238,6 +241,9 @@ class AndroidSdkVersion implements Comparable<AndroidSdkVersion> {
if (_canRun(zipalignPath) != null) if (_canRun(zipalignPath) != null)
return <String>[_canRun(zipalignPath)]; return <String>[_canRun(zipalignPath)];
if (_canRun(apksignerPath) != null)
return <String>[_canRun(apksignerPath) + '\napksigner requires Android SDK Build Tools 24.0.3 or newer.'];
return <String>[]; return <String>[];
} }
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
import 'dart:async'; import 'dart:async';
import '../base/io.dart'; import '../base/io.dart';
import '../base/os.dart';
import '../base/platform.dart'; import '../base/platform.dart';
import '../base/process_manager.dart'; import '../base/process_manager.dart';
import '../doctor.dart'; import '../doctor.dart';
...@@ -63,11 +62,11 @@ class AndroidWorkflow extends DoctorValidator implements Workflow { ...@@ -63,11 +62,11 @@ class AndroidWorkflow extends DoctorValidator implements Workflow {
} }
List<String> validationResult = androidSdk.validateSdkWellFormed(); List<String> validationResult = androidSdk.validateSdkWellFormed();
// Empty result means SDK is well formated.
if (validationResult.isEmpty) { if (validationResult.isEmpty) {
// Empty result means SDK is well formatted.
// The SDK also requires a valid Java JDK installation.
const String _kJdkDownload = 'https://www.oracle.com/technetwork/java/javase/downloads/'; const String _kJdkDownload = 'https://www.oracle.com/technetwork/java/javase/downloads/';
String javaVersion; String javaVersion;
try { try {
...@@ -82,27 +81,20 @@ class AndroidWorkflow extends DoctorValidator implements Workflow { ...@@ -82,27 +81,20 @@ class AndroidWorkflow extends DoctorValidator implements Workflow {
} catch (error) { } catch (error) {
} }
if (javaVersion != null) { if (javaVersion == null) {
messages.add(new ValidationMessage(javaVersion));
if (os.which('jarsigner') == null) {
messages.add(new ValidationMessage.error(
'The jarsigner utility was not found; this is used to build Android APKs. You may need to install\n'
'or re-install the Java JDK: $_kJdkDownload.'
));
} else {
type = ValidationType.installed;
}
} else {
messages.add(new ValidationMessage.error( messages.add(new ValidationMessage.error(
'No Java Development Kit (JDK) found; you can download the JDK from $_kJdkDownload.' 'No Java Development Kit (JDK) found; you can download the JDK from $_kJdkDownload.'
)); ));
} else {
type = ValidationType.installed;
} }
} else { } else {
messages.addAll(validationResult.map((String message) { messages.addAll(validationResult.map((String message) {
return new ValidationMessage.error(message); return new ValidationMessage.error(message);
})); }));
messages.add(new ValidationMessage('Try re-installing or updating your Android SDK.')); messages.add(new ValidationMessage(
'Try re-installing or updating your Android SDK,\n'
'visit https://flutter.io/setup/#android-setup for detailed instructions.'));
} }
} }
......
...@@ -10,7 +10,6 @@ import '../android/gradle.dart'; ...@@ -10,7 +10,6 @@ import '../android/gradle.dart';
import '../base/common.dart'; import '../base/common.dart';
import '../base/file_system.dart'; import '../base/file_system.dart';
import '../base/logger.dart'; import '../base/logger.dart';
import '../base/os.dart';
import '../base/process.dart'; import '../base/process.dart';
import '../base/process_manager.dart'; import '../base/process_manager.dart';
import '../base/utils.dart'; import '../base/utils.dart';
...@@ -68,14 +67,14 @@ class _ApkBuilder { ...@@ -68,14 +67,14 @@ class _ApkBuilder {
File _aapt; File _aapt;
File _dx; File _dx;
File _zipalign; File _zipalign;
File _jarsigner; File _apksigner;
_ApkBuilder(this.sdk) { _ApkBuilder(this.sdk) {
_androidJar = fs.file(sdk.androidJarPath); _androidJar = fs.file(sdk.androidJarPath);
_aapt = fs.file(sdk.aaptPath); _aapt = fs.file(sdk.aaptPath);
_dx = fs.file(sdk.dxPath); _dx = fs.file(sdk.dxPath);
_zipalign = fs.file(sdk.zipalignPath); _zipalign = fs.file(sdk.zipalignPath);
_jarsigner = os.which('jarsigner'); _apksigner = fs.file(sdk.apksignerPath);
} }
String checkDependencies() { String checkDependencies() {
...@@ -87,10 +86,8 @@ class _ApkBuilder { ...@@ -87,10 +86,8 @@ class _ApkBuilder {
return 'Cannot find dx at ${_dx.path}'; return 'Cannot find dx at ${_dx.path}';
if (!processManager.canRun(_zipalign.path)) if (!processManager.canRun(_zipalign.path))
return 'Cannot find zipalign at ${_zipalign.path}'; return 'Cannot find zipalign at ${_zipalign.path}';
if (_jarsigner == null) if (!processManager.canRun(_apksigner.path))
return 'Cannot find jarsigner in PATH.'; return 'Cannot find apksigner at ${_apksigner.path}';
if (!_jarsigner.existsSync())
return 'Cannot find jarsigner at ${_jarsigner.path}';
return null; return null;
} }
...@@ -123,15 +120,13 @@ class _ApkBuilder { ...@@ -123,15 +120,13 @@ class _ApkBuilder {
} }
void sign(File keystore, String keystorePassword, String keyAlias, String keyPassword, File outputApk) { void sign(File keystore, String keystorePassword, String keyAlias, String keyPassword, File outputApk) {
assert(_jarsigner != null); assert(_apksigner != null);
runCheckedSync(<String>[_jarsigner.path, runCheckedSync(<String>[_apksigner.path, 'sign',
'-keystore', keystore.path, '--ks', keystore.path,
'-storepass', keystorePassword, '--ks-key-alias', keyAlias,
'-keypass', keyPassword, '--ks-pass', 'pass:$keystorePassword',
'-digestalg', 'SHA1', '--key-pass', 'pass:$keyPassword',
'-sigalg', 'MD5withRSA',
outputApk.path, outputApk.path,
keyAlias,
]); ]);
} }
...@@ -371,15 +366,14 @@ int _buildApk( ...@@ -371,15 +366,14 @@ int _buildApk(
unalignedApk, components.manifest, assetBuilder.directory, unalignedApk, components.manifest, assetBuilder.directory,
artifactBuilder.directory, components.resources, buildMode artifactBuilder.directory, components.resources, buildMode
); );
int signResult = _signApk(builder, components, unalignedApk, keystore, buildMode);
if (signResult != 0)
return signResult;
File finalApk = fs.file(outputFile); File finalApk = fs.file(outputFile);
ensureDirectoryExists(finalApk.path); ensureDirectoryExists(finalApk.path);
builder.align(unalignedApk, finalApk); builder.align(unalignedApk, finalApk);
int signResult = _signApk(builder, components, finalApk, keystore, buildMode);
if (signResult != 0)
return signResult;
printTrace('calculateSha: $outputFile'); printTrace('calculateSha: $outputFile');
File apkShaFile = fs.file('$outputFile.sha1'); File apkShaFile = fs.file('$outputFile.sha1');
apkShaFile.writeAsStringSync(calculateSha(finalApk)); apkShaFile.writeAsStringSync(calculateSha(finalApk));
......
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