我在Android Studio中使用gradle创建了一个新的应用程序,现在我需要在资源中制作大约10个具有不同包名和值的版本.我在示例中制作了自定义flavor,并希望使用自定义值替换此自定义flavor中的一些字符串.我找到了这样的例子:
filter(org.apache.tools.ant.filters.ReplaceTokens, tokens: ['version': '2.2'])
Run Code Online (Sandbox Code Playgroud)
但我不知道该把它放在哪里.据我所知,我需要把它放到单独的任务中,但如何通过IDE调用此任务?
此外,我需要在Java类和Content Provider的auth中替换一些变量,也许我需要通过将文件复制到flavor1文件夹并让gradle合并它来实现这一点,但似乎错误的解决方案是存储多个文件的副本line ...也许我需要为这一切使用其他一些解决方案?
这是build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4.2'
}
}
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':JazzyListView')
compile project(':ABS')
compile project(':Volley')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
versionCode 5
versionName "3.0"
minSdkVersion 8
targetSdkVersion 17
}
sourceSets {
main {
manifest.srcFile 'src/main/AndroidManifest.xml'
java.srcDirs = ['src/main/java']
res.srcDirs = ['src/main/res']
}
}
productFlavors {
flavor1 {
packageName "com.example.flavor1"
}
flavor2 { …Run Code Online (Sandbox Code Playgroud) 例如,我们有多个条目:
entry: {
main: "./app/entry.js",
view: "./app/entry.js",
},
Run Code Online (Sandbox Code Playgroud)
如何将当前名称(主要或视图)传递给entry.js?
理想的解决方案将是这样的:
new webpack.DefinePlugin({
'_ENTRY_': '[name]'
}),
Run Code Online (Sandbox Code Playgroud)
像其他配置选项可以有,但当然DefinePlugin不知道如何处理这个...
有一种东西叫作文。https://ngxs.gitbook.io/ngxs/advanced/composition
我希望它能让我为所有网格构建可重用状态。喜欢:
@State<GridStateModel<any>>({
name: 'basegridstate',
defaults: {
total: 0,
rows: []
}
})
export class BaseGridState {
@Action(LoadGridRows)
loadRows({patchState, dispatch, setState}: StateContext<GridStateModel<any>>) {
patchState({
total: 2,
});
}
}
Run Code Online (Sandbox Code Playgroud)
然后我想将其扩展很多次,以便在每个网格中使用以获得自己的数据。
喜欢
@State<GridStateModel<Product>>({
name: 'cataloggrid',
defaults: {
total: 0,
rows: []
}
})
export class CatalogGridState extends BaseGridState {
@Action(LoadCatalogRows)
loadCatalogRows({patchState, dispatch, setState}: StateContext<GridStateModel<any>>) {
patchState({
total: 3,
});
dispatch(new LoadGridRows());
}
}
Run Code Online (Sandbox Code Playgroud)
但问题是在扩展基数一的所有其他状态上调度调用 LoadGridRows :(
有没有办法让它只在当前状态下工作?或者也许有其他方法可以重用具有相同逻辑但自定义数据的状态?