aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build/lib/rules/android/AndroidBinaryMultidexTest.java
blob: 9153f0dca5071fe8ddd23b14086d2cfa2e688a3d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Copyright 2017 The Bazel Authors. 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.
// You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License 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.google.devtools.build.lib.rules.android;

import com.google.devtools.build.lib.rules.android.AndroidRuleClasses.MultidexMode;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

/**
 * Tests the multidex code of {@link com.google.devtools.build.lib.rules.android.AndroidBinary}.
 */
@RunWith(JUnit4.class)
public class AndroidBinaryMultidexTest extends AndroidMultidexBaseTest {

  /**
   * Tests that when multidex = "off", a classes.dex file is generated directly
   * from the input jar.
   */
  @Test
  public void testNonMultidexBuildStructure() throws Exception {
    scratch.file("java/foo/BUILD",
        "android_binary(",
        "    name = 'nomultidex',",
        "    srcs = ['a.java'],",
        "    manifest = 'AndroidManifest.xml',",
        "    resource_files = glob(['res/**']),",
        "    multidex = 'off')");
    internalTestNonMultidexBuildStructure("//java/foo:nomultidex");
  }

  /**
   * Tests that the default multidex setting is the same as when multidex = "off".
   */
  @Test
  public void testDefaultBuildStructure() throws Exception {
    scratch.file("java/foo/BUILD",
        "android_binary(",
        "    name = 'default',",
        "    srcs = ['a.java'],",
        "    manifest = 'AndroidManifest.xml',",
        "    resource_files = glob(['res/**']))");
    internalTestNonMultidexBuildStructure("//java/foo:default");
  }

  @Test
  public void testManualMainDexMode() throws Exception {
    scratch.file("java/foo/main_dex_list.txt",
        "android/A.class");
    scratch.file("java/foo/BUILD",
        "android_binary(",
        "    name = 'manual_main_dex',",
        "    srcs = ['a.java'],",
        "    manifest = 'AndroidManifest.xml',",
        "    resource_files = glob(['res/**']),",
        "    multidex = 'manual_main_dex',",
        "    main_dex_list = 'main_dex_list.txt')");
    internalTestMultidexBuildStructure(
        "//java/foo:manual_main_dex", MultidexMode.MANUAL_MAIN_DEX);
  }

  /**
   * Tests that when multidex = "legacy", a classes.dex.zip file is generated from
   * an intermediate file with multidex mode specified and a "--main-dex-list" dx flag
   * filled out with appropriate input, This file is then filtered through a zip
   * action to remove non-.dex files to produce the final output.
   */
  @Test
  public void testLegacyMultidexBuildStructure() throws Exception {
    scratch.file("java/foo/BUILD",
        "android_binary(",
        "    name = 'legacy',",
        "    srcs = ['a.java'],",
        "    manifest = 'AndroidManifest.xml',",
        "    resource_files = glob(['res/**']),",
        "    multidex = 'legacy')");
    internalTestMultidexBuildStructure("//java/foo:legacy", MultidexMode.LEGACY);
  }

  /**
   * Tests that when multidex = "native", a classes.dex.zip file is generated from
   * an intermediate file with multidex mode specified. Unlike in "legacy" mode,
   * no actions are required to set and fill the "--main-dex-list" dx flag. The
   * intermediate file is then filtered through a zip action to remove non-.dex files
   * to produce the final output.
   */
  @Test
  public void testNativeMultidexBuildStructure() throws Exception {
    scratch.file("java/foo/BUILD",
        "android_binary(",
        "    name = 'native',",
        "    srcs = ['a.java'],",
        "    manifest = 'AndroidManifest.xml',",
        "    resource_files = glob(['res/**']),",
        "    multidex = 'native')");
    internalTestMultidexBuildStructure("//java/foo:native", MultidexMode.NATIVE);
  }
}