Revert file naming convention of .aar files to support fuzzy matching in build.gradle (#112149)
This commit is contained in:
parent
35afe1bdac
commit
8e30cc9c56
1
AUTHORS
1
AUTHORS
@ -96,3 +96,4 @@ Jonathan Joelson <jon@joelson.co>
|
||||
Elsabe Ros <hello@elsabe.dev>
|
||||
Nguyễn Phúc Lợi <nploi1998@gmail.com>
|
||||
Jingyi Chen <jingyichen@link.cuhk.edu.cn>
|
||||
Junhua Lin <1075209054@qq.com>
|
||||
|
@ -51,8 +51,7 @@ Future<void> main() async {
|
||||
});
|
||||
});
|
||||
|
||||
bool foundProjectNameInOldAar = false;
|
||||
bool foundProjectNameInNewAar = false;
|
||||
bool foundAarProjectName = false;
|
||||
await runModuleProjectTest((FlutterModuleProject flutterProject) async {
|
||||
section('AAR content with --obfuscate');
|
||||
|
||||
@ -68,23 +67,21 @@ Future<void> main() async {
|
||||
]);
|
||||
});
|
||||
|
||||
section('Check old _release AAR files');
|
||||
|
||||
final String oldReleaseAar = path.join(
|
||||
final String outputAarDirectory = path.join(
|
||||
flutterProject.rootPath,
|
||||
'build/host/outputs/repo/com/example/${flutterProject.name}/flutter_release/1.0/flutter_release-1.0.aar',
|
||||
);
|
||||
final Iterable<String> filesInOldAar = await getFilesInAar(oldReleaseAar);
|
||||
final Iterable<String> aarFiles = await getFilesInAar(outputAarDirectory);
|
||||
|
||||
checkCollectionContains<String>(<String>[
|
||||
...flutterAssets,
|
||||
'jni/armeabi-v7a/libapp.so',
|
||||
], filesInOldAar);
|
||||
], aarFiles);
|
||||
|
||||
// Verify that an identifier from the Dart project code is not present
|
||||
// in the compiled binary.
|
||||
await inDirectory(flutterProject.rootPath, () async {
|
||||
await exec('unzip', <String>['-o', oldReleaseAar]);
|
||||
await exec('unzip', <String>[outputAarDirectory]);
|
||||
checkFileExists(path.join(flutterProject.rootPath, 'jni/armeabi-v7a/libapp.so'));
|
||||
final String response = await eval(
|
||||
'grep',
|
||||
@ -92,46 +89,16 @@ Future<void> main() async {
|
||||
canFail: true,
|
||||
);
|
||||
if (response.trim().contains('matches')) {
|
||||
foundProjectNameInOldAar = true;
|
||||
}
|
||||
});
|
||||
|
||||
section('Check new -release AAR files');
|
||||
|
||||
final String newReleaseAar = path.join(
|
||||
flutterProject.rootPath,
|
||||
'build/host/outputs/repo/com/example/${flutterProject.name}/flutter/1.0/flutter-1.0-release.aar',
|
||||
);
|
||||
final Iterable<String> filesInNewAar = await getFilesInAar(newReleaseAar);
|
||||
|
||||
checkCollectionContains<String>(<String>[
|
||||
...flutterAssets,
|
||||
'jni/armeabi-v7a/libapp.so',
|
||||
], filesInNewAar);
|
||||
|
||||
await inDirectory(flutterProject.rootPath, () async {
|
||||
await exec('unzip', <String>['-o', newReleaseAar]);
|
||||
checkFileExists(path.join(flutterProject.rootPath, 'jni/armeabi-v7a/libapp.so'));
|
||||
final String response = await eval(
|
||||
'grep',
|
||||
<String>[flutterProject.name, 'jni/armeabi-v7a/libapp.so'],
|
||||
canFail: true,
|
||||
);
|
||||
if (response.trim().contains('matches')) {
|
||||
foundProjectNameInNewAar = true;
|
||||
foundAarProjectName = true;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
if (foundApkProjectName) {
|
||||
return TaskResult.failure('Found project name in obfuscated APK dart library');
|
||||
}
|
||||
if (foundProjectNameInOldAar) {
|
||||
return TaskResult.failure('Found project name in obfuscated AAR _release dart library');
|
||||
}
|
||||
if (foundProjectNameInNewAar) {
|
||||
return TaskResult.failure('Found project name in obfuscated AAR -release dart library');
|
||||
if (foundAarProjectName) {
|
||||
return TaskResult.failure('Found project name in obfuscated AAR dart library');
|
||||
}
|
||||
|
||||
return TaskResult.success(null);
|
||||
|
@ -95,7 +95,7 @@ Future<void> main() async {
|
||||
'repo',
|
||||
);
|
||||
|
||||
section('Check release Maven artifacts (old format)');
|
||||
section('Check release Maven artifacts');
|
||||
|
||||
checkFileExists(path.join(
|
||||
repoPath,
|
||||
@ -108,7 +108,7 @@ Future<void> main() async {
|
||||
'flutter_release-1.0.aar',
|
||||
));
|
||||
|
||||
final String releasePomOld = path.join(
|
||||
final String releasePom = path.join(
|
||||
repoPath,
|
||||
'io',
|
||||
'flutter',
|
||||
@ -119,7 +119,7 @@ Future<void> main() async {
|
||||
'flutter_release-1.0.pom',
|
||||
);
|
||||
|
||||
checkFileExists(releasePomOld);
|
||||
checkFileExists(releasePom);
|
||||
|
||||
checkFileExists(path.join(
|
||||
repoPath,
|
||||
@ -143,54 +143,6 @@ Future<void> main() async {
|
||||
'plugin_with_android_release-1.0.pom',
|
||||
));
|
||||
|
||||
section('Check release Maven artifacts (new format)');
|
||||
|
||||
checkFileExists(path.join(
|
||||
repoPath,
|
||||
'io',
|
||||
'flutter',
|
||||
'devicelab',
|
||||
'hello',
|
||||
'flutter',
|
||||
'1.0',
|
||||
'flutter-1.0-release.aar',
|
||||
));
|
||||
|
||||
final String releasePomNew = path.join(
|
||||
repoPath,
|
||||
'io',
|
||||
'flutter',
|
||||
'devicelab',
|
||||
'hello',
|
||||
'flutter',
|
||||
'1.0',
|
||||
'flutter-1.0.pom',
|
||||
);
|
||||
|
||||
checkFileExists(releasePomNew);
|
||||
|
||||
checkFileExists(path.join(
|
||||
repoPath,
|
||||
'io',
|
||||
'flutter',
|
||||
'devicelab',
|
||||
'plugin_with_android',
|
||||
'plugin_with_android',
|
||||
'1.0',
|
||||
'plugin_with_android-1.0-release.aar',
|
||||
));
|
||||
|
||||
checkFileExists(path.join(
|
||||
repoPath,
|
||||
'io',
|
||||
'flutter',
|
||||
'devicelab',
|
||||
'plugin_with_android',
|
||||
'plugin_with_android',
|
||||
'1.0',
|
||||
'plugin_with_android-1.0.pom',
|
||||
));
|
||||
|
||||
section('Check AOT blobs in release POM');
|
||||
|
||||
checkFileContains(<String>[
|
||||
@ -198,17 +150,8 @@ Future<void> main() async {
|
||||
'armeabi_v7a_release',
|
||||
'arm64_v8a_release',
|
||||
'x86_64_release',
|
||||
'plugin_with_android',
|
||||
'<relocation>', //make sure the old pom contains the <relocation> tag
|
||||
], releasePomOld);
|
||||
|
||||
checkFileContains(<String>[
|
||||
'flutter_embedding_release',
|
||||
'armeabi_v7a_release',
|
||||
'arm64_v8a_release',
|
||||
'x86_64_release',
|
||||
'plugin_with_android',
|
||||
], releasePomNew);
|
||||
'plugin_with_android_release',
|
||||
], releasePom);
|
||||
|
||||
section('Check assets in release AAR');
|
||||
|
||||
@ -234,29 +177,7 @@ Future<void> main() async {
|
||||
)
|
||||
);
|
||||
|
||||
checkCollectionContains<String>(
|
||||
<String>[
|
||||
...flutterAssets,
|
||||
// AOT snapshots
|
||||
'jni/arm64-v8a/libapp.so',
|
||||
'jni/armeabi-v7a/libapp.so',
|
||||
'jni/x86_64/libapp.so',
|
||||
],
|
||||
await getFilesInAar(
|
||||
path.join(
|
||||
repoPath,
|
||||
'io',
|
||||
'flutter',
|
||||
'devicelab',
|
||||
'hello',
|
||||
'flutter',
|
||||
'1.0',
|
||||
'flutter-1.0-release.aar',
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
section('Check debug Maven artifacts (old format)');
|
||||
section('Check debug Maven artifacts');
|
||||
|
||||
checkFileExists(path.join(
|
||||
repoPath,
|
||||
@ -269,7 +190,7 @@ Future<void> main() async {
|
||||
'flutter_debug-1.0.aar',
|
||||
));
|
||||
|
||||
final String debugPomOld = path.join(
|
||||
final String debugPom = path.join(
|
||||
repoPath,
|
||||
'io',
|
||||
'flutter',
|
||||
@ -280,7 +201,7 @@ Future<void> main() async {
|
||||
'flutter_debug-1.0.pom',
|
||||
);
|
||||
|
||||
checkFileExists(debugPomOld);
|
||||
checkFileExists(debugPom);
|
||||
|
||||
checkFileExists(path.join(
|
||||
repoPath,
|
||||
@ -304,54 +225,6 @@ Future<void> main() async {
|
||||
'plugin_with_android_debug-1.0.pom',
|
||||
));
|
||||
|
||||
section('Check debug Maven artifacts (new format)');
|
||||
|
||||
checkFileExists(path.join(
|
||||
repoPath,
|
||||
'io',
|
||||
'flutter',
|
||||
'devicelab',
|
||||
'hello',
|
||||
'flutter',
|
||||
'1.0',
|
||||
'flutter-1.0-debug.aar',
|
||||
));
|
||||
|
||||
final String debugPomNew = path.join(
|
||||
repoPath,
|
||||
'io',
|
||||
'flutter',
|
||||
'devicelab',
|
||||
'hello',
|
||||
'flutter',
|
||||
'1.0',
|
||||
'flutter-1.0.pom',
|
||||
);
|
||||
|
||||
checkFileExists(debugPomNew);
|
||||
|
||||
checkFileExists(path.join(
|
||||
repoPath,
|
||||
'io',
|
||||
'flutter',
|
||||
'devicelab',
|
||||
'plugin_with_android',
|
||||
'plugin_with_android',
|
||||
'1.0',
|
||||
'plugin_with_android-1.0-debug.aar',
|
||||
));
|
||||
|
||||
checkFileExists(path.join(
|
||||
repoPath,
|
||||
'io',
|
||||
'flutter',
|
||||
'devicelab',
|
||||
'plugin_with_android',
|
||||
'plugin_with_android',
|
||||
'1.0',
|
||||
'plugin_with_android-1.0.pom',
|
||||
));
|
||||
|
||||
section('Check AOT blobs in debug POM');
|
||||
|
||||
checkFileContains(<String>[
|
||||
@ -360,18 +233,8 @@ Future<void> main() async {
|
||||
'x86_64_debug',
|
||||
'armeabi_v7a_debug',
|
||||
'arm64_v8a_debug',
|
||||
'plugin_with_android',
|
||||
'<relocation>', //make sure the old pom contains the <relocation> tag
|
||||
], debugPomOld);
|
||||
|
||||
checkFileContains(<String>[
|
||||
'flutter_embedding_debug',
|
||||
'x86_debug',
|
||||
'x86_64_debug',
|
||||
'armeabi_v7a_debug',
|
||||
'arm64_v8a_debug',
|
||||
'plugin_with_android',
|
||||
], debugPomNew);
|
||||
'plugin_with_android_debug',
|
||||
], debugPom);
|
||||
|
||||
section('Check assets in debug AAR');
|
||||
|
||||
@ -386,27 +249,11 @@ Future<void> main() async {
|
||||
'flutter_debug-1.0.aar',
|
||||
));
|
||||
|
||||
final Iterable<String> debugAarNew = await getFilesInAar(path.join(
|
||||
repoPath,
|
||||
'io',
|
||||
'flutter',
|
||||
'devicelab',
|
||||
'hello',
|
||||
'flutter',
|
||||
'1.0',
|
||||
'flutter-1.0-debug.aar',
|
||||
));
|
||||
|
||||
checkCollectionContains<String>(<String>[
|
||||
...flutterAssets,
|
||||
...debugAssets,
|
||||
], debugAar);
|
||||
|
||||
checkCollectionContains<String>(<String>[
|
||||
...flutterAssets,
|
||||
...debugAssets,
|
||||
], debugAarNew);
|
||||
|
||||
return TaskResult.success(null);
|
||||
} on TaskResult catch (taskResult) {
|
||||
return taskResult;
|
||||
|
@ -26,8 +26,10 @@ void configureProject(Project project, String outputDir) {
|
||||
project.version = project.property("buildNumber")
|
||||
}
|
||||
|
||||
project.android.libraryVariants.all { variant ->
|
||||
addAarTask(project, variant)
|
||||
project.components.forEach { component ->
|
||||
if (component.name != "all") {
|
||||
addAarTask(project, component)
|
||||
}
|
||||
}
|
||||
|
||||
project.publishing {
|
||||
@ -38,43 +40,6 @@ void configureProject(Project project, String outputDir) {
|
||||
}
|
||||
}
|
||||
|
||||
// Some extra work to have alternative publications with the same format as the old maven plugin.
|
||||
// Instead of using classifiers for the variants, the old maven plugin appended `_{variant}` to the artifactId
|
||||
|
||||
// First, create a default MavenPublication for each variant (except "all" since that is used to publish artifacts in the new way)
|
||||
project.components.forEach { component ->
|
||||
if (component.name != "all") {
|
||||
project.publishing.publications.create(component.name, MavenPublication) {
|
||||
from component
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// then, rename the artifactId to include the variant and make sure to remove any classifier
|
||||
// data tha gradle has set, as well as adding a <relocation> tag pointing to the new coordinates
|
||||
project.publishing.publications.forEach { pub ->
|
||||
def relocationArtifactId = pub.artifactId
|
||||
pub.artifactId = "${relocationArtifactId}_${pub.name}"
|
||||
pub.alias = true
|
||||
|
||||
pub.pom.distributionManagement {
|
||||
relocation {
|
||||
// New artifact coordinates
|
||||
groupId = "${pub.groupId}"
|
||||
artifactId = "${relocationArtifactId}"
|
||||
version = "${pub.version}"
|
||||
message = "Use classifiers rather than _variant for new publish plugin"
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// also publish the artifacts in the new way, using one set of coordinates with classifiers
|
||||
project.publishing.publications.create("all", MavenPublication) {
|
||||
from project.components.all
|
||||
alias false
|
||||
}
|
||||
|
||||
if (!project.property("is-plugin").toBoolean()) {
|
||||
return
|
||||
}
|
||||
@ -114,14 +79,23 @@ String getFlutterRoot(Project project) {
|
||||
return project.property("flutter-root")
|
||||
}
|
||||
|
||||
void addAarTask(Project project, variant) {
|
||||
String variantName = variant.name.capitalize()
|
||||
void addAarTask(Project project, component) {
|
||||
String variantName = component.name.capitalize()
|
||||
String taskName = "assembleAar$variantName"
|
||||
project.tasks.create(name: taskName) {
|
||||
// This check is required to be able to configure the archives before `publish` runs.
|
||||
if (!project.gradle.startParameter.taskNames.contains(taskName)) {
|
||||
return
|
||||
}
|
||||
|
||||
// Create a default MavenPublication for the variant (except "all" since that is used to publish artifacts in the new way)
|
||||
project.publishing.publications.create(component.name, MavenPublication) { pub ->
|
||||
groupId = "${pub.groupId}"
|
||||
artifactId = "${pub.artifactId}_${pub.name}"
|
||||
version = "${pub.version}"
|
||||
from component
|
||||
}
|
||||
|
||||
// Generate the Maven artifacts.
|
||||
finalizedBy "publish"
|
||||
}
|
||||
|
@ -726,7 +726,7 @@ void printHowToConsumeAar({
|
||||
|
||||
for (final String buildMode in buildModes) {
|
||||
logger.printStatus("""
|
||||
${buildMode}Implementation '$androidPackage:flutter:$buildNumber:$buildMode'""");
|
||||
${buildMode}Implementation '$androidPackage:flutter_$buildMode:$buildNumber'""");
|
||||
}
|
||||
|
||||
logger.printStatus('''
|
||||
|
@ -540,9 +540,9 @@ flutter:
|
||||
' 3. Make the host app depend on the Flutter module:\n'
|
||||
'\n'
|
||||
' dependencies {\n'
|
||||
" releaseImplementation 'com.mycompany:flutter:2.2:release'\n"
|
||||
" debugImplementation 'com.mycompany:flutter:2.2:debug'\n"
|
||||
" profileImplementation 'com.mycompany:flutter:2.2:profile'\n"
|
||||
" releaseImplementation 'com.mycompany:flutter_release:2.2'\n"
|
||||
" debugImplementation 'com.mycompany:flutter_debug:2.2'\n"
|
||||
" profileImplementation 'com.mycompany:flutter_profile:2.2'\n"
|
||||
' }\n'
|
||||
'\n'
|
||||
'\n'
|
||||
@ -591,7 +591,7 @@ flutter:
|
||||
' 3. Make the host app depend on the Flutter module:\n'
|
||||
'\n'
|
||||
' dependencies {\n'
|
||||
" releaseImplementation 'com.mycompany:flutter:1.0:release'\n"
|
||||
" releaseImplementation 'com.mycompany:flutter_release:1.0'\n"
|
||||
' }\n'
|
||||
'\n'
|
||||
'To learn more, visit https://flutter.dev/go/build-aar\n'
|
||||
@ -629,7 +629,7 @@ flutter:
|
||||
' 3. Make the host app depend on the Flutter module:\n'
|
||||
'\n'
|
||||
' dependencies {\n'
|
||||
" debugImplementation 'com.mycompany:flutter:1.0:debug'\n"
|
||||
" debugImplementation 'com.mycompany:flutter_debug:1.0'\n"
|
||||
' }\n'
|
||||
'\n'
|
||||
'To learn more, visit https://flutter.dev/go/build-aar\n'
|
||||
@ -668,7 +668,7 @@ flutter:
|
||||
' 3. Make the host app depend on the Flutter module:\n'
|
||||
'\n'
|
||||
' dependencies {\n'
|
||||
" profileImplementation 'com.mycompany:flutter:1.0:profile'\n"
|
||||
" profileImplementation 'com.mycompany:flutter_profile:1.0'\n"
|
||||
' }\n'
|
||||
'\n'
|
||||
'\n'
|
||||
|
Loading…
x
Reference in New Issue
Block a user