1818
1919import com .google .firebase .crashlytics .buildtools .Buildtools ;
2020import com .google .firebase .crashlytics .buildtools .ndk .NativeSymbolGenerator ;
21- import com .google .firebase .crashlytics .buildtools .ndk .internal .CodeMappingException ;
2221import java .io .File ;
23- import java .io .FileOutputStream ;
2422import java .io .IOException ;
2523import java .io .InputStream ;
2624import java .io .OutputStream ;
2725import java .nio .file .Files ;
26+ import java .nio .file .Path ;
27+ import java .nio .file .Paths ;
2828import java .nio .file .StandardCopyOption ;
2929import java .nio .file .attribute .PosixFilePermission ;
3030import java .util .Arrays ;
@@ -43,7 +43,7 @@ public class BreakpadSymbolGenerator implements NativeSymbolGenerator {
4343
4444 private static final Set <PosixFilePermission > DUMP_SYMS_PERMISSIONS =
4545 Collections .unmodifiableSet (
46- new HashSet <PosixFilePermission >(
46+ new HashSet <>(
4747 Arrays .asList (
4848 PosixFilePermission .OWNER_READ ,
4949 PosixFilePermission .GROUP_READ ,
@@ -65,15 +65,16 @@ public class BreakpadSymbolGenerator implements NativeSymbolGenerator {
6565 */
6666 public static File extractDefaultDumpSymsBinary (File destPath ) throws IOException {
6767 final String osString = getOsForDumpSyms ();
68+ final String resource = "dump_syms/" + osString + "/dump_syms.bin" ;
6869
6970 final File outputFile =
7071 new File (destPath , OS_WINDOWS .equals (osString ) ? "dump_syms.exe" : "dump_syms.bin" );
71- if (outputFile .exists ()) {
72+
73+ if (outputFile .exists () && isLocalFileApplicable (outputFile , resource )) {
7274 Buildtools .logD ("Skipping dumpsyms extraction, file exists: " + outputFile .getAbsolutePath ());
7375 return outputFile ;
7476 }
7577
76- final String resource = "dump_syms/" + osString + "/dump_syms.bin" ;
7778 Buildtools .logD (
7879 "Extracting dump_syms from " + resource + " to " + outputFile .getAbsolutePath ());
7980 extractResource (resource , outputFile );
@@ -98,10 +99,27 @@ public static File extractDefaultDumpSymsBinary(File destPath) throws IOExceptio
9899 return outputFile ;
99100 }
100101
102+ /**
103+ * @return true if localFile can still be useful; if a different file size is found at resources,
104+ * file extraction is required.
105+ */
106+ private static boolean isLocalFileApplicable (File localFile , String rawResourcesFilePath ) {
107+ try {
108+ Path localFilePath = Paths .get (localFile .getPath ());
109+ Path resourcesFilePath = Paths .get (rawResourcesFilePath );
110+
111+ // A different file size means a newer version is available at resources path.
112+ return Files .size (localFilePath ) == Files .size (resourcesFilePath );
113+ } catch (IOException e ) {
114+ // Fallback value to keep process going forward.
115+ return false ;
116+ }
117+ }
118+
101119 private static void extractResource (String pathToResource , File outputFile ) throws IOException {
102120 final InputStream binStream =
103121 BreakpadSymbolGenerator .class .getClassLoader ().getResourceAsStream (pathToResource );
104- final OutputStream outStream = new FileOutputStream (outputFile );
122+ final OutputStream outStream = Files . newOutputStream (outputFile . toPath () );
105123 IOUtils .copy (binStream , outStream );
106124 binStream .close ();
107125 outStream .close ();
@@ -127,8 +145,7 @@ public BreakpadSymbolGenerator(File dumpSymsBin) {
127145 }
128146
129147 @ Override
130- public File generateSymbols (File nativeLib , File symbolFileOutputDir )
131- throws IOException , CodeMappingException {
148+ public File generateSymbols (File nativeLib , File symbolFileOutputDir ) throws IOException {
132149
133150 Buildtools .logD (
134151 "Crashlytics generating Breakpad Symbol file for: " + nativeLib .getAbsolutePath ());
0 commit comments