Closed duytient31 closed 1 month ago
I am facing the same issue as I have set up 3 flavors (development, staging, and production). Could you please help @lijy91?
In my case, because of the custom flavor, my end folder is named Build/Products/Release-development
. If there was a way to manually adjust this path in the library, that would be amazing!
A little digging into the code reveals that this is because of an assumption made in the BuildMacOsResultResolver
class where it appends the buildMode
at the end of the assumed path (i.e. build/macos/Build/Products/
)
Here's the code 👇
A possible solution could be to keep the existing logic as it is, and just prepend it with a little customisation where the user would be able to provide a custom output-directory
inside distribute_options.yaml
like this:
output: dist/
releases:
- name: development
jobs:
# Build your dmg
- name: release-development-macos
package:
platform: macos
target: dmg
# The plugin will look for the `.app` file inside the provided directory
output-directory: build/macos/Build/Products/Release-development
build_args:
flavor: development
target: lib/main_development.dart
And BuildMacOsResultResolver
might be able to accommodate this customisation by asking for a variable in its constructor like this:
class BuildMacOsResultResolver extends BuildResultResolver {
final String? customPath; // Ask for this new variable
const BuildMacOsResultResolver({this.customPath});
@override
BuildResult resolve(BuildConfig config) {
final r = BuildMacOsResult(config, customPath);
final String pattern = '${r.outputDirectory.path}/*.app';
r.outputFiles = Glob(pattern).listSync().map((e) => File(e.path)).toList();
return r;
}
}
class BuildMacOsResult extends BuildResult {
final String? customPath; // Ask for this new variable
BuildMacOsResult(BuildConfig config, this.customPath) : super(config);
@override
Directory get outputDirectory {
String buildMode = ReCase(config.mode.name).sentenceCase;
String path = customPath ?? 'build/macos/Build/Products/$buildMode';
return Directory(path);
}
}
I hope this helps somehow :)
Another possible (and a much easier) solution that does not require the end user to know anything about the final build
directory and the library to add any new fields would be to just make use of the flavor
value that the user already passes in his distribute_options.yaml
file like this:
class BuildMacOsResult extends BuildResult {
BuildMacOsResult(BuildConfig config) : super(config);
@override
Directory get outputDirectory {
String buildMode = ReCase(config.mode.name).sentenceCase;
// Get the value for `flavor` from the `config` object
String path = 'build/macos/Build/Products/$buildMode-${config.flavor}';
return Directory(path);
}
}
Solve it in this pr https://github.com/leanflutter/flutter_distributor/pull/196
from "outputDirectory": "build/macos/Build/Products/Release" to build/macos/Build/Products/Release-uat/ Please!!!
`{ "config": { "mode": "release", "flavor": "uat", "arguments": { "dart-define": { "APP_ENV": "dev" }, "flavor": "uat", "target": "lib/main_uat.dart" } }, "outputDirectory": "build/macos/Build/Products/Release", "duration": 457358, "outputFiles": [] } Successfully built Directory: 'build/macos/Build/Products/Release' in 457s PathNotFoundException: Directory listing failed, path = 'build/macos/Build/Products/Release/' (OS Error: No such file or directory, errno = 2)
RELEASE FAILED in 489s PathNotFoundException: Directory listing failed, path = 'build/macos/Build/Products/Release/' (OS Error: No such file or directory, errno = 2)
0 _Directory._fillWithDirectoryListing (dart:io-patch/directory_patch.dart:42:24)
1 _Directory.listSync (dart:io/directory_impl.dart:233:5)
2 AppPackageMakerZip.make (package:flutter_app_packager/src/makers/zip/app_package_maker_zip.dart:30:12)
3 FlutterAppPackager.package (package:flutter_app_packager/src/flutter_app_packager.dart:40:18)
4 FlutterDistributor.package (package:flutter_distributor/src/flutter_distributor.dart:182:51)