Proguard default config file.

It is located in $SDK/tools/lib/proguard.cfg and automatically
put in Ant project (create and update if project is not already setup
for proguard).

Change-Id: I9bcb2a5aafec1329b0c001799f4ba34c61569c3a
diff --git a/build/tools.atree b/build/tools.atree
index 55ad757..e9810fb 100644
--- a/build/tools.atree
+++ b/build/tools.atree
@@ -51,6 +51,7 @@
 # sdk.git Ant templates for project build files
 sdk/templates/build.template        tools/lib/build.template
 sdk/templates/build.export.template tools/lib/build.export.template
+sdk/files/proguard.cfg              tools/lib/proguard.cfg
 
 # Ant Build Rules
 sdk/files/ant                       tools/ant
diff --git a/changes.txt b/changes.txt
index 603c3e6..9bc8a66 100644
--- a/changes.txt
+++ b/changes.txt
@@ -1,12 +1,15 @@
 Change log for Android SDK Tools.
 
 Revision 8:
-- New SDK component: platform-tools. This makes all platform use the same
+- New SDK component: platform-tools. This makes all platforms use the same
   latest version of aapt/aidl/dx.
 - Support for true debug build. No need to change the value of debuggable in
   the Android Manifest.
   "ant debug" will automatically insert debuggable==true, while "ant release"
   will not.
+  If debuggable=true is set, then "ant release" will actually do a debug build.
+- Automatic Proguard support in release builds. Only need to have a proguard.config
+  property in default.properties that points to a proguard config file.
 - new overridable Ant javac properties: java.encoding, java.source, and java.target
   (default to "ascii", "1.5" and "1.5")
 
diff --git a/eclipse/changes.txt b/eclipse/changes.txt
index 1061bd2..8162ec7 100644
--- a/eclipse/changes.txt
+++ b/eclipse/changes.txt
@@ -4,7 +4,10 @@
   the Android Manifest.
   Incremental build will automatically insert debuggable==true while using
   the "export signed/unsigned application package" will not.
-- Don't recompile the whole workspace on launch.
+  If debuggable=true is set, then release builds will actually do a debug build.
+- Automatic Proguard support in release builds. Only need to have a proguard.config
+  property in default.properties that points to a proguard config file.
+- Android launch configurations don't recompile the whole workspace on launch anymore.
 
 0.9.9:
 - Fix bug where ADT would delete the source folder of projects imported from version control.
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/NewProjectWizard.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/NewProjectWizard.java
index 7a4eaaa..2a9f231 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/NewProjectWizard.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/NewProjectWizard.java
@@ -62,6 +62,7 @@
 
 import java.io.ByteArrayInputStream;
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
@@ -672,6 +673,13 @@
                 addStringDictionaryFile(project, dictionary, monitor);
             }
 
+            // add the default proguard config
+            File libFolder = new File((String) parameters.get(PARAM_SDK_TOOLS_DIR),
+                    SdkConstants.FD_LIB);
+            addLocalFile(project,
+                    new File(libFolder, SdkConstants.FN_PROGUARD_CFG),
+                    monitor);
+
             // Set output location
             javaProject.setOutputLocation(project.getFolder(BIN_DIRECTORY).getFullPath(),
                     monitor);
@@ -1025,6 +1033,22 @@
     }
 
     /**
+     * Adds a file to the root of the project
+     * @param project the project to add the file to.
+     * @param source the file to add. It'll keep the same filename once copied into the project.
+     * @throws FileNotFoundException
+     * @throws CoreException
+     */
+    private void addLocalFile(IProject project, File source, IProgressMonitor monitor)
+            throws FileNotFoundException, CoreException {
+        IFile dest = project.getFile(source.getName());
+        if (dest.exists() == false) {
+            FileInputStream stream = new FileInputStream(source);
+            dest.create(stream, false /* force */, new SubProgressMonitor(monitor, 10));
+        }
+    }
+
+    /**
      * Adds the given folder to the project's class path.
      *
      * @param javaProject The Java Project to update.
diff --git a/files/proguard.cfg b/files/proguard.cfg
new file mode 100644
index 0000000..8ad7d33
--- /dev/null
+++ b/files/proguard.cfg
@@ -0,0 +1,34 @@
+-optimizationpasses 5
+-dontusemixedcaseclassnames
+-dontskipnonpubliclibraryclasses
+-dontpreverify
+-verbose
+-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
+
+-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 com.android.vending.licensing.ILicensingService
+
+-keepclasseswithmembernames class * {
+    native <methods>;
+}
+
+-keepclasseswithmembernames class * {
+    public <init>(android.content.Context, android.util.AttributeSet);
+}
+
+-keepclasseswithmembernames class * {
+    public <init>(android.content.Context, android.util.AttributeSet, int);
+}
+
+-keepclassmembers enum * {
+    public static **[] values();
+    public static ** valueOf(java.lang.String);
+}
+
+-keep class * implements android.os.Parcelable {
+  public static final android.os.Parcelable$Creator *;
+}
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/SdkConstants.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/SdkConstants.java
index 783decb..217a118 100644
--- a/sdkmanager/libs/sdklib/src/com/android/sdklib/SdkConstants.java
+++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/SdkConstants.java
@@ -148,6 +148,9 @@
      */
     public final static String FN_GDBSERVER = "gdbserver";
 
