

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 在 AWS Device Farm 中对 Instrumentation 测试进行故障排除
<a name="troubleshooting-instrumentation-tests"></a>

以下主题列出了在上传 Instrumentation 测试期间出现的错误消息并推荐了解决方法来解决每个错误。

**注意**  
有关在 AWS Device Farm 中使用 Instrumentation 测试时的重要注意事项，请参阅[适用于 Android 的 Instrumentation 与 AWS Device Farm](test-types-android-instrumentation.md)。

## INSTRUMENTATION\$1TEST\$1PACKAGE\$1UNZIP\$1FAILED
<a name="INSTRUMENTATION_TEST_PACKAGE_UNZIP_FAILED"></a>

如果您看到以下消息，请执行以下步骤来修复此问题。

```
Warning: We could not open your test APK file. Please verify that the file is valid and
    try again.
```

确保您可以解压测试程序包，而不会出现错误。在以下示例中，程序包的名称为 **app-debug-androidTest-unaligned.apk**。

1. 将您的测试程序包复制到工作目录，然后运行以下命令：

   ```
   $ unzip app-debug-androidTest-unaligned.apk
   ```

1. 成功解压缩程序包后，您可以通过运行以下命令找到工作目录树结构：

   ```
   $ tree .
   ```

   有效的 Instrumentation 测试程序包将生成类似以下内容的输出：

   ```
   .
   |-- AndroidManifest.xml
   |--  classes.dex
   |-- resources.arsc
   |-- LICENSE-junit.txt
   |-- junit (directory)
   `-- META-INF (directory)
   ```

   有关更多信息，请参阅 [适用于 Android 的 Instrumentation 与 AWS Device Farm](test-types-android-instrumentation.md)。

## INSTRUMENTATION\$1TEST\$1PACKAGE\$1AAPT\$1DEBUG\$1BADGING\$1FAILED
<a name="INSTRUMENTATION_TEST_PACKAGE_AAPT_DEBUG_BADGING_FAILED"></a>

如果您看到以下消息，请执行以下步骤来修复此问题。

```
We could not extract information about your test package. Please verify that the
      test package is valid by running the command "aapt debug badging <path to your test
      package>", and try again after the command does not print any error.
```

在上传验证过程中，Device Farm 解析 `aapt debug badging <path to your package>` 命令输出中的信息。

确保您可以对 Instrumentation 测试程序包成功运行此命令。

在以下示例中，程序包的名称为 **app-debug-androidTest-unaligned.apk**。
+ 将您的测试程序包复制到工作目录，然后运行以下命令：

  ```
  $ aapt debug badging app-debug-androidTest-unaligned.apk
  ```

  有效的 Instrumentation 测试程序包将生成类似以下内容的输出：

  ```
  package: name='com.amazon.aws.adf.android.referenceapp.test' versionCode='' versionName='' platformBuildVersionName='5.1.1-1819727'
  sdkVersion:'9'
  targetSdkVersion:'22'
  application-label:'Test-api'
  application: label='Test-api' icon=''
  application-debuggable
  uses-library:'android.test.runner'
  feature-group: label=''
  uses-feature: name='android.hardware.touchscreen'
  uses-implied-feature: name='android.hardware.touchscreen' reason='default feature for all apps'
  supports-screens: 'small' 'normal' 'large' 'xlarge'
  supports-any-density: 'true'
  locales: '--_--'
  densities: '160'
  ```

  有关更多信息，请参阅 [适用于 Android 的 Instrumentation 与 AWS Device Farm](test-types-android-instrumentation.md)。

## INSTRUMENTATION\$1TEST\$1PACKAGE\$1INSTRUMENTATION\$1RUNNER\$1VALUE\$1MISSING
<a name="INSTRUMENTATION_TEST_PACKAGE_INSTRUMENTATION_RUNNER_VALUE_MISSING"></a>

如果您看到以下消息，请执行以下步骤来修复此问题。

```
We could not find the instrumentation runner value in the AndroidManifest.xml.
      Please verify the test package is valid by running the command "aapt dump xmltree <path to
      your test package> AndroidManifest.xml", and try again after finding the instrumentation
      runner value behind the keyword "instrumentation."
