Open kkkkan opened 1 year ago
This is because archivesBaseName renaming
is not considered in File findBundleFile(FlutterProject project, BuildInfo buildInfo, Logger logger, Usage usage)
in flutter/packages/flutter_tools/lib/src/android/gradle.dart
, which checks whether the app bundle is generated after the generation is completed.
.childFile('app-${buildInfo.modeName}.aab'),
Here, use regular expressions to clear any aab (sorry ,I don`t know how write in dart. but I means like below).
.childFile('/*/-${buildInfo.modeName}.aab'),
Or、like on apk, create new directory like flutter-bundle
, and copy appbundle flie in here by fixed file name.
Like this :
in flutter/packages/flutter_tools/gradle/flutter.gradle
variant.outputs.all { output ->
assembleTask.doLast {
// `packageApplication` became `packageApplicationProvider` in AGP 3.3.0.
def outputDirectory = variant.hasProperty("packageApplicationProvider")
? variant.packageApplicationProvider.get().outputDirectory
: variant.packageApplication.outputDirectory
// `outputDirectory` is a `DirectoryProperty` in AGP 4.1.
String outputDirectoryStr = outputDirectory.metaClass.respondsTo(outputDirectory, "get")
? outputDirectory.get()
: outputDirectory
String filename = "app"
String abi = output.getFilter(OutputFile.ABI)
if (abi != null && !abi.isEmpty()) {
filename += "-${abi}"
}
if (variant.flavorName != null && !variant.flavorName.isEmpty()) {
filename += "-${variant.flavorName.toLowerCase()}"
}
filename += "-${buildModeFor(variant.buildType)}"
project.copy {
from new File("$outputDirectoryStr/${output.outputFileName}")
into new File("${project.buildDir}/outputs/flutter-apk");
rename {
return "${filename}.apk"
}
}
}
}
}
add like this :
variant.outputs.all { output ->
bundleTask.doLast {
and
project.copy {
from new File("$outputDirectoryStr/${output.outputFileName}")
into new File("${project.buildDir}/outputs/flutter-bundle");
rename {
return "${filename}.aab"
}
}
and in File findBundleFile(FlutterProject project, BuildInfo buildInfo, Logger logger, Usage usage)
function , change checking path so.
Thanks for the report @kkkkan Can you check this related issue and see if it resembles your case ?
@darshankawar
Thank you for checking.
The issue #73919 you pointed out seems to be about building apks. This issue is similar, but slightly different.
Currently, even if you add archivesBaseName
, the apk build is successful, but app-<buildtype>.apk
is created in the ${baseBuildDir}/flutter-apk
directory. (${baseBuildDir}/apk
directory contains ${archivesBaseName}-<buildtype>.apk
.) The issue you pointed out seems to be about creating ${archivesBaseName}-<buildtype>.apk
in ${baseBuildDir}/flutter-apk
directory as well.
This issue I raised is that the build fails when archivesBaseName
is added to the AppBundle
build, so it is slightly different. (The method that #73919 said should be fixed in the issue you pointed out seems to be a method that can only be used for apk builds, if I understand correctly.)
I hope this is helpful! Let me know if you have any other questions.
I apologize for the error in the previous part. The code I provided earlier probably won't work.
add like this :
variant.outputs.all { output -> bundleTask.doLast {
and
project.copy { from new File("$outputDirectoryStr/${output.outputFileName}") into new File("${project.buildDir}/outputs/flutter-bundle"); rename { return "${filename}.aab" } }
There is no function such as bundleTask
, and I think we need to do the following in order to achieve the same goal.
I think it would be better to do the following instead of the above.
Change
variant.outputs.all { output ->
assembleTask.doLast {
// `packageApplication` became `packageApplicationProvider` in AGP 3.3.0.
def outputDirectory = variant.hasProperty("packageApplicationProvider")
? variant.packageApplicationProvider.get().outputDirectory
: variant.packageApplication.outputDirectory
// `outputDirectory` is a `DirectoryProperty` in AGP 4.1.
String outputDirectoryStr = outputDirectory.metaClass.respondsTo(outputDirectory, "get")
? outputDirectory.get()
: outputDirectory
String filename = "app"
String abi = output.getFilter(OutputFile.ABI)
if (abi != null && !abi.isEmpty()) {
filename += "-${abi}"
}
if (variant.flavorName != null && !variant.flavorName.isEmpty()) {
filename += "-${variant.flavorName.toLowerCase()}"
}
filename += "-${buildModeFor(variant.buildType)}"
project.copy {
from new File("$outputDirectoryStr/${output.outputFileName}")
into new File("${project.buildDir}/outputs/flutter-apk");
rename {
return "${filename}.apk"
}
}
}
}
}
to like this :
variant.outputs.all { output ->
assembleTask.doLast {
// `packageApplication` became `packageApplicationProvider` in AGP 3.3.0.
def outputDirectory = variant.hasProperty("packageApplicationProvider")
? variant.packageApplicationProvider.get().outputDirectory
: variant.packageApplication.outputDirectory
// `outputDirectory` is a `DirectoryProperty` in AGP 4.1.
String outputDirectoryStr = outputDirectory.metaClass.respondsTo(outputDirectory, "get")
? outputDirectory.get()
: outputDirectory
String filename = "app"
String abi = output.getFilter(OutputFile.ABI)
if (abi != null && !abi.isEmpty()) {
filename += "-${abi}"
}
if (variant.flavorName != null && !variant.flavorName.isEmpty()) {
filename += "-${variant.flavorName.toLowerCase()}"
}
filename += "-${buildModeFor(variant.buildType)}"
project.copy {
from new File("$outputDirectoryStr/${output.outputFileName}")
into new File("${project.buildDir}/outputs/flutter-apk");
rename {
return "${filename}.apk"
}
}
**
// replace "apk" to "aab" because AGP make bundle same prefix between apk and aab
// (I don`t know how to write replace substring , so belows is just image. actual working code is maybe not like this.)
def bundleName = output.outputFileName.replace(".apk",".aab")
// replace "apk" to "bundle" because AGP make appbundle in `bundle` directory. (apk in `apk` directory.)
// (I don`t know how to write replace substring , so belows is just image. actual working code is maybe not like this.)
// I think the directory name might be in output.outputFileName, so it might be better to replace it there.
// However, I think it is in outputDirectoryStr.
def bundleOuputDir = outputDirectoryStr.replace("apk","bundle")
project.copy {
from new File("$bundleOuputDir/${bundleName}")
into new File("${project.buildDir}/outputs/flutter-bundle");
rename {
return "${filename}.aab"
}
}
**
}
}
}
Thanks for the update. Seeing the same behavior as reported.
+1 I have faced the same issue too. The build failed when build appbundle with archivesBaseName modified in build.gradle
+1 I have faced the same issue too. The build failed when build appbundle with archivesBaseName modified in build.gradle
Is there an existing issue for this?
Steps to reproduce
flutter create bug
command.projectRoot/android/app/gradle
.........
......
}
Screenshots or Video
Screenshots / Video demonstration
[Upload media here]Logs
Logs
It was too long, so I uploaded it as a txt file. Here is the link. https://pastebin.com/0E3wYXVbFlutter Doctor output
Doctor output
```console [√] Flutter (Channel stable, 3.10.0, on Microsoft Windows [Version 10.0.22621.1555], locale ja-JP) • Flutter version 3.10.0 on channel stable at C:\Users\xxxx\AppData\Local\flutter_windows_3.10.0-stable\flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 84a1e904f4 (7 days ago), 2023-05-09 07:41:44 -0700 • Engine revision d44b5a94c9 • Dart version 3.0.0 • DevTools version 2.23.1 [√] Windows Version (Installed version of Windows is version 10 or higher) [!] Android toolchain - develop for Android devices (Android SDK version 33.0.1) • Android SDK at C:\Users\xxxx\AppData\Local\Android\sdk X cmdline-tools component is missing Run `path/to/sdkmanager --install "cmdline-tools;latest"` See https://developer.android.com/studio/command-line for more details. X Android license status unknown. Run `flutter doctor --android-licenses` to accept the SDK licenses. See https://flutter.dev/docs/get-started/install/windows#android-setup for more details. [√] Chrome - develop for the web • Chrome at C:\Users\xxxx\AppData\Local\Google\Chrome\Application\chrome.exe [!] Visual Studio - develop for Windows (Visual Studio Build Tools 2019 16.11.9) • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools • Visual Studio Build Tools 2019 version 16.11.32106.194 X The current Visual Studio installation is incomplete. Please reinstall Visual Studio. [√] Android Studio (version 2022.1) • Android Studio at C:\Program Files\Android\Android Studio • Flutter plugin can be installed from: https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-9505619) [√] Android Studio (version 2022.2) • Android Studio at C:\Users\xxxx\Downloads\android-studio-2022.2.1.17-windows\android-studio • Flutter plugin can be installed from: https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 17.0.6+0-b2043.56-9586694) [√] Android Studio (version 2022.1) • Android Studio at C:\Users\xxxx\Desktop\android-studio-2022.1.1.10-windows\android-studio • Flutter plugin can be installed from: https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301) [√] VS Code (version 1.74.1) • VS Code at C:\Users\xxxx\AppData\Local\Programs\Microsoft VS Code • Flutter extension can be installed from: https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter [√] Connected device (3 available) • Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.22621.1555] • Chrome (web) • chrome • web-javascript • Google Chrome 113.0.5672.93 • Edge (web) • edge • web-javascript • Microsoft Edge 112.0.1722.58 [√] Network resources • All expected network resources are available. ! Doctor found issues in 2 categories. ```