From 249dc0127b12679441013dd78208706feb632c59 Mon Sep 17 00:00:00 2001 From: Xavier Ducrohet Date: Fri, 25 May 2012 16:27:34 -0700 Subject: Use aapt output to feed proguard's keep list. This allows us to only keep classes that are really used either through code or through XML. Also tweak the default rules for better control of animated properties. Added a test of a custom property animation and fixed some other misc test files. Change-Id: I7cc5839a764881d8d3c7bfce0a3f12ea7cba660e --- anttasks/src/com/android/ant/AaptExecTask.java | 38 +++++---- files/ant/build.xml | 4 +- files/proguard-android.txt | 29 ++----- templates/build.template | 16 ++-- testapps/customPropAnimTest/.classpath | 8 ++ testapps/customPropAnimTest/.project | 33 ++++++++ testapps/customPropAnimTest/AndroidManifest.xml | 23 ++++++ testapps/customPropAnimTest/build.xml | 90 +++++++++++++++++++++ testapps/customPropAnimTest/proguard-project.txt | 20 +++++ testapps/customPropAnimTest/project.properties | 15 ++++ .../res/drawable-hdpi/ic_launcher.png | Bin 0 -> 9397 bytes .../res/drawable-ldpi/ic_launcher.png | Bin 0 -> 2729 bytes .../res/drawable-mdpi/ic_launcher.png | Bin 0 -> 5237 bytes .../res/drawable-xhdpi/ic_launcher.png | Bin 0 -> 14383 bytes testapps/customPropAnimTest/res/layout/main.xml | 8 ++ testapps/customPropAnimTest/res/values/strings.xml | 7 ++ .../CustomPropertyAnimationActivity.java | 22 +++++ .../android/custompropertyanimation/MyView.java | 24 ++++++ .../customViewTest/libWithCustomView/build.xml | 39 +++++---- testapps/customViewTest/mainProject/build.xml | 39 +++++---- testapps/customViewTest/mainProject/proguard.cfg | 40 --------- .../customViewTest/mainProject/project.properties | 3 + .../mainProject/res/values/strings.xml | 2 +- testapps/libsAndJarTest/app/build.xml | 11 ++- testapps/libsAndJarTest/app/project.properties | 6 +- testapps/libsAndJarTest/lib1/build.xml | 11 ++- testapps/libsAndJarTest/lib2/build.xml | 11 ++- 27 files changed, 365 insertions(+), 134 deletions(-) create mode 100644 testapps/customPropAnimTest/.classpath create mode 100644 testapps/customPropAnimTest/.project create mode 100644 testapps/customPropAnimTest/AndroidManifest.xml create mode 100644 testapps/customPropAnimTest/build.xml create mode 100644 testapps/customPropAnimTest/proguard-project.txt create mode 100644 testapps/customPropAnimTest/project.properties create mode 100644 testapps/customPropAnimTest/res/drawable-hdpi/ic_launcher.png create mode 100644 testapps/customPropAnimTest/res/drawable-ldpi/ic_launcher.png create mode 100644 testapps/customPropAnimTest/res/drawable-mdpi/ic_launcher.png create mode 100644 testapps/customPropAnimTest/res/drawable-xhdpi/ic_launcher.png create mode 100644 testapps/customPropAnimTest/res/layout/main.xml create mode 100644 testapps/customPropAnimTest/res/values/strings.xml create mode 100644 testapps/customPropAnimTest/src/com/android/custompropertyanimation/CustomPropertyAnimationActivity.java create mode 100644 testapps/customPropAnimTest/src/com/android/custompropertyanimation/MyView.java delete mode 100644 testapps/customViewTest/mainProject/proguard.cfg diff --git a/anttasks/src/com/android/ant/AaptExecTask.java b/anttasks/src/com/android/ant/AaptExecTask.java index 2b57277..c96f7d0 100644 --- a/anttasks/src/com/android/ant/AaptExecTask.java +++ b/anttasks/src/com/android/ant/AaptExecTask.java @@ -97,6 +97,7 @@ public final class AaptExecTask extends SingleDependencyTask { private String mLibraryPackagesRefid; private boolean mNonConstantId; private String mIgnoreAssets; + private String mProguardFile; /** * Input path that ignores the same folders/files that aapt does. @@ -321,6 +322,10 @@ public final class AaptExecTask extends SingleDependencyTask { mLibraryPackagesRefid = libraryPackagesRefid; } + public void setProguardFile(Path proguardFile) { + mProguardFile = TaskHelper.checkSinglePath("proguardFile", proguardFile); + } + /** * Returns an object representing a nested nocompress element. */ @@ -344,6 +349,11 @@ public final class AaptExecTask extends SingleDependencyTask { return path; } + @Override + protected String getExecTaskName() { + return "aapt"; + } + /* * (non-Javadoc) * @@ -375,24 +385,6 @@ public final class AaptExecTask extends SingleDependencyTask { libPkgProp = libPkgProp.replace(';', ':'); } } - // Call aapt. If there are libraries, we'll pass a non-null string of libs. - callAapt(libPkgProp); - } - - @Override - protected String getExecTaskName() { - return "aapt"; - } - - /** - * Calls aapt with the given parameters. - * @param resourceFilter the resource configuration filter to pass to aapt (if configName is - * non null) - * @param extraPackages an optional list of colon-separated packages. Can be null - * Ex: com.foo.one:com.foo.two:com.foo.lib - */ - private void callAapt(String extraPackages) { - Project taskProject = getProject(); final boolean generateRClass = mRFolder != null && new File(mRFolder).isDirectory(); @@ -538,9 +530,9 @@ public final class AaptExecTask extends SingleDependencyTask { } } - if (mNonConstantId == false && extraPackages != null && extraPackages.length() > 0) { + if (mNonConstantId == false && libPkgProp != null && libPkgProp.length() > 0) { task.createArg().setValue("--extra-packages"); - task.createArg().setValue(extraPackages); + task.createArg().setValue(libPkgProp); } // if the project contains libraries, force auto-add-overlay @@ -635,6 +627,12 @@ public final class AaptExecTask extends SingleDependencyTask { // Use dependency generation task.createArg().setValue("--generate-dependencies"); + // use the proguard file + if (mProguardFile != null && mProguardFile.length() > 0) { + task.createArg().setValue("-G"); + task.createArg().setValue(mProguardFile); + } + // final setup of the task task.setProject(taskProject); task.setOwningTarget(getOwningTarget()); diff --git a/files/ant/build.xml b/files/ant/build.xml index 1f85f5e..cd1bc7d 100644 --- a/files/ant/build.xml +++ b/files/ant/build.xml @@ -648,7 +648,8 @@ nonConstantId="${android.library}" libraryResFolderPathRefid="project.library.res.folder.path" libraryPackagesRefid="project.library.packages" - ignoreAssets="${aapt.ignore.assets}"> + ignoreAssets="${aapt.ignore.assets}" + proguardFile="${out.absolute.dir}/proguard.txt"> @@ -821,6 +822,7 @@ destfile="${preobfuscate.jar.file}" /> -include "${proguard.configcmd}" + -include "${out.absolute.dir}/proguard.txt" -injars ${project.all.classes.value} -outjars "${obfuscated.jar.file}" -libraryjars ${project.target.classpath.value} diff --git a/files/proguard-android.txt b/files/proguard-android.txt index 6613823..3cc5c8a 100644 --- a/files/proguard-android.txt +++ b/files/proguard-android.txt @@ -24,15 +24,7 @@ # file from your project's proguard.config path property. -keepattributes *Annotation* --keep public class * extends android.app.Activity --keep public class * extends android.app.Application --keep public class * extends android.app.Service --keep public class * extends android.content.BroadcastReceiver --keep public class * extends android.content.ContentProvider --keep public class * extends android.app.backup.BackupAgent --keep public class * extends android.preference.Preference --keep public class * extends android.support.v4.app.Fragment --keep public class * extends android.app.Fragment +-keep public class com.google.vending.licensing.ILicensingService -keep public class com.android.vending.licensing.ILicensingService # For native methods, see http://proguard.sourceforge.net/manual/examples.html#native @@ -40,21 +32,14 @@ native ; } --keep public class * extends android.view.View { - public (android.content.Context); - public (android.content.Context, android.util.AttributeSet); - public (android.content.Context, android.util.AttributeSet, int); - public void set*(...); -} - --keepclasseswithmembers class * { - public (android.content.Context, android.util.AttributeSet); -} - --keepclasseswithmembers class * { - public (android.content.Context, android.util.AttributeSet, int); +# keep setters in Views so that animations can still work. +# see http://proguard.sourceforge.net/manual/examples.html#beans +-keepclassmembers public class * extends android.view.View { + void set*(***); + *** get*(); } +# We want to keep methods in Activity that could be used in the XML attribute onClick -keepclassmembers class * extends android.app.Activity { public void *(android.view.View); } diff --git a/templates/build.template b/templates/build.template index 1ab7ea2..aea57a2 100644 --- a/templates/build.template +++ b/templates/build.template @@ -28,6 +28,15 @@ --> + + + + + + - - - - - - + + + + + + + diff --git a/testapps/customPropAnimTest/.project b/testapps/customPropAnimTest/.project new file mode 100644 index 0000000..0d12fe9 --- /dev/null +++ b/testapps/customPropAnimTest/.project @@ -0,0 +1,33 @@ + + + customPropAnimTest + + + + + + com.android.ide.eclipse.adt.ResourceManagerBuilder + + + + + com.android.ide.eclipse.adt.PreCompilerBuilder + + + + + org.eclipse.jdt.core.javabuilder + + + + + com.android.ide.eclipse.adt.ApkBuilder + + + + + + com.android.ide.eclipse.adt.AndroidNature + org.eclipse.jdt.core.javanature + + diff --git a/testapps/customPropAnimTest/AndroidManifest.xml b/testapps/customPropAnimTest/AndroidManifest.xml new file mode 100644 index 0000000..72c58d0 --- /dev/null +++ b/testapps/customPropAnimTest/AndroidManifest.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/testapps/customPropAnimTest/build.xml b/testapps/customPropAnimTest/build.xml new file mode 100644 index 0000000..d6ee0bc --- /dev/null +++ b/testapps/customPropAnimTest/build.xml @@ -0,0 +1,90 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/testapps/customPropAnimTest/proguard-project.txt b/testapps/customPropAnimTest/proguard-project.txt new file mode 100644 index 0000000..f2fe155 --- /dev/null +++ b/testapps/customPropAnimTest/proguard-project.txt @@ -0,0 +1,20 @@ +# To enable ProGuard in your project, edit project.properties +# to define the proguard.config property as described in that file. +# +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in ${sdk.dir}/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the ProGuard +# include property in project.properties. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/testapps/customPropAnimTest/project.properties b/testapps/customPropAnimTest/project.properties new file mode 100644 index 0000000..1a88dc6 --- /dev/null +++ b/testapps/customPropAnimTest/project.properties @@ -0,0 +1,15 @@ +# This file is automatically generated by Android Tools. +# Do not modify this file -- YOUR CHANGES WILL BE ERASED! +# +# This file must be checked in Version Control Systems. +# +# To customize properties used by the Ant build system edit +# "ant.properties", and override values to adapt the script to your +# project structure. +# +# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): +proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt + +# Project target. +target=android-15 + diff --git a/testapps/customPropAnimTest/res/drawable-hdpi/ic_launcher.png b/testapps/customPropAnimTest/res/drawable-hdpi/ic_launcher.png new file mode 100644 index 0000000..96a442e Binary files /dev/null and b/testapps/customPropAnimTest/res/drawable-hdpi/ic_launcher.png differ diff --git a/testapps/customPropAnimTest/res/drawable-ldpi/ic_launcher.png b/testapps/customPropAnimTest/res/drawable-ldpi/ic_launcher.png new file mode 100644 index 0000000..9923872 Binary files /dev/null and b/testapps/customPropAnimTest/res/drawable-ldpi/ic_launcher.png differ diff --git a/testapps/customPropAnimTest/res/drawable-mdpi/ic_launcher.png b/testapps/customPropAnimTest/res/drawable-mdpi/ic_launcher.png new file mode 100644 index 0000000..359047d Binary files /dev/null and b/testapps/customPropAnimTest/res/drawable-mdpi/ic_launcher.png differ diff --git a/testapps/customPropAnimTest/res/drawable-xhdpi/ic_launcher.png b/testapps/customPropAnimTest/res/drawable-xhdpi/ic_launcher.png new file mode 100644 index 0000000..71c6d76 Binary files /dev/null and b/testapps/customPropAnimTest/res/drawable-xhdpi/ic_launcher.png differ diff --git a/testapps/customPropAnimTest/res/layout/main.xml b/testapps/customPropAnimTest/res/layout/main.xml new file mode 100644 index 0000000..40f9f1a --- /dev/null +++ b/testapps/customPropAnimTest/res/layout/main.xml @@ -0,0 +1,8 @@ + + + + \ No newline at end of file diff --git a/testapps/customPropAnimTest/res/values/strings.xml b/testapps/customPropAnimTest/res/values/strings.xml new file mode 100644 index 0000000..9c3c31b --- /dev/null +++ b/testapps/customPropAnimTest/res/values/strings.xml @@ -0,0 +1,7 @@ + + + + Hello World, CustomPropertyAnimationActivity! + CustomPropertyAnimation + + \ No newline at end of file diff --git a/testapps/customPropAnimTest/src/com/android/custompropertyanimation/CustomPropertyAnimationActivity.java b/testapps/customPropAnimTest/src/com/android/custompropertyanimation/CustomPropertyAnimationActivity.java new file mode 100644 index 0000000..b1b91b9 --- /dev/null +++ b/testapps/customPropAnimTest/src/com/android/custompropertyanimation/CustomPropertyAnimationActivity.java @@ -0,0 +1,22 @@ +package com.android.custompropertyanimation; + +import android.animation.ObjectAnimator; +import android.app.Activity; +import android.os.Bundle; +import android.widget.LinearLayout; + +public class CustomPropertyAnimationActivity extends Activity { + /** Called when the activity is first created. */ + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.main); + LinearLayout container = (LinearLayout) findViewById(R.id.container); + + MyView view = new MyView(this); + container.addView(view); + + ObjectAnimator anim = ObjectAnimator.ofFloat(view, "foo", 1); + anim.start(); + } +} \ No newline at end of file diff --git a/testapps/customPropAnimTest/src/com/android/custompropertyanimation/MyView.java b/testapps/customPropAnimTest/src/com/android/custompropertyanimation/MyView.java new file mode 100644 index 0000000..e557fda --- /dev/null +++ b/testapps/customPropAnimTest/src/com/android/custompropertyanimation/MyView.java @@ -0,0 +1,24 @@ +package com.android.custompropertyanimation; + +import android.content.Context; +import android.view.View; + +public class MyView extends View { + + float mFoo = 0; + + public MyView(Context context) { + super(context); + } + + public void setFoo(float foo) { + System.out.println("foo = " + foo); + mFoo = foo; + } + + public float getFoo() { + System.out.println("getFoo() returning " + mFoo); + return mFoo; + } + +} diff --git a/testapps/customViewTest/libWithCustomView/build.xml b/testapps/customViewTest/libWithCustomView/build.xml index 772f422..7d9e032 100644 --- a/testapps/customViewTest/libWithCustomView/build.xml +++ b/testapps/customViewTest/libWithCustomView/build.xml @@ -1,5 +1,5 @@ - + + + + + + + - - - + + + + + + + + - - - + + + + + + + + diff --git a/testapps/libsAndJarTest/app/project.properties b/testapps/libsAndJarTest/app/project.properties index 4fe0502..9df4221 100644 --- a/testapps/libsAndJarTest/app/project.properties +++ b/testapps/libsAndJarTest/app/project.properties @@ -7,9 +7,9 @@ # "ant.properties", and override values to adapt the script to your # project structure. # -# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): -proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt - # Project target. target=android-15 android.library.reference.1=../lib1 + +# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): +proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt diff --git a/testapps/libsAndJarTest/lib1/build.xml b/testapps/libsAndJarTest/lib1/build.xml index 2a15ae6..ed25521 100644 --- a/testapps/libsAndJarTest/lib1/build.xml +++ b/testapps/libsAndJarTest/lib1/build.xml @@ -1,5 +1,5 @@ - + + + + + + + diff --git a/testapps/libsAndJarTest/lib2/build.xml b/testapps/libsAndJarTest/lib2/build.xml index 3d36fda..4f351c8 100644 --- a/testapps/libsAndJarTest/lib2/build.xml +++ b/testapps/libsAndJarTest/lib2/build.xml @@ -1,5 +1,5 @@ - + + + + + + + -- cgit v1.1