title: How do i add a new resource identifier for a drawable in an app decompiled by apktool?
body: <p>I'm trying to inject a imageview in to a decompiled apk's smali code. But the drawable used by the imageview needs it's own unique resource identifier. So far i have been unsuccessful in adding a new resource identifier without getting building  errors from apktool. Any help would be greatly appreciated. Here are the steps i have taken: </p>
  
  <p><strong>Step 1:</strong> </p>
  
  <p>Find the last resource id in the public.xml file.
  In my case : <code>&lt;public type="menu" name="search_item_minioverflow" id="0x7f0d0003" /&gt;</code>.</p>
  
  <p>Convert the id from hex to text, this gives me the following: <em>2131558403</em>.
  Increment the number by 1 and convert it back to hex : <em>0x7f0d0004</em>.</p>
  
  <p><strong>Step 2:</strong></p>
  
  <p>Paste the new resource with incremented id: <code>&lt;public type="drawable" name="cross" id="0x7f0d0004" /&gt;</code> in to the public.xml file.</p>
  
  <p><strong>Step 3:</strong></p>
  
  <p>Paste the new static field with incremented id: <code>.field public static final cross:I = 0x7f0d0004</code> in to the R$drawable.smali file.</p>
  
  <p><strong>Finally:</strong></p>
  
  <p>I try to build the decompiled apk with apktool but receive the following building error:</p>
  
  <pre><code>res\values\public.xml:986: error: Public resource drawable/cross has conflicting type codes for its public identifiers (0x2 vs 0xd).
      W:
      brut.androlib.AndrolibException: brut.common.BrutException: could not exec (exit code = 1): [C:\Users\user\AppData\Local\Temp\brut_util_Jar_6742820997882567173.tmp, p, --forced-package-id, 127, --min-sdk-version, 14, --target-sdk-version, 25, --version-code, 111, --version-name, 5.2.1, --no-version-vectors, -F, C:\Users\user\AppData\Local\Temp\APKTOOL3513689331380739071.tmp, -0, arsc, -0, png, -0, arsc, -I, C:\Users\user\AppData\Local\Temp\1.apk, -S, C:\Users\user\Desktop\tune\res, -M, C:\Users\user\Desktop\tune\AndroidManifest.xml]
  </code></pre>
  
  <p><strong>EDIT:</strong> And here is the smali code being injected, it runs normally in the apk it's taken from: </p>
  
  <pre><code>.method public showDialog()V
      .locals 6
  
      .line 92
      new-instance v0, Landroid/widget/RelativeLayout;
  
      invoke-virtual {p0}, Lcom/example/MainActivity;-&gt;getApplicationContext()Landroid/content/Context;
  
      move-result-object v1
  
      invoke-direct {v0, v1}, Landroid/widget/RelativeLayout;-&gt;&lt;init&gt;(Landroid/content/Context;)V
  
      .line 93
      .local v0, "overlay":Landroid/widget/RelativeLayout;
      new-instance v1, Landroid/widget/RelativeLayout$LayoutParams;
  
      const/4 v2, -0x1
  
      invoke-direct {v1, v2, v2}, Landroid/widget/RelativeLayout$LayoutParams;-&gt;&lt;init&gt;(II)V
  
      .line 94
      .local v1, "params":Landroid/widget/RelativeLayout$LayoutParams;
      invoke-virtual {v0, v1}, Landroid/widget/RelativeLayout;-&gt;setLayoutParams(Landroid/view/ViewGroup$LayoutParams;)V
  
      .line 95
      const/4 v2, 0x0
  
      invoke-virtual {v0, v2}, Landroid/widget/RelativeLayout;-&gt;setBackgroundColor(I)V
  
      .line 96
      invoke-virtual {v0, v2}, Landroid/widget/RelativeLayout;-&gt;setClickable(Z)V
  
      .line 97
      invoke-virtual {v0, v2}, Landroid/widget/RelativeLayout;-&gt;setFocusable(Z)V
  
      .line 99
      new-instance v3, Landroid/widget/ImageView;
  
      invoke-virtual {p0}, Lcom/example/MainActivity;-&gt;getApplicationContext()Landroid/content/Context;
  
      move-result-object v4
  
      invoke-direct {v3, v4}, Landroid/widget/ImageView;-&gt;&lt;init&gt;(Landroid/content/Context;)V
  
      .line 100
      .local v3, "cross":Landroid/widget/ImageView;
      const v4, 0x7f060055
  
      invoke-virtual {v3, v4}, Landroid/widget/ImageView;-&gt;setImageResource(I)V
  
      .line 102
      new-instance v4, Landroid/widget/RelativeLayout$LayoutParams;
  
      const/4 v5, -0x2
  
      invoke-direct {v4, v5, v5}, Landroid/widget/RelativeLayout$LayoutParams;-&gt;&lt;init&gt;(II)V
  
      move-object v1, v4
  
      .line 103
      const/16 v4, 0xb
  
      invoke-virtual {v1, v4}, Landroid/widget/RelativeLayout$LayoutParams;-&gt;addRule(I)V
  
      .line 104
      invoke-virtual {v3}, Landroid/widget/ImageView;-&gt;getDrawable()Landroid/graphics/drawable/Drawable;
  
      move-result-object v4
  
      invoke-virtual {v4}, Landroid/graphics/drawable/Drawable;-&gt;getIntrinsicHeight()I
  
      move-result v4
  
      div-int/lit8 v4, v4, 0x2
  
      invoke-virtual {v3}, Landroid/widget/ImageView;-&gt;getDrawable()Landroid/graphics/drawable/Drawable;
  
      move-result-object v5
  
      invoke-virtual {v5}, Landroid/graphics/drawable/Drawable;-&gt;getIntrinsicWidth()I
  
      move-result v5
  
      div-int/lit8 v5, v5, 0x2
  
      rsub-int/lit8 v5, v5, 0x50
  
      invoke-virtual {v1, v2, v4, v5, v2}, Landroid/widget/RelativeLayout$LayoutParams;-&gt;setMargins(IIII)V
  
      .line 105
      invoke-virtual {v3, v1}, Landroid/widget/ImageView;-&gt;setLayoutParams(Landroid/view/ViewGroup$LayoutParams;)V
  
      .line 107
      invoke-virtual {v0, v3}, Landroid/widget/RelativeLayout;-&gt;addView(Landroid/view/View;)V
  
      .line 109
      new-instance v2, Landroid/app/Dialog;
  
      const v4, 0x1030010
  
      invoke-direct {v2, p0, v4}, Landroid/app/Dialog;-&gt;&lt;init&gt;(Landroid/content/Context;I)V
  
      .line 110
      .local v2, "topDialog":Landroid/app/Dialog;
      invoke-virtual {v2, v0}, Landroid/app/Dialog;-&gt;setContentView(Landroid/view/View;)V
  
      .line 111
      invoke-virtual {v2}, Landroid/app/Dialog;-&gt;show()V
  
      .line 113
      return-void
  .end method
  </code></pre>