Search in sources :

Example 1 with ANDROID_K_API_VERSION

use of com.android.tools.build.bundletool.model.utils.Versions.ANDROID_K_API_VERSION in project bundletool by google.

the class D8DexMergerTest method mergeCoreDesugaringLibrary_ok.

@Test
public void mergeCoreDesugaringLibrary_ok() throws Exception {
    // Two application dex files together with code desugaring dex.
    Path dexFile1 = writeTestDataToFile("testdata/dex/classes.dex");
    Path dexFile2 = writeTestDataToFile("testdata/dex/classes-other.dex");
    Path dexFile3 = writeTestDataToFile("testdata/dex/classes-emulated-coredesugar.dex");
    ImmutableList<Path> mergedDexFiles = new D8DexMerger().merge(ImmutableList.of(dexFile1, dexFile2, dexFile3), outputDir, /* mainDexListFile= */
    Optional.empty(), /* proguardMap= */
    NO_FILE, /* isDebuggable= */
    false, /* minSdkVersion= */
    ANDROID_K_API_VERSION);
    ImmutableList<String> mergedDexFilenames = mergedDexFiles.stream().map(dex -> dex.getFileName().toString()).collect(toImmutableList());
    assertThat(mergedDexFiles.size()).isAtLeast(2);
    assertThat(mergedDexFilenames).containsExactly("classes.dex", "classes2.dex");
    assertThat(listClassesInDexFiles(mergedDexFiles.get(0))).isEqualTo(listClassesInDexFiles(dexFile1, dexFile2));
    // Core desugaring dex must not be merged with application dex.
    assertThat(Files.readAllBytes(mergedDexFiles.get(1))).isEqualTo(Files.readAllBytes(dexFile3));
}
Also used : Path(java.nio.file.Path) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) DexFileFactory(org.jf.dexlib2.DexFileFactory) Arrays(java.util.Arrays) RunWith(org.junit.runner.RunWith) Opcodes(org.jf.dexlib2.Opcodes) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) DexBackedClassDef(org.jf.dexlib2.dexbacked.DexBackedClassDef) ImmutableList(com.google.common.collect.ImmutableList) Path(java.nio.file.Path) Before(org.junit.Before) DexBackedDexFile(org.jf.dexlib2.dexbacked.DexBackedDexFile) ImmutableSet(com.google.common.collect.ImmutableSet) Files(java.nio.file.Files) ANDROID_K_API_VERSION(com.android.tools.build.bundletool.model.utils.Versions.ANDROID_K_API_VERSION) CommandExecutionException(com.android.tools.build.bundletool.model.exceptions.CommandExecutionException) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) TestData(com.android.tools.build.bundletool.TestData) Collection(java.util.Collection) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) ANDROID_L_API_VERSION(com.android.tools.build.bundletool.model.utils.Versions.ANDROID_L_API_VERSION) Truth.assertThat(com.google.common.truth.Truth.assertThat) FileUtils(com.android.tools.build.bundletool.testing.FileUtils) File(java.io.File) Rule(org.junit.Rule) Optional(java.util.Optional) TemporaryFolder(org.junit.rules.TemporaryFolder) Test(org.junit.Test)

Aggregations

TestData (com.android.tools.build.bundletool.TestData)1 CommandExecutionException (com.android.tools.build.bundletool.model.exceptions.CommandExecutionException)1 ANDROID_K_API_VERSION (com.android.tools.build.bundletool.model.utils.Versions.ANDROID_K_API_VERSION)1 ANDROID_L_API_VERSION (com.android.tools.build.bundletool.model.utils.Versions.ANDROID_L_API_VERSION)1 FileUtils (com.android.tools.build.bundletool.testing.FileUtils)1 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Truth.assertThat (com.google.common.truth.Truth.assertThat)1 File (java.io.File)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Optional (java.util.Optional)1 DexFileFactory (org.jf.dexlib2.DexFileFactory)1 Opcodes (org.jf.dexlib2.Opcodes)1 DexBackedClassDef (org.jf.dexlib2.dexbacked.DexBackedClassDef)1 DexBackedDexFile (org.jf.dexlib2.dexbacked.DexBackedDexFile)1