use of com.android.tools.build.bundletool.model.ZipPath in project bundletool by google.
the class InstallApksCommandTest method installAssetModules.
@Test
@Theory
public void installAssetModules(@FromDataPoints("apksInDirectory") boolean apksInDirectory) throws Exception {
String installTimeModule1 = "installtime_assetmodule1";
String installTimeModule2 = "installtime_assetmodule2";
String onDemandModule = "ondemand_assetmodule";
ZipPath installTimeMasterApk1 = ZipPath.create(installTimeModule1 + "-master.apk");
ZipPath installTimeEnApk1 = ZipPath.create(installTimeModule1 + "-en.apk");
ZipPath installTimeMasterApk2 = ZipPath.create(installTimeModule2 + "-master.apk");
ZipPath installTimeEnApk2 = ZipPath.create(installTimeModule2 + "-en.apk");
ZipPath onDemandMasterApk = ZipPath.create(onDemandModule + "-master.apk");
ZipPath baseApk = ZipPath.create("base-master.apk");
BuildApksResult tableOfContent = BuildApksResult.newBuilder().setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(createVariant(VariantTargeting.getDefaultInstance(), createSplitApkSet("base", createMasterApkDescription(ApkTargeting.getDefaultInstance(), baseApk)))).addAssetSliceSet(AssetSliceSet.newBuilder().setAssetModuleMetadata(AssetModuleMetadata.newBuilder().setName(installTimeModule1).setDeliveryType(DeliveryType.INSTALL_TIME)).addApkDescription(splitApkDescription(ApkTargeting.getDefaultInstance(), installTimeMasterApk1)).addApkDescription(splitApkDescription(apkLanguageTargeting("en"), installTimeEnApk1))).addAssetSliceSet(AssetSliceSet.newBuilder().setAssetModuleMetadata(AssetModuleMetadata.newBuilder().setName(installTimeModule2).setDeliveryType(DeliveryType.INSTALL_TIME)).addApkDescription(splitApkDescription(ApkTargeting.getDefaultInstance(), installTimeMasterApk2)).addApkDescription(splitApkDescription(apkLanguageTargeting("en"), installTimeEnApk2))).addAssetSliceSet(AssetSliceSet.newBuilder().setAssetModuleMetadata(AssetModuleMetadata.newBuilder().setName(onDemandModule).setDeliveryType(DeliveryType.ON_DEMAND)).addApkDescription(splitApkDescription(ApkTargeting.getDefaultInstance(), onDemandMasterApk))).build();
Path apksFile = createApks(tableOfContent, apksInDirectory);
List<Path> installedApks = new ArrayList<>();
FakeDevice fakeDevice = FakeDevice.fromDeviceSpec(DEVICE_ID, DeviceState.ONLINE, lDeviceWithLocales("en-US"));
AdbServer adbServer = new FakeAdbServer(/* hasInitialDeviceList= */
true, ImmutableList.of(fakeDevice));
fakeDevice.setInstallApksSideEffect((apks, installOptions) -> installedApks.addAll(apks));
InstallApksCommand.builder().setApksArchivePath(apksFile).setAdbPath(adbPath).setAdbServer(adbServer).setModules(ImmutableSet.of(installTimeModule1)).build().execute();
assertThat(getFileNames(installedApks)).containsExactly(baseApk.toString(), installTimeMasterApk1.toString(), installTimeEnApk1.toString());
}
use of com.android.tools.build.bundletool.model.ZipPath in project bundletool by google.
the class ApkMatcherTest method apkMatch_withModuleNameFiltering_standaloneApkMatches_throws.
@Test
public void apkMatch_withModuleNameFiltering_standaloneApkMatches_throws() {
DeviceSpec x86Device = lDeviceWithAbis("x86");
ZipPath apk = ZipPath.create("master-x86.apk");
BuildApksResult buildApksResult = buildApksResult(standaloneVariant(variantAbiTargeting(X86), apkAbiTargeting(X86), apk));
// Sanity-check that the device matches the standalone APK.
assertThat(new ApkMatcher(x86Device).getMatchingApks(buildApksResult)).containsExactly(baseMatchedApk(apk));
Optional<ImmutableSet<String>> baseModuleOnly = Optional.of(ImmutableSet.of("base"));
InvalidCommandException exception = assertThrows(InvalidCommandException.class, () -> createMatcher(x86Device, baseModuleOnly).getMatchingApks(buildApksResult));
assertThat(exception).hasMessageThat().contains("Cannot restrict modules");
}
use of com.android.tools.build.bundletool.model.ZipPath in project bundletool by google.
the class ApkMatcherTest method apkMatch_withModuleNameFiltering_splitApks_checksModuleName.
// Module name filtering.
@Test
public void apkMatch_withModuleNameFiltering_splitApks_checksModuleName() {
DeviceSpec device = deviceWithSdk(21);
ZipPath apk = ZipPath.create("master-de-fr.apk");
BuildApksResult buildApksResult = buildApksResult(createVariant(VariantTargeting.getDefaultInstance(), splitApkSet(/* moduleName= */
"base", splitApkDescription(ApkTargeting.getDefaultInstance(), apk))));
Optional<ImmutableSet<String>> allModules = Optional.empty();
assertThat(createMatcher(device, allModules).getMatchingApks(buildApksResult)).containsExactly(baseMatchedApk(apk));
Optional<ImmutableSet<String>> baseModuleOnly = Optional.of(ImmutableSet.of("base"));
assertThat(createMatcher(device, baseModuleOnly).getMatchingApks(buildApksResult)).containsExactly(baseMatchedApk(apk));
Optional<ImmutableSet<String>> unknownModuleOnly = Optional.of(ImmutableSet.of("unknown_module"));
InvalidCommandException exception = assertThrows(InvalidCommandException.class, () -> createMatcher(device, unknownModuleOnly).getMatchingApks(buildApksResult));
assertThat(exception).hasMessageThat().contains("The APK Set archive does not contain the following modules: [unknown_module]");
}
use of com.android.tools.build.bundletool.model.ZipPath in project bundletool by google.
the class ApkMatcherTest method apkMatch_textureSplit_noBetterAlternative.
@Test
public void apkMatch_textureSplit_noBetterAlternative() {
ZipPath apk = ZipPath.create("master-etc1_rgb8.apk");
BuildApksResult buildApksResult = buildApksResult(oneApkSplitApkVariant(variantSdkTargeting(sdkVersionFrom(Versions.ANDROID_L_API_VERSION)), apkTextureTargeting(ETC1_RGB8, ImmutableSet.of(ATC, PVRTC)), apk));
assertThat(new ApkMatcher(lDeviceWithGlExtensions("GL_OES_compressed_ETC1_RGB8_texture")).getMatchingApks(buildApksResult)).containsExactly(baseMatchedApk(apk));
}
use of com.android.tools.build.bundletool.model.ZipPath in project bundletool by google.
the class ApkMatcherTest method variantMatching_SdkAbiDensity.
@Test
public void variantMatching_SdkAbiDensity() {
ZipPath apk = ZipPath.create("sample.apk");
BuildApksResult buildApksResult = buildApksResult(standaloneVariant(mergeVariantTargeting(variantSdkTargeting(sdkVersionFrom(1), ImmutableSet.of(sdkVersionFrom(21))), variantAbiTargeting(X86, ImmutableSet.of(ARMEABI_V7A, ARM64_V8A)), variantDensityTargeting(XHDPI, ImmutableSet.of(LDPI, XXHDPI))), ApkTargeting.getDefaultInstance(), apk));
assertThat(new ApkMatcher(deviceWith(19, ImmutableList.of("x86_64", "x86", "arm64-v8a"), HDPI)).getMatchingApks(buildApksResult)).containsExactly(baseMatchedApk(apk));
}
Aggregations