평생 동안 나는 이것을 알아낼 수 없습니다. 알아 냈다고 생각했지만 아니요
아래와 같은 항목이 포함된 XML 파일이 있습니다.
<compat-change description="Flag {@link android.content.Context#BIND_INCLUDE_CAPABILITIES} is used to pass while-in-use capabilities from client process to bound service. In targetSdkVersion R and above, if client is a TOP activity, when this flag is present, bound service gets all while-in-use capabilities; when this flag is not present, bound service gets no while-in-use capability from client." enableAfterTargetSdk="29" id="136274596" name="PROCESS_CAPABILITY_CHANGE_ID"/>
ID와 이름(항상 정적 값 및 동일한 순서)을 일치시켜야 하지만 Sdk 값(변경 가능)을 변경해야 합니다.
Sdk="29" id="136274596" name="PROCESS_CAPABILITY"
나는 노력했다
sed -i '/Sdk=\"[0-9]\+\".*id="143937733".*name="PROCESS_CAPABILITY"/ {s/Sdk=\"[0-9]\+\"/Sdk=\"0\"/1;}'
어떤 제안이라도 대단히 감사하겠습니다.
답변1
xmlstarlet
다음과 같은 적절한 XML 도구를 사용하는 것이 좋습니다 .
xmlstarlet ed -u '
//compat-change[@id="136274596"][starts-with(@name,"PROCESS_CAPABILITY")]/@enableAfterTargetSdk
' -v 0 file.xml
전임자.
$ xmlstarlet ed -u '//compat-change[@id="136274596"][starts-with(@name,"PROCESS_CAPABILITY")]/@enableAfterTargetSdk' -v 0 file.xml
<?xml version="1.0"?>
<compat-change description="Flag {@link android.content.Context#BIND_INCLUDE_CAPABILITIES} is used to pass while-in-use capabilities from client process to bound service. In targetSdkVersion R and above, if client is a TOP activity, when this flag is present, bound service gets all while-in-use capabilities; when this flag is not present, bound service gets no while-in-use capability from client." enableAfterTargetSdk="0" id="136274596" name="PROCESS_CAPABILITY_CHANGE_ID"/>
답변2
사용sed
$ sed -E 's/(Sdk=")[^"]*(" id="136274596" name="PROCESS_CAPABILITY)/\10\2/' input_file
<compat-change description="Flag {@link android.content.Context#BIND_INCLUDE_CAPABILITIES} is used to pass while-in-use capabilities from client process to bound service. In targetSdkVersion R and above, if client is a TOP activity, when this flag is present, bound service gets all while-in-use capabilities; when this flag is not present, bound service gets no while-in-use capability from client." enableAfterTargetSdk="0" id="136274596" name="PROCESS_CAPABILITY_CHANGE_ID"/>