Unverified Commit 76957c9d authored by Emmanuel Garcia's avatar Emmanuel Garcia Committed by GitHub

build aar prints how to consume the artifacts (#44127)

parent 7957c569
...@@ -545,6 +545,45 @@ Future<void> buildGradleAar({ ...@@ -545,6 +545,45 @@ Future<void> buildGradleAar({
'$successMark Built ${fs.path.relative(repoDirectory.path)}.', '$successMark Built ${fs.path.relative(repoDirectory.path)}.',
color: TerminalColor.green, color: TerminalColor.green,
); );
_printHowToConsumeAar(
buildMode: androidBuildInfo.buildInfo.modeName,
androidPackage: project.manifest.androidPackage,
repoPath: repoDirectory.path,
);
}
/// Prints how to consume the AAR from a host app.
void _printHowToConsumeAar({
@required String buildMode,
@required String androidPackage,
@required String repoPath,
}) {
assert(buildMode != null);
assert(androidPackage != null);
assert(repoPath != null);
printStatus('''
${terminal.bolden('Consuming the Module')}
1. Open ${fs.path.join('<host>', 'app', 'build.gradle')}
2. Ensure you have the repositories configured, otherwise add them:
repositories {
maven {
url '$repoPath'
}
maven {
url 'http://download.flutter.io'
}
}
3. Make the host app depend on the $buildMode module:
dependencies {
${buildMode}Implementation '$androidPackage:flutter_$buildMode:1.0'
}
To learn more, visit https://flutter.dev/go/build-aar''');
} }
String _hex(List<int> bytes) { String _hex(List<int> bytes) {
......
...@@ -1501,56 +1501,115 @@ plugin2=${plugin2.path} ...@@ -1501,56 +1501,115 @@ plugin2=${plugin2.path}
ProcessManager: () => mockProcessManager, ProcessManager: () => mockProcessManager,
}); });
testUsingContext('indicates how to consume an AAR', () async {
final File manifestFile = fs.file('pubspec.yaml');
manifestFile.createSync(recursive: true);
manifestFile.writeAsStringSync('''
flutter:
module:
androidPackage: com.example.test
'''
);
fs.file('.android/gradlew').createSync(recursive: true);
fs.file('.android/gradle.properties')
.writeAsStringSync('irrelevant');
fs.file('.android/build.gradle')
.createSync(recursive: true);
// Let any process start. Assert after.
when(mockProcessManager.run(
any,
environment: anyNamed('environment'),
workingDirectory: anyNamed('workingDirectory'),
)).thenAnswer((_) async => ProcessResult(1, 0, '', ''));
fs.directory('build/outputs/repo').createSync(recursive: true);
await buildGradleAar(
androidBuildInfo: const AndroidBuildInfo(BuildInfo(BuildMode.release, null)),
project: FlutterProject.current(),
outputDir: fs.directory('build/'),
target: '',
);
final BufferLogger logger = context.get<Logger>();
expect(
logger.statusText,
contains('Built build/outputs/repo'),
);
expect(
logger.statusText,
contains('''
Consuming the Module
1. Open <host>/app/build.gradle
2. Ensure you have the repositories configured, otherwise add them:
repositories {
maven {
url 'build/outputs/repo'
}
maven {
url 'http://download.flutter.io'
}
}
3. Make the host app depend on the release module:
dependencies {
releaseImplementation 'com.example.test:flutter_release:1.0'
}
To learn more, visit https://flutter.dev/go/build-aar'''));
}, overrides: <Type, Generator>{
AndroidSdk: () => mockAndroidSdk,
AndroidStudio: () => mockAndroidStudio,
Artifacts: () => mockArtifacts,
Cache: () => cache,
Platform: () => android,
FileSystem: () => fs,
ProcessManager: () => mockProcessManager,
});
testUsingContext('build aar uses selected local engine', () async { testUsingContext('build aar uses selected local engine', () async {
when(mockArtifacts.getArtifactPath(Artifact.flutterFramework, when(mockArtifacts.getArtifactPath(Artifact.flutterFramework,
platform: TargetPlatform.android_arm, mode: anyNamed('mode'))).thenReturn('engine'); platform: TargetPlatform.android_arm, mode: anyNamed('mode'))).thenReturn('engine');
when(mockArtifacts.engineOutPath).thenReturn(fs.path.join('out', 'android_arm')); when(mockArtifacts.engineOutPath).thenReturn(fs.path.join('out', 'android_arm'));
final File manifestFile = fs.file('path/to/project/pubspec.yaml'); final File manifestFile = fs.file('pubspec.yaml');
manifestFile.createSync(recursive: true); manifestFile.createSync(recursive: true);
manifestFile.writeAsStringSync(''' manifestFile.writeAsStringSync('''
name: test
version: 1.0.0+1
dependencies:
flutter:
sdk: flutter
flutter: flutter:
module: module:
androidX: false
androidPackage: com.example.test androidPackage: com.example.test
iosBundleIdentifier: com.example.test
''' '''
); );
final File gradlew = fs.file('path/to/project/.android/gradlew'); final File gradlew = fs.file('.android/gradlew');
gradlew.createSync(recursive: true); gradlew.createSync(recursive: true);
fs.file('path/to/project/.android/gradle.properties') fs.file('.android/gradle.properties')
.writeAsStringSync('irrelevant'); .writeAsStringSync('irrelevant');
fs.file('path/to/project/.android/build.gradle') fs.file('.android/build.gradle')
.createSync(recursive: true); .createSync(recursive: true);
when(mockProcessManager.run( when(mockProcessManager.run(
<String> ['/path/to/project/.android/gradlew', '-v'], <String> ['.android/gradlew', '-v'],
workingDirectory: anyNamed('workingDirectory'), workingDirectory: anyNamed('workingDirectory'),
environment: anyNamed('environment'), environment: anyNamed('environment'),
)).thenAnswer( )).thenAnswer((_) async => ProcessResult(1, 0, '5.1.1', ''));
(_) async => ProcessResult(1, 0, '5.1.1', ''),
);
// write schemaData otherwise pubspec.yaml file can't be loaded
writeEmptySchemaFile(fs);
fs.currentDirectory = 'path/to/project';
// Let any process start. Assert after. // Let any process start. Assert after.
when(mockProcessManager.run( when(mockProcessManager.run(
any, any,
environment: anyNamed('environment'), environment: anyNamed('environment'),
workingDirectory: anyNamed('workingDirectory'), workingDirectory: anyNamed('workingDirectory'),
)).thenAnswer( )).thenAnswer((_) async => ProcessResult(1, 0, '', ''));
(_) async => ProcessResult(1, 0, '', ''),
);
fs.directory('build/outputs/repo').createSync(recursive: true); fs.directory('build/outputs/repo').createSync(recursive: true);
await buildGradleAar( await buildGradleAar(
...@@ -1566,7 +1625,7 @@ plugin2=${plugin2.path} ...@@ -1566,7 +1625,7 @@ plugin2=${plugin2.path}
workingDirectory: anyNamed('workingDirectory')), workingDirectory: anyNamed('workingDirectory')),
).captured.last; ).captured.last;
expect(actualGradlewCall, contains('/path/to/project/.android/gradlew')); expect(actualGradlewCall, contains('/.android/gradlew'));
expect(actualGradlewCall, contains('-PlocalEngineOut=out/android_arm')); expect(actualGradlewCall, contains('-PlocalEngineOut=out/android_arm'));
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
AndroidSdk: () => mockAndroidSdk, AndroidSdk: () => mockAndroidSdk,
......
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