Revert file naming convention of .aar files to support fuzzy matching in build.gradle (#112149)
diff --git a/AUTHORS b/AUTHORS
index 2ec90be..fd9c0c9 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -96,3 +96,4 @@
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>
diff --git a/dev/devicelab/bin/tasks/android_obfuscate_test.dart b/dev/devicelab/bin/tasks/android_obfuscate_test.dart
index b692161..6676a0d 100644
--- a/dev/devicelab/bin/tasks/android_obfuscate_test.dart
+++ b/dev/devicelab/bin/tasks/android_obfuscate_test.dart
@@ -51,8 +51,7 @@
});
});
- bool foundProjectNameInOldAar = false;
- bool foundProjectNameInNewAar = false;
+ bool foundAarProjectName = false;
await runModuleProjectTest((FlutterModuleProject flutterProject) async {
section('AAR content with --obfuscate');
@@ -68,23 +67,21 @@
]);
});
- 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 @@
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);
diff --git a/dev/devicelab/bin/tasks/build_aar_module_test.dart b/dev/devicelab/bin/tasks/build_aar_module_test.dart
index 1f5850c..ed9988c 100644
--- a/dev/devicelab/bin/tasks/build_aar_module_test.dart
+++ b/dev/devicelab/bin/tasks/build_aar_module_test.dart
@@ -95,7 +95,7 @@
'repo',
);
- section('Check release Maven artifacts (old format)');
+ section('Check release Maven artifacts');
checkFileExists(path.join(
repoPath,
@@ -108,7 +108,7 @@
'flutter_release-1.0.aar',
));
- final String releasePomOld = path.join(
+ final String releasePom = path.join(
repoPath,
'io',
'flutter',
@@ -119,7 +119,7 @@
'flutter_release-1.0.pom',
);
- checkFileExists(releasePomOld);
+ checkFileExists(releasePom);
checkFileExists(path.join(
repoPath,
@@ -143,54 +143,6 @@
'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 @@
'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 @@
)
);
- 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 @@
'flutter_debug-1.0.aar',
));
- final String debugPomOld = path.join(
+ final String debugPom = path.join(
repoPath,
'io',
'flutter',
@@ -280,7 +201,7 @@
'flutter_debug-1.0.pom',
);
- checkFileExists(debugPomOld);
+ checkFileExists(debugPom);
checkFileExists(path.join(
repoPath,
@@ -304,54 +225,6 @@
'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 @@
'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 @@
'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;
diff --git a/packages/flutter_tools/gradle/aar_init_script.gradle b/packages/flutter_tools/gradle/aar_init_script.gradle
index c4bf065..07f8f55 100644
--- a/packages/flutter_tools/gradle/aar_init_script.gradle
+++ b/packages/flutter_tools/gradle/aar_init_script.gradle
@@ -26,8 +26,10 @@
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 @@
}
}
- // 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 @@
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"
}
diff --git a/packages/flutter_tools/lib/src/android/gradle.dart b/packages/flutter_tools/lib/src/android/gradle.dart
index 547a921..cc00fb1 100644
--- a/packages/flutter_tools/lib/src/android/gradle.dart
+++ b/packages/flutter_tools/lib/src/android/gradle.dart
@@ -726,7 +726,7 @@
for (final String buildMode in buildModes) {
logger.printStatus("""
- ${buildMode}Implementation '$androidPackage:flutter:$buildNumber:$buildMode'""");
+ ${buildMode}Implementation '$androidPackage:flutter_$buildMode:$buildNumber'""");
}
logger.printStatus('''
diff --git a/packages/flutter_tools/test/general.shard/android/gradle_test.dart b/packages/flutter_tools/test/general.shard/android/gradle_test.dart
index 413587e..51527d7 100644
--- a/packages/flutter_tools/test/general.shard/android/gradle_test.dart
+++ b/packages/flutter_tools/test/general.shard/android/gradle_test.dart
@@ -540,9 +540,9 @@
' 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 @@
' 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 @@
' 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 @@
' 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'