如何使用gradle在manifest中设置testOnly属性

时间:2017-02-24 21:48:53

标签: android gradle android-gradle

Gradle可以设置一些清单属性,就像:

public class ViewManagerViewModel : ViewModelBaseEx { public ViewManagerModel Model; public ObservableCollection<ViewWrapper> Views { get; private set; } public ObservableCollection<ViewWrapper> ViewTemplates { get; private set; } public IList SelectedViews { get; set; } public RelayCommand<DataGridCellEditEndingEventArgs> CellEditEndingCommand { get; set; } public RelayCommand<SelectionChangedEventArgs> SelectChangeCommand { get; set; } public ViewManagerViewModel(Document doc) { Model = new ViewManagerModel(doc); Views = Model.CollectViews(); ViewTemplates = Model.CollectViewTemplates(); CellEditEndingCommand = new RelayCommand<DataGridCellEditEndingEventArgs>(args => OnCellEditEnding(args)); SelectChangeCommand = new RelayCommand<SelectionChangedEventArgs>(args => OnSelectionChanged(args)); } private void OnSelectionChanged(SelectionChangedEventArgs e) { // do something } /// <summary> /// Logic for handling cell editing events. /// </summary> /// <param name="e">DataGrid Row object.</param> private void OnCellEditEnding(DataGridCellEditEndingEventArgs e) { var wrapper = e.Row.Item as ViewWrapper; switch (e.Column.SortMemberPath) { case "Name": Model.ChangeName(wrapper); break; case "ViewGroup": Model.SetParameter(wrapper, "View Group", wrapper.ViewGroup); break; case "ViewSubGroup": Model.SetParameter(wrapper, "View Sub Group", wrapper.ViewSubGroup); break; default: break; } } public override void Apply() { var vw = new List<ViewWrapper>(); foreach (ViewWrapper v in SelectedViews) { vw.Add(v); } Model.Delete(vw); // update collection so that rows get deleted in datagrid foreach (ViewWrapper i in vw) { Views.Remove(i); } } } targetSdkVersion

有没有办法用gradle添加android:testOnly应用程序属性而不用手触摸清单

https://developer.android.com/guide/topics/manifest/application-element.html#testOnly

1 个答案:

答案 0 :(得分:0)

您可以使用Gradle创建自定义资源值。例如。在您的应用模块的 android - &gt;下的 build.gradle defaultConfig

IdentDefs

然后在你的AndroidManifest.xml中

macro iterateFields*(t: typed): untyped =
  echo "--------------------------------"

  # check type of t
  var tTypeImpl = t.getTypeImpl
  echo tTypeImpl.len
  echo tTypeImpl.kind
  echo tTypeImpl.typeKind
  echo tTypeImpl.treeRepr

  case tTypeImpl.typeKind:
  of ntyTuple:
    # For a tuple the IdentDefs are top level, no need to descent
    discard
  of ntyObject:
    # For an object we have to descent to the nnkRecList
    tTypeImpl = tTypeImpl[2]
  else:
    error "Not a tuple or object"

  # iterate over fields
  for child in tTypeImpl.children:
    if child.kind == nnkIdentDefs:
      let field = child[0] # first child of IdentDef is a Sym corresponding to field name
      let ftype = child[1] # second child is type
      echo "Iterating field: " & $field & " -> " & $ftype
    else:
      echo "Unexpected kind: " & child.kind.repr
      # Note that this can happen for an object with a case
      # fields, which would give a child of type nnkRecCase.
      # How to handle them depends on the use case.

# small test
type
  TestObj = object
    x: int
    y: int
    name: string

let t = (x: 0, y: 1, name: "")
let o = TestObj(x: 0, y: 1, name: "")

iterateFields(t)
iterateFields(o)    

E.g。你可以将它设置为不同风格的不同值