Last Updated: Jun 02, 2017

Direct introduction of the JAR package

After you download the OSS Android SDK ZIP package, perform the following steps (applicable to Android Studio and Eclipse):

  • Download the SDK package from the official website.
  • Unzip the SDK package to obtain the following JAR packages: aliyun-oss-sdk-android-2.3.0.jar, okhttp-3.x.x.jar and okio-1.x.x.jar.
  • Import the three JAR packages to the “libs” directory.

Maven dependency

  1. <dependency>
  2. <groupId>com.aliyun.dpa</groupId>
  3. <artifactId>oss-android-sdk</artifactId>
  4. <version>2.3.0</version>
  5. </dependency>

Permission settings

The following are the Android permissions needed by the OSS Android SDK. Please make sure these permissions are already set in your “AndroidManifest.xml” file. Otherwise, the SDK will not work normally.

  1. <uses-permission android:name="android.permission.INTERNET"></uses-permission>
  2. <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
  3. <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>
  4. <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>

Obfuscation settings

Add the following to the obfuscation configuration:

  1. -keep class** { *; }
  2. -dontwarn okio.**
  3. -dontwarn org.apache.commons.codec.binary.**

Descriptions of synchronous interfaces and asynchronous interfaces in the SDK

Because network requests are not allowed to be processed in the UI thread in mobile development, many interfaces of the SDK support both synchronous and asynchronous calls to handle requests. The synchronous interface call will block other requests while waiting for the returned results, whereas the asynchronous interface only requires a callback function at the request to return the requested execution results.

The UI thread does not support synchronous interface calls. ClientException or ServiceException will be thrown in the event of an exception. ClientException indicates a local exception, such as a network exception or invalid parameters. ServiceException indicates a service exception returned by the OSS, such as an authentication failure or a server error.

When an exception occurs during asynchronous request processing, the exception will be handled by a callback function.

When an asynchronous interface is called, the function will return a task. You can cancel the task, wait till the task is finished, or obtain results directly. For example,

  1. OSSAsyncTask task = oss.asyncGetObejct(...);
  2. task.cancel(); // You can cancel the task
  3. task.waitUntilFinished(); // Wait till the task is finished
  4. GetObjectResult result = task.getResult(); // Block other requests and wait for the returned results

Note: The interface supports both the synchronous and asynchronous calling of methods. For the purpose of keeping this document concise, examples of how to call important interfaces in synchronous and asynchronous modes are given. For other interfaces, only the asynchronous mode is described.

Thank you! We've received your feedback.