trie 实现在 flutter 中抛出收缩器错误
trie implementation throws shrinker error in flutter
我正在研究可以与 flutter_typeahed 包一起使用的搜索。
我找到了一个名为 trie
的包,但它没有空安全性,所以我想包括它并为项目和我自己的项目做出贡献。
由于整个 trie
文件很大,我提供 link 给 pastebin。
这是我写的 Search
class:
class Search {
final Map<String, RecipeModel> _map = Map.fromIterable(
Store.instance.getAllRecipes(),
key: (recipe) => RecipeModel().recipeName!);
late final Trie trie;
Search() {
// This will be O[n]
trie = Trie.list(_map.keys.toList());
}
late RecipeModel recipe;
RecipeModel returnRecipe(String? suggestion) {
if (suggestion == null) return recipe;
// This will be O(1) instead of O(n) [better]
final RecipeModel? found = _map[suggestion];
return found ?? recipe;
}
List<String> returnSuggestions(String prefix) {
//will return O[W*L] ad-hoc search was O[n^2]
return trie.getAllWordsWithPrefix(prefix);
}
}
但我收到以下错误:
Cannot fit requested classes in a single dex file (# methods: 66909 > 65536)
com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:
The number of method references in a .dex file cannot exceed 64K.
The shrinker may have failed to optimize the Java bytecode.
To disable the shrinker, pass the `--no-shrink` flag to this command.
我该怎么做才能使我的代码高效并修复错误?
N.B:RecipeModel 只是一个包含 recipeName、authorId 等的模型。Store.instance.getAllRecipes(),
returns 食谱列表
我必须启用 multidex。我必须更改以下内容:
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.food_app"
minSdkVersion 17
targetSdkVersion 30
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true // add this line
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:multidex:1.0.1' // add this one
}
我正在研究可以与 flutter_typeahed 包一起使用的搜索。
我找到了一个名为 trie
的包,但它没有空安全性,所以我想包括它并为项目和我自己的项目做出贡献。
由于整个 trie
文件很大,我提供 link 给 pastebin。
这是我写的 Search
class:
class Search {
final Map<String, RecipeModel> _map = Map.fromIterable(
Store.instance.getAllRecipes(),
key: (recipe) => RecipeModel().recipeName!);
late final Trie trie;
Search() {
// This will be O[n]
trie = Trie.list(_map.keys.toList());
}
late RecipeModel recipe;
RecipeModel returnRecipe(String? suggestion) {
if (suggestion == null) return recipe;
// This will be O(1) instead of O(n) [better]
final RecipeModel? found = _map[suggestion];
return found ?? recipe;
}
List<String> returnSuggestions(String prefix) {
//will return O[W*L] ad-hoc search was O[n^2]
return trie.getAllWordsWithPrefix(prefix);
}
}
但我收到以下错误:
Cannot fit requested classes in a single dex file (# methods: 66909 > 65536)
com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:
The number of method references in a .dex file cannot exceed 64K.
The shrinker may have failed to optimize the Java bytecode.
To disable the shrinker, pass the `--no-shrink` flag to this command.
我该怎么做才能使我的代码高效并修复错误?
N.B:RecipeModel 只是一个包含 recipeName、authorId 等的模型。Store.instance.getAllRecipes(),
returns 食谱列表
我必须启用 multidex。我必须更改以下内容:
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.food_app"
minSdkVersion 17
targetSdkVersion 30
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true // add this line
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:multidex:1.0.1' // add this one
}