updateRawFolder function
void
updateRawFolder(
- String? soundPath
)
Implementation
void updateRawFolder(String? soundPath) {
print("Please provide the path to your sound file:");
if (soundPath != null) {
final assetFile = File(soundPath);
if (!assetFile.existsSync()) {
print("Error: Sound file not found at the specified path: $soundPath");
return;
}
final rawResDir = Directory('android/app/src/main/res/raw');
if (!rawResDir.existsSync()) {
rawResDir.createSync(recursive: true);
}
final filename = assetFile.uri.pathSegments.last;
final rawSoundFile = File('${rawResDir.path}/$filename');
assetFile.copySync(rawSoundFile.path);
final keepXmlContent = '''
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools"
tools:shrinkMode="strict"
tools:keep="@raw/${filename.split(".").first}"
tools:discard="@layout/unused_layout" />
''';
final keepXmlFile = File('${rawResDir.path}/keep.xml');
keepXmlFile.writeAsStringSync(keepXmlContent);
}
}