diff --git a/AUTHORS b/AUTHORS index 2ec90be11a..fd9c0c9ce1 100644 --- a/AUTHORS +++ b/AUTHORS @@ -96,3 +96,4 @@ Jonathan Joelson Elsabe Ros Nguyễn Phúc Lợi Jingyi Chen +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 b692161a7c..6676a0d61f 100644 --- a/dev/devicelab/bin/tasks/android_obfuscate_test.dart +++ b/dev/devicelab/bin/tasks/android_obfuscate_test.dart @@ -51,8 +51,7 @@ Future 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 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 filesInOldAar = await getFilesInAar(oldReleaseAar); + final Iterable aarFiles = await getFilesInAar(outputAarDirectory); checkCollectionContains([ ...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', ['-o', oldReleaseAar]); + await exec('unzip', [outputAarDirectory]); checkFileExists(path.join(flutterProject.rootPath, 'jni/armeabi-v7a/libapp.so')); final String response = await eval( 'grep', @@ -92,46 +89,16 @@ Future 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 filesInNewAar = await getFilesInAar(newReleaseAar); - - checkCollectionContains([ - ...flutterAssets, - 'jni/armeabi-v7a/libapp.so', - ], filesInNewAar); - - await inDirectory(flutterProject.rootPath, () async { - await exec('unzip', ['-o', newReleaseAar]); - checkFileExists(path.join(flutterProject.rootPath, 'jni/armeabi-v7a/libapp.so')); - final String response = await eval( - 'grep', - [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 1f5850c41c..ed9988c6ba 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 @@ Future main() async { 'repo', ); - section('Check release Maven artifacts (old format)'); + section('Check release Maven artifacts'); checkFileExists(path.join( repoPath, @@ -108,7 +108,7 @@ Future 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 main() async { 'flutter_release-1.0.pom', ); - checkFileExists(releasePomOld); + checkFileExists(releasePom); checkFileExists(path.join( repoPath, @@ -143,54 +143,6 @@ Future 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([ @@ -198,17 +150,8 @@ Future main() async { 'armeabi_v7a_release', 'arm64_v8a_release', 'x86_64_release', - 'plugin_with_android', - '', //make sure the old pom contains the tag - ], releasePomOld); - - checkFileContains([ - '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 main() async { ) ); - checkCollectionContains( - [ - ...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 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 main() async { 'flutter_debug-1.0.pom', ); - checkFileExists(debugPomOld); + checkFileExists(debugPom); checkFileExists(path.join( repoPath, @@ -304,54 +225,6 @@ Future 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([ @@ -360,18 +233,8 @@ Future main() async { 'x86_64_debug', 'armeabi_v7a_debug', 'arm64_v8a_debug', - 'plugin_with_android', - '', //make sure the old pom contains the tag - ], debugPomOld); - - checkFileContains([ - '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 main() async { 'flutter_debug-1.0.aar', )); - final Iterable debugAarNew = await getFilesInAar(path.join( - repoPath, - 'io', - 'flutter', - 'devicelab', - 'hello', - 'flutter', - '1.0', - 'flutter-1.0-debug.aar', - )); - checkCollectionContains([ ...flutterAssets, ...debugAssets, ], debugAar); - checkCollectionContains([ - ...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 c4bf0655d3..07f8f55299 100644 --- a/packages/flutter_tools/gradle/aar_init_script.gradle +++ b/packages/flutter_tools/gradle/aar_init_script.gradle @@ -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 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" } diff --git a/packages/flutter_tools/lib/src/android/gradle.dart b/packages/flutter_tools/lib/src/android/gradle.dart index 547a921057..cc00fb1c12 100644 --- a/packages/flutter_tools/lib/src/android/gradle.dart +++ b/packages/flutter_tools/lib/src/android/gradle.dart @@ -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(''' 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 413587ee14..51527d7140 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 @@ 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'