Skip to content

Commit

Permalink
AWS SDK for Android 2.2.9
Browse files Browse the repository at this point in the history
  • Loading branch information
AWS committed Nov 24, 2015
1 parent ce8d52e commit d37ea33
Show file tree
Hide file tree
Showing 51 changed files with 630 additions and 411 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,14 @@
# Change Log - AWS SDK for Android

## [Release 2.2.9](https://github.com/aws/aws-sdk-android/releases/tag/release_v2.2.9) (11/18/2015)

### New Features
- **Amazon Web Services**: General service updates and documentation improvements.

### Bug Fixes
- **Amazon S3**: Fixed slow initialization of Amazon S3 client. [#69](https://github.com/aws/aws-sdk-android/issues/69)
- **General**: Updated instruction for proguard.

## [Release 2.2.8](https://github.com/aws/aws-sdk-android/releases/tag/release_v2.2.8) (11/05/2015)

### New Features
Expand Down
40 changes: 16 additions & 24 deletions Proguard.html
Expand Up @@ -33,7 +33,7 @@ <h2>Creating a Proguard Config</h2>
versions 17 and later, a default config ships with the toolkit and can be included in
your Android app. A project customization file <i>proguard-project.txt</i> will also be
created where additional options can be supplied as needed. </p>
<p> If you are adding Progaard to an existing app, you can place your <i>proguard-project.txt</i> anywhere
<p> If you are adding Proguard to an existing app, you can place your <i>proguard-project.txt</i> anywhere
in the project folder, but typically it is placed at the root of your project, alongside
the <i>AndroidManifest.xml</i> and
<i>project.properties</i> files.
Expand Down Expand Up @@ -82,28 +82,20 @@ <h2>Modifying proguard-project.txt for the AWS SDK for Android</h2>
</p>

<table class="sample"><tr><td align="left" >
<pre>-keep class org.apache.commons.logging.** { *; }
-keep class com.amazonaws.services.sqs.QueueUrlHandler { *; }
-keep class com.amazonaws.javax.xml.transform.sax.* { public *; }
-keep class com.amazonaws.javax.xml.stream.** { *; }
-keep class com.amazonaws.services.**.model.*Exception* { *; }
-keep class com.amazonaws.internal.** { *; }
-keep class org.codehaus.** { *; }
-keep class org.joda.convert.* { *; }
-keepattributes Signature,*Annotation*,EnclosingMethod
-keepnames class com.fasterxml.jackson.** { *; }
-keepnames class com.amazonaws.** { *; }

-dontwarn com.amazonaws.auth.policy.conditions.S3ConditionFactory
-dontwarn org.joda.time.**
-dontwarn com.fasterxml.jackson.databind.**
-dontwarn javax.xml.stream.events.**
-dontwarn org.codehaus.jackson.**
-dontwarn org.apache.commons.logging.impl.**
-dontwarn org.apache.http.conn.scheme.**
-dontwarn org.apache.http.annotation.**
-dontwarn org.ietf.jgss.**
-dontwarn org.w3c.dom.bootstrap.**</pre></td></tr>
<pre>
# Class names are needed in reflection
-keepnames class com.amazonaws.**
# Request handlers defined in request.handlers
-keep class com.amazonaws.services.**.*Handler
# The following are referenced but aren't required to run
-dontwarn com.fasterxml.jackson.**
-dontwarn org.apache.commons.logging.**
# Android 6.0 release removes support for the Apache HTTP client
-dontwarn org.apache.http.**
# The SDK has several references of Apache HTTP client
-dontwarn com.amazonaws.http.**
-dontwarn com.amazonaws.metrics.**
</pre></td></tr>
</table>

<p>
Expand Down Expand Up @@ -133,4 +125,4 @@ <h2>Questions?</h2>
</p>

</body>
</html>
</html>
60 changes: 60 additions & 0 deletions Proguard.md
@@ -0,0 +1,60 @@
# Using Proguard with the AWS SDK for Android

Proguard is an open source project whose aim is to help Java developers shrink, optimize, and obfuscate their Java code. With storage on mobile devices at a premium, Proguard has become a popular option for Android developers looking to minimize the size of their apps and also protect their code from prying eyes. You can learn more about Proguard and its features at the project's [official site](http://proguard.sourceforge.net/).

Starting with version 1.3.0 of the AWS SDK for Android, AWS will be actively supporting users who want to make use of Proguard in their Android projects. This article discusses how developers can optimally configure Proguard to shrink, optimize, and obfuscate their code and still use the AWS SDK for Android for all services it supports.

## Creating a Proguard Config

Proguard is now integrated into the Eclipse IDE by means of the ADT plug-in. Starting with ADT versions 17 and later, a default config ships with the toolkit and can be included in your Android app. A project customization file _proguard-project.txt_ will also be created where additional options can be supplied as needed.

If you are adding Proguard to an existing app, you can place your _proguard-project.txt_ anywhere in the project folder, but typically it is placed at the root of your project, alongside the _AndroidManifest.xml_ and _project.properties_ files.

Regardless of whether you created the file yourself or used the default config when you created a new project, you still need to enable Proguard for your app. As noted on the [Android Tools Project Site](http://tools.android.com/recent/proguardimprovements), you do this by adding a line similar to the following in your _project.properties_ file:

```
proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
```

If you did not create your _proguard-project.txt_ file at the root of your project directory, you need to supply the path to the file as well.

```
proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:<path_to_proguard>/proguard-project.txt
```

You may also choose to completely override the default proguard configuration as supplied by ADT by simply excluding it from your project.properties. You can than copy the portions of the default _proguard-android.txt_ you want into your _proguard-project.txt_ **Note:** This is not recommended by the ADT developers and it will prevent your app from receiving updates released with ADT updates and may generate a warning during lint processing.

```
proguard.config=proguard-project.txt
```

## Modifying proguard-project.txt for the AWS SDK for Android

When exporting your app using the AWS SDK for Android with the default, empty _proguard-project.txt_ file, you may notice that Eclipse reports errors. In order to correct these errors, add the following lines to the end of your _proguard-project.txt_ file:

```
# Class names are needed in reflection
-keepnames class com.amazonaws.**
# Request handlers defined in request.handlers
-keep class com.amazonaws.services.**.*Handler
# The following are referenced but aren't required to run
-dontwarn com.fasterxml.jackson.**
-dontwarn org.apache.commons.logging.**
# Android 6.0 release removes support for the Apache HTTP client
-dontwarn org.apache.http.**
# The SDK has several references of Apache HTTP client
-dontwarn com.amazonaws.http.**
-dontwarn com.amazonaws.metrics.**
```

**Note:** This configuration applies only to the AWS SDK for Android; if you are using other third-party libraries, you need to consult the documentation for those libraries to see if they require additional configuration to support the use of Proguard.

## Conclusion and Additional Resources

Proguard is a valuable tool for Android developers who care about the size of their apps. The configuration provided in this article allows developers to ship apps using the AWS SDK for Android that use less of the user's storage.

All samples in the AWS SDK for Android starting with version 1.3.0 ship with functional Proguard configuration. You can download the latest version of the AWS SDK for Android [here](http://aws.amazon.com/sdkforandroid).

## Questions?

Please feel free to ask questions or provide comments in the [Mobile Development Forum](https://forums.aws.amazon.com/forum.jspa?forumID=88).
4 changes: 2 additions & 2 deletions aws-android-sdk-apigateway-core/pom.xml
Expand Up @@ -12,15 +12,15 @@
<parent>
<groupId>com.amazonaws</groupId>
<artifactId>aws-android-sdk-pom</artifactId>
<version>2.2.8</version>
<version>2.2.9</version>
</parent>

<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-android-sdk-core</artifactId>
<optional>false</optional>
<version>2.2.8</version>
<version>2.2.9</version>
</dependency>
</dependencies>

Expand Down
4 changes: 2 additions & 2 deletions aws-android-sdk-autoscaling/pom.xml
Expand Up @@ -12,15 +12,15 @@
<parent>
<groupId>com.amazonaws</groupId>
<artifactId>aws-android-sdk-pom</artifactId>
<version>2.2.8</version>
<version>2.2.9</version>
</parent>

<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-android-sdk-core</artifactId>
<optional>false</optional>
<version>2.2.8</version>
<version>2.2.9</version>
</dependency>
</dependencies>

Expand Down
4 changes: 2 additions & 2 deletions aws-android-sdk-cloudwatch/pom.xml
Expand Up @@ -12,15 +12,15 @@
<parent>
<groupId>com.amazonaws</groupId>
<artifactId>aws-android-sdk-pom</artifactId>
<version>2.2.8</version>
<version>2.2.9</version>
</parent>

<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-android-sdk-core</artifactId>
<optional>false</optional>
<version>2.2.8</version>
<version>2.2.9</version>
</dependency>
</dependencies>

Expand Down
2 changes: 1 addition & 1 deletion aws-android-sdk-core/pom.xml
Expand Up @@ -12,7 +12,7 @@
<parent>
<groupId>com.amazonaws</groupId>
<artifactId>aws-android-sdk-pom</artifactId>
<version>2.2.8</version>
<version>2.2.9</version>
</parent>

<dependencies>
Expand Down
Expand Up @@ -301,7 +301,7 @@ public CognitoCredentialsProvider(AWSCognitoIdentityProvider provider, Regions r
public CognitoCredentialsProvider(AWSCognitoIdentityProvider provider,
Regions region, ClientConfiguration clientConfiguration) {
this(provider, new AmazonCognitoIdentityClient(
new AnonymousAWSCredentials(), new ClientConfiguration()));
new AnonymousAWSCredentials(), clientConfiguration));
this.cib.setRegion(Region.getRegion(region));
}

Expand Down
@@ -0,0 +1,56 @@
/*
* Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

package com.amazonaws.internal.config;

import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

public class HostRegexToRegionMapping {
private final String hostNameRegex;
private final String regionName;

public HostRegexToRegionMapping(
String hostNameRegex, String regionName) {
if (hostNameRegex == null || hostNameRegex.isEmpty()) {
throw new IllegalArgumentException(
"Invalid HostRegexToRegionMapping configuration: " +
"hostNameRegex must be non-empty");
}
try {
Pattern.compile(hostNameRegex);
} catch (PatternSyntaxException e) {
throw new IllegalArgumentException(
"Invalid HostRegexToRegionMapping configuration: " +
"hostNameRegex is not a valid regex",
e);
}
if (regionName == null || regionName.isEmpty()) {
throw new IllegalArgumentException(
"Invalid HostRegexToRegionMapping configuration: " +
"regionName must be non-empty");
}
this.hostNameRegex = hostNameRegex;
this.regionName = regionName;
}

public String getHostNameRegex() {
return hostNameRegex;
}

public String getRegionName() {
return regionName;
}
}
Expand Up @@ -20,7 +20,10 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
Expand All @@ -35,20 +38,15 @@ public class InternalConfig {
private final Map<String, SignerConfig> regionSigners;
private final Map<String, SignerConfig> serviceSigners;
private final Map<String, HttpClientConfig> httpClients;
private final List<HostRegexToRegionMapping> hostRegexToRegionMappings;

InternalConfig() {
defaultSignerConfig = getDefaultSigner();
regionSigners = getDefaultRegionSigners();
regionSigners.putAll(getOverrideRegionSigners());

serviceSigners = getDefaultServiceSigners();
serviceSigners.putAll(getOverrideServiceSigners());

serviceRegionSigners = getDefaultServiceRegionSigners();
serviceRegionSigners.putAll(getOverrideServiceRegionSigners());

httpClients = getDefaultHttpClients();
httpClients.putAll(getOverrideHttpClients());
hostRegexToRegionMappings = getDefaultHostRegexToRegionMappings();
}

/**
Expand Down Expand Up @@ -98,13 +96,17 @@ public SignerConfig getSignerConfig(String serviceName, String regionName) {
return signerConfig == null ? defaultSignerConfig : signerConfig;
}

/**
* @return all the host-name-regex to region-name mappings.
*/
public List<HostRegexToRegionMapping> getHostRegexToRegionMappings() {
return Collections.unmodifiableList(hostRegexToRegionMappings);
}

private static Map<String, HttpClientConfig> getDefaultHttpClients() {
// map from service client name to sigv4 service name
Map<String, HttpClientConfig> ret = new HashMap<String, HttpClientConfig>();
ret.put("AmazonSimpleWorkflowClient", new HttpClientConfig("swf"));
ret.put("AmazonCloudWatchClient", new HttpClientConfig("monitoring"));
ret.put("DataPipelineClient", new HttpClientConfig("datapipeline"));
ret.put("AmazonIdentityManagementClient", new HttpClientConfig("iam"));
ret.put("AmazonSimpleDBClient", new HttpClientConfig("sdb"));
ret.put("AmazonSimpleEmailServiceClient", new HttpClientConfig("email"));
ret.put("AWSSecurityTokenServiceClient", new HttpClientConfig("sts"));
Expand Down Expand Up @@ -134,39 +136,21 @@ private static Map<String, SignerConfig> getDefaultServiceSigners() {
Map<String, SignerConfig> ret = new HashMap<String, SignerConfig>();
ret.put("ec2", new SignerConfig("QueryStringSignerType"));
ret.put("email", new SignerConfig("AWS3SignerType"));
ret.put("importexport", new SignerConfig("QueryStringSignerType"));
ret.put("route53", new SignerConfig("AWS3SignerType"));
ret.put("s3", new SignerConfig("S3SignerType"));
ret.put("sdb", new SignerConfig("QueryStringSignerType"));
ret.put("cloudsearchdomain", new SignerConfig("NoOpSignerType"));
return ret;
}

private static SignerConfig getDefaultSigner() {
return new SignerConfig("AWS4SignerType");
}

private static Map<String, HttpClientConfig> getOverrideHttpClients() {
// map from service client name to sigv4 service name
Map<String, HttpClientConfig> ret = new HashMap<String, HttpClientConfig>();
return ret;
}

private static Map<String, SignerConfig> getOverrideRegionSigners() {
// map from region name to signer type
Map<String, SignerConfig> ret = new HashMap<String, SignerConfig>();
return ret;
}

private static Map<String, SignerConfig> getOverrideServiceRegionSigners() {
// map from "<service>/<region>" to signer type
Map<String, SignerConfig> ret = new HashMap<String, SignerConfig>();
return ret;
}

private static Map<String, SignerConfig> getOverrideServiceSigners() {
// map from abbreviated service name to signer type
Map<String, SignerConfig> ret = new HashMap<String, SignerConfig>();
private static List<HostRegexToRegionMapping> getDefaultHostRegexToRegionMappings() {
List<HostRegexToRegionMapping> ret = new ArrayList<HostRegexToRegionMapping>();
ret.add(new HostRegexToRegionMapping("(.+\\.)?s3\\.amazonaws\\.com", "us-east-1"));
ret.add(new HostRegexToRegionMapping("(.+\\.)?s3-external-1\\.amazonaws\\.com", "us-east-1"));
ret.add(new HostRegexToRegionMapping("(.+\\.)?s3-fips-us-gov-west-1\\.amazonaws\\.com",
"us-gov-west-1"));
return ret;
}

Expand All @@ -176,7 +160,9 @@ void dump() {
.append(defaultSignerConfig).append("\n")
.append("serviceRegionSigners: ").append(serviceRegionSigners)
.append("\n").append("regionSigners: ").append(regionSigners)
.append("\n").append("serviceSigners: ").append(serviceSigners);
.append("\n").append("serviceSigners: ").append(serviceSigners)
.append("\n").append("hostRegexToRegionMappings: ")
.append(hostRegexToRegionMappings);
log.debug(sb.toString());
}

Expand Down

0 comments on commit d37ea33

Please sign in to comment.