diff options
author | Michael Hoisie <hoisie@google.com> | 2022-10-26 04:47:13 +0000 |
---|---|---|
committer | Michael Hoisie <hoisie@google.com> | 2022-10-26 04:47:13 +0000 |
commit | b5c92e03aabffa3af97c3f2c5388dd34267f9cbc (patch) | |
tree | 90f472069e91bceeb3c35351651056d1961dcb1a /preinstrumented | |
parent | e28374430bde87c64f10992e7e411201dfe7997e (diff) | |
parent | a617ddde0ffdd0ea6697e5476ac1f37a58716bd5 (diff) | |
download | robolectric-b5c92e03aabffa3af97c3f2c5388dd34267f9cbc.tar.gz |
Merge branch 'google' into 'master'
Diffstat (limited to 'preinstrumented')
-rw-r--r-- | preinstrumented/src/main/java/org/robolectric/preinstrumented/JarInstrumentor.java | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/preinstrumented/src/main/java/org/robolectric/preinstrumented/JarInstrumentor.java b/preinstrumented/src/main/java/org/robolectric/preinstrumented/JarInstrumentor.java index ed5769215..c23798eaa 100644 --- a/preinstrumented/src/main/java/org/robolectric/preinstrumented/JarInstrumentor.java +++ b/preinstrumented/src/main/java/org/robolectric/preinstrumented/JarInstrumentor.java @@ -8,6 +8,7 @@ import java.io.IOException; import java.io.InputStream; import java.util.Enumeration; import java.util.Locale; +import java.util.Properties; import java.util.jar.JarEntry; import java.util.jar.JarFile; import java.util.jar.JarOutputStream; @@ -64,6 +65,13 @@ public class JarInstrumentor { int nonClassCount = 0; int classCount = 0; + // get the jar's SDK version + try { + classInstrumentor.setAndroidJarSDKVersion(getJarAndroidSDKVersion(jarFile)); + } catch (Exception e) { + throw new AssertionError("Unable to get Android SDK version from Jar File", e); + } + try (JarOutputStream jarOut = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(destFile), ONE_MB))) { Enumeration<JarEntry> entries = jarFile.entries(); @@ -136,4 +144,11 @@ public class JarInstrumentor { entry.setTime(original.getTime()); return entry; } + + private int getJarAndroidSDKVersion(JarFile jarFile) throws IOException { + ZipEntry buildProp = jarFile.getEntry("build.prop"); + Properties buildProps = new Properties(); + buildProps.load(jarFile.getInputStream(buildProp)); + return Integer.parseInt(buildProps.getProperty("ro.build.version.sdk")); + } } |