Update simple sample app to use a resource directly from code
Also, add getting of 10 non-existing resource ids with ids that we
can mangle with in resource shrinking.
Bug: 148441055
Change-Id: Ibfd966f575f13fb96251b043d1a395153b73e4a5
diff --git a/src/test/sampleApks/simple/res/layout/main.xml b/src/test/sampleApks/simple/res/layout/main.xml
index 7859435..ab673af 100644
--- a/src/test/sampleApks/simple/res/layout/main.xml
+++ b/src/test/sampleApks/simple/res/layout/main.xml
@@ -14,5 +14,5 @@
android:layout_height="wrap_content"
android:layout_width="match_parent" android:id="@+id/PressButton"
android:layout_margin="2dip"
- android:text="Do something"/>
+ android:text="@string/referenced_from_layout"/>
</LinearLayout>
diff --git a/src/test/sampleApks/simple/res/values/strings.xml b/src/test/sampleApks/simple/res/values/strings.xml
index 8bae26c..5bf4844 100644
--- a/src/test/sampleApks/simple/res/values/strings.xml
+++ b/src/test/sampleApks/simple/res/values/strings.xml
@@ -6,4 +6,7 @@
-->
<resources>
<string name="app_name">R8 simple app</string>
+ <string name="referenced_from_layout">Push it</string>
+ <string name="referenced_from_code">code txt</string>
+ <string name="not_used">not used</string>
</resources>
diff --git a/src/test/sampleApks/simple/src/com/android/tools/r8/sample/simple/R8Activity.java b/src/test/sampleApks/simple/src/com/android/tools/r8/sample/simple/R8Activity.java
index 4a09fd4..67aca2b 100644
--- a/src/test/sampleApks/simple/src/com/android/tools/r8/sample/simple/R8Activity.java
+++ b/src/test/sampleApks/simple/src/com/android/tools/r8/sample/simple/R8Activity.java
@@ -7,11 +7,40 @@
import android.app.Activity;
import android.os.Bundle;
import com.android.tools.r8.sample.simple.R;
+import java.util.ArrayList;
+import android.content.res.Resources;
+
public class R8Activity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTheme(android.R.style.Theme_Light);
setContentView(R.layout.main);
+ System.out.println(R.string.referenced_from_code);
+ useResources();
+ }
+
+
+ public void useResources() {
+ // Add usage of resource identifiers with ID's that would never
+ // exist in aapt generated R class (so that we can swap them out).
+ ArrayList<Integer> resources = new ArrayList();
+ resources.add(0x7fDEAD01);
+ resources.add(0x7fDEAD02);
+ resources.add(0x7fDEAD03);
+ resources.add(0x7fDEAD04);
+ resources.add(0x7fDEAD05);
+ resources.add(0x7fDEAD06);
+ resources.add(0x7fDEAD07);
+ resources.add(0x7fDEAD08);
+ resources.add(0x7fDEAD09);
+ resources.add(0x7fDEAD0a);
+ for (int id : resources) {
+ try {
+ getResources().getResourceName(id);
+ } catch (Resources.NotFoundException e) {
+ // Do nothing
+ }
+ }
}
}