private AndroidInstrumentationApk(
     BuildRuleParams buildRuleParams, String manifest, AndroidBinaryRule apkUnderTest) {
   super(
       buildRuleParams,
       manifest,
       apkUnderTest.getTarget(),
       apkUnderTest.getKeystorePropertiesPath(),
       PackageType.INSTRUMENTED,
       // Do not include the classes that will already be in the classes.dex of the APK under test.
       ImmutableSet.<BuildRule>builder()
           .addAll(apkUnderTest.getBuildRulesToExcludeFromDex())
           .addAll(Classpaths.getClasspathEntries(apkUnderTest.getDeps()).keySet())
           .build(),
       // Do not split the test apk even if the tested apk is split
       new DexSplitMode(
           /* shouldSplitDex */ false,
           ZipSplitter.DexSplitStrategy.MAXIMIZE_PRIMARY_DEX_SIZE,
           DexStore.JAR),
       apkUnderTest.isUseAndroidProguardConfigWithOptimizations(),
       apkUnderTest.getProguardConfig(),
       apkUnderTest.isCompressResources(),
       apkUnderTest.getPrimaryDexSubstrings(),
       apkUnderTest.getResourceFilter(),
       apkUnderTest.getCpuFilter());
   this.apkUnderTest = apkUnderTest;
 }
  /**
   * Creates/finds the set of build rules that correspond to pre-dex'd artifacts that should be
   * merged to create the final classes.dex for the APK.
   *
   * <p>This method may modify {@code ruleResolver}, inserting new rules into its index.
   */
  @VisibleForTesting
  BuildRule createPreDexMergeRule(UberRDotJava uberRDotJava) {
    ImmutableSet.Builder<DexProducedFromJavaLibrary> preDexDeps = ImmutableSet.builder();
    ImmutableSet<JavaLibrary> transitiveJavaDeps =
        Classpaths.getClasspathEntries(originalDeps).keySet();
    for (JavaLibrary javaLibrary : transitiveJavaDeps) {
      // If the rule has no output file (which happens when a java_library has no srcs or
      // resources, but export_deps is true), then there will not be anything to dx.
      if (javaLibrary.getPathToOutputFile() == null) {
        continue;
      }

      // If the rule is in the no_dx list, then do not pre-dex it.
      if (buildRulesToExcludeFromDex.contains(javaLibrary.getBuildTarget())) {
        continue;
      }

      // See whether the corresponding IntermediateDexRule has already been added to the
      // ruleResolver.
      BuildTarget originalTarget = javaLibrary.getBuildTarget();
      BuildTarget preDexTarget =
          new BuildTarget(originalTarget.getBaseName(), originalTarget.getShortName(), DEX_FLAVOR);
      BuildRule preDexRule = ruleResolver.get(preDexTarget);
      if (preDexRule != null) {
        preDexDeps.add((DexProducedFromJavaLibrary) preDexRule.getBuildable());
        continue;
      }

      // Create the IntermediateDexRule and add it to both the ruleResolver and preDexDeps.
      DexProducedFromJavaLibrary preDex = new DexProducedFromJavaLibrary(preDexTarget, javaLibrary);
      buildRuleAndAddToIndex(
          preDex,
          BuildRuleType.PRE_DEX,
          preDexTarget,
          ImmutableSortedSet.of(ruleResolver.get(javaLibrary.getBuildTarget())));
      preDexDeps.add(preDex);
    }

    ImmutableSet<DexProducedFromJavaLibrary> allPreDexDeps = preDexDeps.build();

    BuildTarget buildTargetForDexMerge = createBuildTargetWithFlavor(DEX_MERGE_FLAVOR);
    PreDexMerge preDexMerge =
        new PreDexMerge(
            buildTargetForDexMerge, primaryDexPath, dexSplitMode, allPreDexDeps, uberRDotJava);
    BuildRule preDexMergeBuildRule =
        buildRuleAndAddToIndex(
            preDexMerge,
            BuildRuleType.DEX_MERGE,
            buildTargetForDexMerge,
            getDexMergeDeps(uberRDotJava, allPreDexDeps));

    return preDexMergeBuildRule;
  }
예제 #3
0
 @Override
 public ImmutableSet<JavaLibrary> getTransitiveClasspathDeps() {
   return Classpaths.getClasspathDeps(getDeps());
 }
예제 #4
0
 @Override
 public ImmutableSetMultimap<JavaLibrary, Path> getTransitiveClasspathEntries() {
   return Classpaths.getClasspathEntries(getDeps());
 }