forked from firka/flutter
Find Java for gradlew executions (#18821)
This commit is contained in:
committed by
GitHub
parent
3351423a42
commit
5e54b9e0fd
@@ -21,9 +21,8 @@ Future<Null> main() async {
|
||||
await flutter('packages', options: <String>['get']);
|
||||
await flutter('clean');
|
||||
await flutter('build', options: <String>['apk', '--target', 'test/live_smoketest.dart']);
|
||||
final String androidStudioPath = grep('Android Studio at', from: await evalFlutter('doctor', options: <String>['-v'])).first.split(' ').last;
|
||||
await exec('./tool/run_instrumentation_test.sh', <String>[], environment: <String, String>{
|
||||
'JAVA_HOME': '$androidStudioPath/jre',
|
||||
'JAVA_HOME': await findJavaHome(),
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -27,10 +27,12 @@ Future<void> runTest(Future<void> testFunction(FlutterProject project, FlutterPl
|
||||
|
||||
void main() async {
|
||||
await task(() async {
|
||||
section('Running flutter doctor to get JAVA_HOME');
|
||||
final String flutterDoctor = await evalFlutter('doctor', options: <String>['-v']);
|
||||
final RegExp javaHomeExtractor = new RegExp(r'Android Studio at (.*)');
|
||||
javaHome = javaHomeExtractor.firstMatch(flutterDoctor).group(1) + '/jre';
|
||||
section('Find Java');
|
||||
|
||||
javaHome = await findJavaHome();
|
||||
if (javaHome == null)
|
||||
return new TaskResult.failure('Could not find Java');
|
||||
print('\nUsing JAVA_HOME=$javaHome');
|
||||
|
||||
try {
|
||||
await runTest((FlutterProject project, FlutterPluginProject pluginProject) async {
|
||||
|
||||
@@ -13,6 +13,13 @@ import 'package:path/path.dart' as path;
|
||||
Future<Null> main() async {
|
||||
await task(() async {
|
||||
|
||||
section('Find Java');
|
||||
|
||||
final String javaHome = await findJavaHome();
|
||||
if (javaHome == null)
|
||||
return new TaskResult.failure('Could not find Java');
|
||||
print('\nUsing JAVA_HOME=$javaHome');
|
||||
|
||||
section('Create Flutter module project');
|
||||
|
||||
final Directory directory = await Directory.systemTemp.createTemp('module');
|
||||
@@ -27,7 +34,11 @@ Future<Null> main() async {
|
||||
section('Build Android .aar');
|
||||
|
||||
await inDirectory(new Directory(path.join(directory.path, 'hello', '.android')), () async {
|
||||
await exec('./gradlew', <String>['flutter:assembleDebug']);
|
||||
await exec(
|
||||
'./gradlew',
|
||||
<String>['flutter:assembleDebug'],
|
||||
environment: <String, String>{ 'JAVA_HOME': javaHome },
|
||||
);
|
||||
});
|
||||
|
||||
final bool aarBuilt = exists(new File(path.join(
|
||||
@@ -63,7 +74,10 @@ Future<Null> main() async {
|
||||
|
||||
await inDirectory(hostApp, () async {
|
||||
await exec('chmod', <String>['+x', 'gradlew']);
|
||||
await exec('./gradlew', <String>['app:assembleDebug']);
|
||||
await exec('./gradlew',
|
||||
<String>['app:assembleDebug'],
|
||||
environment: <String, String>{ 'JAVA_HOME': javaHome },
|
||||
);
|
||||
});
|
||||
|
||||
final bool appBuilt = exists(new File(path.join(
|
||||
|
||||
@@ -348,6 +348,20 @@ String get dartBin =>
|
||||
|
||||
Future<int> dart(List<String> args) => exec(dartBin, args);
|
||||
|
||||
/// Returns a future that completes with a path suitable for JAVA_HOME
|
||||
/// or with null, if Java cannot be found.
|
||||
Future<String> findJavaHome() async {
|
||||
final Iterable<String> hits = grep(
|
||||
'Java binary at: ',
|
||||
from: await evalFlutter('doctor', options: <String>['-v']),
|
||||
);
|
||||
if (hits.isEmpty)
|
||||
return null;
|
||||
final String javaBinary = hits.first.split(': ').last;
|
||||
// javaBinary == /some/path/to/java/home/bin/java
|
||||
return path.dirname(path.dirname(javaBinary));
|
||||
}
|
||||
|
||||
Future<dynamic> inDirectory(dynamic directory, Future<dynamic> action()) async {
|
||||
final String previousCwd = cwd;
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user