+    /** default proguard config file */
+    public final static String FN_PROGUARD_CFG = "proguard.cfg";
+
     /* Folder Names for Android Projects . */
 
     /** Resources folder name, i.e. "res". */
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/project/ProjectCreator.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/project/ProjectCreator.java
index 783b0fe..e9f65ab 100644
--- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/project/ProjectCreator.java
+++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/project/ProjectCreator.java
@@ -170,6 +170,7 @@
      * @param pathToMainProject if non-null the project will be setup to test a main project
      * located at the given path.
      */
+    @SuppressWarnings("deprecation")
     public void createProject(String folderPath, String projectName,
             String packageName, String activityEntry, IAndroidTarget target, boolean library,
             String pathToMainProject) {
@@ -317,7 +318,7 @@
                         : "java_file.template";
                 String activityFileName = activityClassName + ".java";
 
-                installTemplate(javaTemplate, new File(sourceFolder, activityFileName),
+                installTargetTemplate(javaTemplate, new File(sourceFolder, activityFileName),
                         keywords, target);
             } else {
                 // we should at least create 'src'
@@ -332,11 +333,11 @@
             if (isTestProject == false) {
                 /* Make res files only for non test projects */
                 File valueFolder = createDirs(resourceFolder, SdkConstants.FD_VALUES);
-                installTemplate("strings.template", new File(valueFolder, "strings.xml"),
+                installTargetTemplate("strings.template", new File(valueFolder, "strings.xml"),
                         keywords, target);
 
                 File layoutFolder = createDirs(resourceFolder, SdkConstants.FD_LAYOUT);
-                installTemplate("layout.template", new File(layoutFolder, "main.xml"),
+                installTargetTemplate("layout.template", new File(layoutFolder, "main.xml"),
                         keywords, target);
 
                 // create the icons
@@ -353,13 +354,18 @@
                 manifestTemplate = "AndroidManifest.tests.template";
             }
 
-            installTemplate(manifestTemplate,
+            installTargetTemplate(manifestTemplate,
                     new File(projectFolder, SdkConstants.FN_ANDROID_MANIFEST_XML),
                     keywords, target);
 
             installTemplate("build.template",
                     new File(projectFolder, SdkConstants.FN_BUILD_XML),
                     keywords);
+
+            // install the proguard config file.
+            installTemplate(SdkConstants.FN_PROGUARD_CFG,
+                    new File(projectFolder, SdkConstants.FN_PROGUARD_CFG),
+                    null /*keywords*/);
         } catch (Exception e) {
             mLog.error(e, null);
         }
@@ -476,12 +482,17 @@
         // get the parent File.
         File projectFolder = androidManifest.getParentFile();
 
+        boolean hasProguard = false;
+
         // Check there's a default.properties with a target *or* --target was specified
         IAndroidTarget originalTarget = null;
         ProjectProperties props = ProjectProperties.load(folderPath, PropertyType.DEFAULT);
         if (props != null) {
             String targetHash = props.getProperty(ProjectProperties.PROPERTY_TARGET);
             originalTarget = mSdkManager.getTargetFromHashString(targetHash);
+
+            // if the project is already setup with proguard, we won't copy the proguard config.
+            hasProguard = props.getProperty(ProjectProperties.PROPERTY_PROGUARD_CONFIG) != null;
         }
 
         if (originalTarget == null && target == null) {
@@ -655,6 +666,17 @@
             }
         }
 
+        if (hasProguard == false) {
+            try {
+                installTemplate(SdkConstants.FN_PROGUARD_CFG,
+                        new File(projectFolder, SdkConstants.FN_PROGUARD_CFG),
+                        null /*placeholderMap*/);
+            } catch (ProjectCreateException e) {
+                mLog.error(e, null);
+                return false;
+            }
+        }
+
         return true;
     }
 
@@ -1035,7 +1057,7 @@
      * @param target the Target of the project that will be providing the template.
      * @throws ProjectCreateException
      */
-    private void installTemplate(String templateName, File destFile,
+    private void installTargetTemplate(String templateName, File destFile,
             Map<String, String> placeholderMap, IAndroidTarget target)
             throws ProjectCreateException {
         // query the target for its template directory