title: Trying to use <!ENTITY in ANDROID resources with error: "The entity was referenced, but not declared."
body: <p>I'm following this solution to use enetities in my string resource file:</p>
  
  <p><a href="https://stackoverflow.com/questions/6679518/is-it-possible-to-do-string-substitution-in-android-resource-xml-files-directly">Is it possible to do string substitution in Android resource XML files directly?</a></p>
  
  <p>I'm using an external file in the resource tree: <code>/res/raw/entities.dtd</code>, its content:</p>
  
  <pre><code>&lt;!ENTITY ent_devicename "MyDeviceName"&gt;
  </code></pre>
  
  <p>In the <code>string.xml</code> resource file:</p>
  
  <pre><code>&lt;!DOCTYPE resources [
      &lt;!ENTITY % ent_devicename SYSTEM "../raw/entities.dtd"&gt;
      %ent_devicename;
  ]&gt;
  
  &lt;resources&gt;
      &lt;string name="name"&gt;The name is &amp;ent_devicename;&lt;/string&gt;
  &lt;/resources&gt;
  </code></pre>
  
  <p>but I get this error:</p>
  
  <blockquote>
    <p>The entity "ent_devicename" was referenced, but not declared.</p>
  </blockquote>
  
  <p>As you can see Android Studio recognizes the external entity file:</p>
  
  <p><a href="https://i.stack.imgur.com/qxJjT.png" rel="noreferrer"><img src="https://i.stack.imgur.com/qxJjT.png" alt="enter image description here"></a></p>
  
  <p>and the entity:</p>
  
  <p><a href="https://i.stack.imgur.com/AA9ay.png" rel="noreferrer"><img src="https://i.stack.imgur.com/AA9ay.png" alt="enter image description here"></a></p>
  
  <p>Can someone provide full a correct example to make things work? <strong>I mean a full compilable Android Studio project, with entities declarations in a separated file.</strong></p>
  
  <p><strong>UPDATE</strong>
  Ok, if you pay more attention to this w3schools link:</p>
  
  <p><a href="https://stackoverflow.com/questions/6679518/is-it-possible-to-do-string-substitution-in-android-resource-xml-files-directly">https://www.w3schools.com/xml/xml_dtd_entities.asp</a></p>
  
  <p>you see the solution:</p>
  
  <p>the external <code>entities.dtd</code> files contains</p>
  
  <pre><code>&lt;!ENTITY ent_devicename "MyDeviceName"&gt;
  </code></pre>
  
  <p>then the new string resource resource:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  
      &lt;!DOCTYPE resources [
          &lt;!ENTITY ent_devicename SYSTEM "../raw/entities.dtd"&gt;
          ]&gt;
  
  &lt;resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="Typos"&gt;
      &lt;string name="ent_devicenamxxe2"&gt;&amp;ent_devicename;&lt;/string&gt;
  </code></pre>
  
  <p>I changed <code>&lt;!ENTITY % ent_devicename</code> to <code>&lt;!ENTITY ent_devicename</code> (no more %)
  I deleted <code>%ent_devicename;</code></p>
  
  <p>Now it compiles but the resulting APK seems to ignore the entity values (uses an empty string). So the problem is not resolved!</p>
  
  <p>Let me know!</p>