```

在上传验证过程中，Device Farm 解析程序包中包含的 XML 文件的 XML 解析树中的 Instrumentation 运行程序值。您可使用以下命令：`aapt dump xmltree <path to your package> AndroidManifest.xml`。

确保您可以对 Instrumentation 测试程序包运行此命令并成功找到 Instrumentation 值。

在以下示例中，程序包的名称为 **app-debug-androidTest-unaligned.apk**。
+ 将您的测试程序包复制到工作目录，然后运行以下命令：

  ```
  $ aapt dump xmltree app-debug-androidTest-unaligned.apk AndroidManifest.xml | grep -A5 "instrumentation"
  ```

  有效的 Instrumentation 测试程序包将生成类似以下内容的输出：

  ```
  E: instrumentation (line=9)
        A: android:label(0x01010001)="Tests for com.amazon.aws.adf.android.referenceapp" (Raw: "Tests for com.amazon.aws.adf.android.referenceapp")
        A: android:name(0x01010003)="android.support.test.runner.AndroidJUnitRunner" (Raw: "android.support.test.runner.AndroidJUnitRunner")
        A: android:targetPackage(0x01010021)="com.amazon.aws.adf.android.referenceapp" (Raw: "com.amazon.aws.adf.android.referenceapp")
        A: android:handleProfiling(0x01010022)=(type 0x12)0x0
        A: android:functionalTest(0x01010023)=(type 0x12)0x0
  ```

  有关更多信息，请参阅 [适用于 Android 的 Instrumentation 与 AWS Device Farm](test-types-android-instrumentation.md)。

## INSTRUMENTATION\$1TEST\$1PACKAGE\$1AAPT\$1DUMP\$1XMLTREE\$1FAILED
<a name="INSTRUMENTATION_TEST_PACKAGE_AAPT_DUMP_XMLTREE_FAILED"></a>

如果您看到以下消息，请执行以下步骤来修复此问题。

```
We could not find the valid AndroidManifest.xml in your test package. Please
      verify that the test package is valid by running the command "aapt dump xmltree <path to
      your test package> AndroidManifest.xml", and try again after the command does not print any
      error.
```

在上传验证过程中，Device Farm 使用以下命令解析程序包中包含的 XML 文件的 XML 解析树中的信息：`aapt dump xmltree <path to your package> AndroidManifest.xml`。

确保您可以对 Instrumentation 测试程序包成功运行此命令。

在以下示例中，程序包的名称为 **app-debug-androidTest-unaligned.apk**。
+ 将您的测试程序包复制到工作目录，然后运行以下命令：

  ```
  $ aapt dump xmltree app-debug-androidTest-unaligned.apk AndroidManifest.xml
  ```

  有效的 Instrumentation 测试程序包将生成类似以下内容的输出：

  ```
  N: android=http://schemas.android.com/apk/res/android
    E: manifest (line=2)
      A: package="com.amazon.aws.adf.android.referenceapp.test" (Raw: "com.amazon.aws.adf.android.referenceapp.test")
      A: platformBuildVersionCode=(type 0x10)0x16 (Raw: "22")
      A: platformBuildVersionName="5.1.1-1819727" (Raw: "5.1.1-1819727")
      E: uses-sdk (line=5)
        A: android:minSdkVersion(0x0101020c)=(type 0x10)0x9
        A: android:targetSdkVersion(0x01010270)=(type 0x10)0x16
      E: instrumentation (line=9)
        A: android:label(0x01010001)="Tests for com.amazon.aws.adf.android.referenceapp" (Raw: "Tests for com.amazon.aws.adf.android.referenceapp")
        A: android:name(0x01010003)="android.support.test.runner.AndroidJUnitRunner" (Raw: "android.support.test.runner.AndroidJUnitRunner")
        A: android:targetPackage(0x01010021)="com.amazon.aws.adf.android.referenceapp" (Raw: "com.amazon.aws.adf.android.referenceapp")
        A: android:handleProfiling(0x01010022)=(type 0x12)0x0
        A: android:functionalTest(0x01010023)=(type 0x12)0x0
      E: application (line=16)
        A: android:label(0x01010001)=@0x7f020000
        A: android:debuggable(0x0101000f)=(type 0x12)0xffffffff
        E: uses-library (line=17)
          A: android:name(0x01010003)="android.test.runner" (Raw: "android.test.runner")
  ```

  有关更多信息，请参阅 [适用于 Android 的 Instrumentation 与 AWS Device Farm](test-types-android-instrumentation.md)。

## INSTRUMENTATION\$1TEST\$1PACKAGE\$1TEST\$1PACKAGE\$1NAME\$1VALUE\$1MISSING
<a name="INSTRUMENTATION_TEST_PACKAGE_TEST_PACKAGE_NAME_VALUE_MISSING"></a>

如果您看到以下消息，请执行以下步骤来修复此问题。

```
We could not find the package name in your test package. Please verify that the
      test package is valid by running the command "aapt debug badging <path to your test
      package>", and try again after finding the package name value behind the keyword "package:
      name."
```

在上传验证过程中，Device Farm 解析以下命令输出中的程序包名称值：`aapt debug badging <path to your package>`。

确保您可以对 Instrumentation 测试程序包运行此命令并成功找到程序包名称值。

在以下示例中，程序包的名称为 **app-debug-androidTest-unaligned.apk**。
+ 将您的测试程序包复制到工作目录，然后运行以下命令：

  ```
  $ aapt debug badging app-debug-androidTest-unaligned.apk | grep "package: name="
  ```

  有效的 Instrumentation 测试程序包将生成类似以下内容的输出：

  ```
  package: name='com.amazon.aws.adf.android.referenceapp.test' versionCode='' versionName='' platformBuildVersionName='5.1.1-1819727'
  ```

  有关更多信息，请参阅 [适用于 Android 的 Instrumentation 与 AWS Device Farm](test-types-android-instrumentation.md)。