Android Studio codestyles/Project.xml Configuration

huangapple go评论87阅读模式
英文:

Android Studio codestyles/Project.xml Configuration

问题

我在处理 Android 项目的 project.xml 配置方面遇到了问题。我希望按照该文件中提到的编码风格进行编码,并且不希望 Android Studio 自己在此文件中添加任何内容。

问题

在处理项目时,Android Studio 会在自己中添加以下行。

 <option name="PACKAGES_TO_USE_STAR_IMPORTS">
    <value>
      <package name="java.util" alias="false" withSubpackages="false" />
      <package name="kotlinx.android.synthetic" alias="false" withSubpackages="true" />
      <package name="io.ktor" alias="false" withSubpackages="true" />
    </value>
  </option>
  <option name="PACKAGES_IMPORT_LAYOUT">
    <value>
      <package name="" alias="false" withSubpackages="true" />
      <package name="java" alias="false" withSubpackages="true" />
      <package name="javax" alias="false" withSubpackages="true" />
      <package name="kotlin" alias="false" withSubpackages="true" />
      <package name="" alias="true" withSubpackages="true" />
    </value>
  </option>

有没有办法阻止 Android Studio 添加这些行?我尝试了不同的方法,但无法得到期望的结果。

这是我想要遵循的实际 project.xml 文件内容:

<component name="ProjectCodeStyleConfiguration">
  <code_scheme name="Project" version="173">
    <option name="RIGHT_MARGIN" value="150" />
    <DBN-PSQL>
      <case-options enabled="true">
        <option name="KEYWORD_CASE" value="lower" />
        <option name="FUNCTION_CASE" value="lower" />
        <option name="PARAMETER_CASE" value="lower" />
        <option name="DATATYPE_CASE" value="lower" />
        <option name="OBJECT_CASE" value="preserve" />
      </case-options>
      <formatting-settings enabled="false" />
    </DBN-PSQL>
    <DBN-SQL>
      <case-options enabled="true">
        <option name="KEYWORD_CASE" value="lower" />
        <option name="FUNCTION_CASE" value="lower" />
        <option name="PARAMETER_CASE" value="lower" />
        <option name="DATATYPE_CASE" value="lower" />
        <option name="OBJECT_CASE" value="preserve" />
      </case-options>
      <formatting-settings enabled="false">
        <option name="STATEMENT_SPACING" value="one_line" />
        <option name="CLAUSE_CHOP_DOWN" value="chop_down_if_statement_long" />
        <option name="ITERATION_ELEMENTS_WRAPPING" value="chop_down_if_not_single" />
      </formatting-settings>
    </DBN-SQL>
    <JetCodeStyleSettings>
      <option name="NAME_COUNT_TO_USE_STAR_IMPORT" value="2147483647" />
      <option name="NAME_COUNT_TO_USE_STAR_IMPORT_FOR_MEMBERS" value="2147483647" />
      <option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
    </JetCodeStyleSettings>
    <codeStyleSettings language="XML">
      <option name="RIGHT_MARGIN" value="300" />
      <indentOptions>
        <option name="CONTINUATION_INDENT_SIZE" value="4" />
      </indentOptions>
      <arrangement>
        <rules>
          <section>
            <rule>
              <match>
                <AND>
                  <NAME>xmlns:android</NAME>
                  <XML_ATTRIBUTE />
                  <XML_NAMESPACE>^$</XML_NAMESPACE>
                </AND>
              </match>
            </rule>
          </section>
          <section>
            <rule>
              <match>
                <AND>
                  <NAME>xmlns:.*</NAME>
                  <XML_ATTRIBUTE />
                  <XML_NAMESPACE>^$</XML_NAMESPACE>
                </AND>
              </match>
              <order>BY_NAME</order>
            </rule>
          </section>
          <section>
            <rule>
              <match>
                <AND>
                  <NAME>.*:id</NAME>
                  <XML_ATTRIBUTE />
                  <XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
                </AND>
              </match>
            </rule>
英文:

I am struggling with configuration of project.xml of android project. I want to follow the coding style mentioned in this file and I don't want Android Studio to add any stuff in this file itself.

Problem

While working on the project Android studio add following lines in itself.

 <option name="PACKAGES_TO_USE_STAR_IMPORTS">
    <value>
      <package name="java.util" alias="false" withSubpackages="false" />
      <package name="kotlinx.android.synthetic" alias="false" withSubpackages="true" />
      <package name="io.ktor" alias="false" withSubpackages="true" />
    </value>
  </option>
  <option name="PACKAGES_IMPORT_LAYOUT">
    <value>
      <package name="" alias="false" withSubpackages="true" />
      <package name="java" alias="false" withSubpackages="true" />
      <package name="javax" alias="false" withSubpackages="true" />
      <package name="kotlin" alias="false" withSubpackages="true" />
      <package name="" alias="true" withSubpackages="true" />
    </value>
  </option>

Is there any way that I can prevent android studio from adding these lines? I have tried different methods to do that but unable to produces the desire results.

This is the actual project.xml file that I want to follow

<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<option name="RIGHT_MARGIN" value="150" />
<DBN-PSQL>
<case-options enabled="true">
<option name="KEYWORD_CASE" value="lower" />
<option name="FUNCTION_CASE" value="lower" />
<option name="PARAMETER_CASE" value="lower" />
<option name="DATATYPE_CASE" value="lower" />
<option name="OBJECT_CASE" value="preserve" />
</case-options>
<formatting-settings enabled="false" />
</DBN-PSQL>
<DBN-SQL>
<case-options enabled="true">
<option name="KEYWORD_CASE" value="lower" />
<option name="FUNCTION_CASE" value="lower" />
<option name="PARAMETER_CASE" value="lower" />
<option name="DATATYPE_CASE" value="lower" />
<option name="OBJECT_CASE" value="preserve" />
</case-options>
<formatting-settings enabled="false">
<option name="STATEMENT_SPACING" value="one_line" />
<option name="CLAUSE_CHOP_DOWN" value="chop_down_if_statement_long" />
<option name="ITERATION_ELEMENTS_WRAPPING" value="chop_down_if_not_single" />
</formatting-settings>
</DBN-SQL>
<JetCodeStyleSettings>
<option name="NAME_COUNT_TO_USE_STAR_IMPORT" value="2147483647" />
<option name="NAME_COUNT_TO_USE_STAR_IMPORT_FOR_MEMBERS" value="2147483647" />
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
</JetCodeStyleSettings>
<codeStyleSettings language="XML">
<option name="RIGHT_MARGIN" value="300" />
<indentOptions>
<option name="CONTINUATION_INDENT_SIZE" value="4" />
</indentOptions>
<arrangement>
<rules>
<section>
<rule>
<match>
<AND>
<NAME>xmlns:android</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>xmlns:.*</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*:id</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*:name</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>name</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>style</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
<order>ANDROID_ATTRIBUTE_ORDER</order>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>.*</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
</section>
</rules>
</arrangement>
</codeStyleSettings>
<codeStyleSettings language="kotlin">
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
<option name="FIELD_ANNOTATION_WRAP" value="0" />
</codeStyleSettings>
</code_scheme>
</component>

Any help will be appreciated, Thanks!

答案1

得分: 3

我觉得这是在Android Studio V.4.0.1中的一个问题 youtrack.jetbrains.com/issue/KT-39937,这在最新版的Android Studio中已经得到解决。

英文:

I figured it was an issue in Android-Studio V.4.0.1 youtrack.jetbrains.com/issue/KT-39937 which has been resolved in latest Android Studio

huangapple
  • 本文由 发表于 2020年8月30日 19:13:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/63656836.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定