@@ -111,7 +111,7 @@ public void decode(File outDir) throws AndrolibException, IOException, Directory
111
111
if (hasResources ()) {
112
112
switch (config .decodeResources ) {
113
113
case Config .DECODE_RESOURCES_NONE :
114
- decodeResourcesRaw (mApkFile , outDir );
114
+ copyResourcesRaw (mApkFile , outDir );
115
115
if (config .forceDecodeManifest == Config .FORCE_DECODE_MANIFEST_FULL ) {
116
116
// done after raw decoding of resources because copyToDir overwrites dest files
117
117
if (hasManifest ()) {
@@ -135,15 +135,15 @@ public void decode(File outDir) throws AndrolibException, IOException, Directory
135
135
decodeManifestFull (mApkFile , outDir , getResTable ());
136
136
}
137
137
else {
138
- decodeManifestRaw (mApkFile , outDir );
138
+ copyManifestRaw (mApkFile , outDir );
139
139
}
140
140
}
141
141
}
142
142
143
143
if (hasSources ()) {
144
144
switch (config .decodeSources ) {
145
145
case Config .DECODE_SOURCES_NONE :
146
- decodeSourcesRaw (mApkFile , outDir , "classes.dex" );
146
+ copySourcesRaw (mApkFile , outDir , "classes.dex" );
147
147
break ;
148
148
case Config .DECODE_SOURCES_SMALI :
149
149
case Config .DECODE_SOURCES_SMALI_ONLY_MAIN_CLASSES :
@@ -160,7 +160,7 @@ public void decode(File outDir) throws AndrolibException, IOException, Directory
160
160
if (! file .equalsIgnoreCase ("classes.dex" )) {
161
161
switch (config .decodeSources ) {
162
162
case Config .DECODE_SOURCES_NONE :
163
- decodeSourcesRaw (mApkFile , outDir , file );
163
+ copySourcesRaw (mApkFile , outDir , file );
164
164
break ;
165
165
case Config .DECODE_SOURCES_SMALI :
166
166
decodeSourcesSmali (mApkFile , outDir , file );
@@ -169,7 +169,7 @@ public void decode(File outDir) throws AndrolibException, IOException, Directory
169
169
if (file .startsWith ("classes" ) && file .endsWith (".dex" )) {
170
170
decodeSourcesSmali (mApkFile , outDir , file );
171
171
} else {
172
- decodeSourcesRaw (mApkFile , outDir , file );
172
+ copySourcesRaw (mApkFile , outDir , file );
173
173
}
174
174
break ;
175
175
}
@@ -178,11 +178,11 @@ public void decode(File outDir) throws AndrolibException, IOException, Directory
178
178
}
179
179
}
180
180
181
- decodeRawFiles (mApkFile , outDir );
182
- decodeUnknownFiles (mApkFile , outDir );
181
+ copyRawFiles (mApkFile , outDir );
182
+ copyUnknownFiles (mApkFile , outDir );
183
183
mUncompressedFiles = new ArrayList <>();
184
184
recordUncompressedFiles (mApkFile , mUncompressedFiles );
185
- writeOriginalFiles (mApkFile , outDir );
185
+ copyOriginalFiles (mApkFile , outDir );
186
186
writeMetaFile (outDir );
187
187
} finally {
188
188
try {
@@ -250,25 +250,25 @@ public void close() throws IOException {
250
250
mAndRes .close ();
251
251
}
252
252
253
- public void writeMetaFile (File outDir )
254
- throws AndrolibException {
253
+ public void writeMetaFile (File outDir ) throws AndrolibException {
255
254
MetaInfo meta = new MetaInfo ();
256
255
meta .version = ApktoolProperties .getVersion ();
257
256
meta .apkFileName = mApkFile .getName ();
258
257
259
258
if (mResTable != null ) {
260
- meta .isFrameworkApk = mResTable .isFrameworkApk ();
261
- putUsesFramework (meta );
262
- putSdkInfo (outDir , meta );
263
- putPackageInfo (meta );
264
- putVersionInfo (outDir , meta );
265
- putSharedLibraryInfo (meta );
266
- putSparseResourcesInfo (meta );
259
+ mResTable .initMetaInfo (meta , outDir );
260
+ if (config .frameworkTag != null ) {
261
+ meta .usesFramework .tag = config .frameworkTag ;
262
+ }
267
263
} else {
268
- putMinSdkInfo (meta );
264
+ if (mMinSdkVersion > 0 ) {
265
+ meta .sdkInfo = getMinSdkInfo ();
266
+ }
267
+ }
268
+ meta .unknownFiles = mResUnknownFiles .getUnknownFiles ();
269
+ if (mUncompressedFiles != null && !mUncompressedFiles .isEmpty ()) {
270
+ meta .doNotCompress = mUncompressedFiles ;
269
271
}
270
- putUnknownInfo (meta );
271
- putFileCompressionInfo (meta );
272
272
273
273
try {
274
274
meta .save (new File (outDir , "apktool.yml" ));
@@ -277,111 +277,13 @@ public void writeMetaFile(File outDir)
277
277
}
278
278
}
279
279
280
- private void putUsesFramework (MetaInfo meta ) {
281
- Set <ResPackage > pkgs = mResTable .listFramePackages ();
282
- if (pkgs .isEmpty ()) {
283
- return ;
284
- }
285
-
286
- Integer [] ids = new Integer [pkgs .size ()];
287
- int i = 0 ;
288
- for (ResPackage pkg : pkgs ) {
289
- ids [i ++] = pkg .getId ();
290
- }
291
- Arrays .sort (ids );
292
-
293
- meta .usesFramework = new UsesFramework ();
294
- meta .usesFramework .ids = Arrays .asList (ids );
295
-
296
- if (config .frameworkTag != null ) {
297
- meta .usesFramework .tag = config .frameworkTag ;
298
- }
299
- }
300
-
301
- private void putSdkInfo (File outDir , MetaInfo meta ) {
302
- Map <String , String > info = mResTable .getSdkInfo ();
303
- if (info .size () > 0 ) {
304
- String refValue ;
305
- if (info .get ("minSdkVersion" ) != null ) {
306
- refValue = ResXmlPatcher .pullValueFromIntegers (outDir , info .get ("minSdkVersion" ));
307
- if (refValue != null ) {
308
- info .put ("minSdkVersion" , refValue );
309
- }
310
- }
311
- if (info .get ("targetSdkVersion" ) != null ) {
312
- refValue = ResXmlPatcher .pullValueFromIntegers (outDir , info .get ("targetSdkVersion" ));
313
- if (refValue != null ) {
314
- info .put ("targetSdkVersion" , refValue );
315
- }
316
- }
317
- if (info .get ("maxSdkVersion" ) != null ) {
318
- refValue = ResXmlPatcher .pullValueFromIntegers (outDir , info .get ("maxSdkVersion" ));
319
- if (refValue != null ) {
320
- info .put ("maxSdkVersion" , refValue );
321
- }
322
- }
323
- meta .sdkInfo = info ;
324
- }
325
- }
326
-
327
- private void putMinSdkInfo (MetaInfo meta ) {
328
- if (mMinSdkVersion > 0 ) {
329
- Map <String , String > sdkInfo = new LinkedHashMap <>();
330
- sdkInfo .put ("minSdkVersion" , Integer .toString (mMinSdkVersion ));
331
- meta .sdkInfo = sdkInfo ;
332
- }
333
- }
334
-
335
- private void putPackageInfo (MetaInfo meta ) throws AndrolibException {
336
- String renamed = mResTable .getPackageRenamed ();
337
- String original = mResTable .getPackageOriginal ();
338
-
339
- int id = mResTable .getPackageId ();
340
- try {
341
- id = mResTable .getPackage (renamed ).getId ();
342
- } catch (UndefinedResObjectException ignored ) {}
343
-
344
- if (Strings .isNullOrEmpty (original )) {
345
- return ;
346
- }
347
-
348
- meta .packageInfo = new PackageInfo ();
349
-
350
- // only put rename-manifest-package into apktool.yml, if the change will be required
351
- if (!renamed .equalsIgnoreCase (original )) {
352
- meta .packageInfo .renameManifestPackage = renamed ;
353
- }
354
- meta .packageInfo .forcedPackageId = String .valueOf (id );
355
- }
356
-
357
- private void putVersionInfo (File outDir , MetaInfo meta ) {
358
- VersionInfo info = mResTable .getVersionInfo ();
359
- String refValue = ResXmlPatcher .pullValueFromStrings (outDir , info .versionName );
360
- if (refValue != null ) {
361
- info .versionName = refValue ;
362
- }
363
- meta .versionInfo = info ;
364
- }
365
-
366
- private void putSharedLibraryInfo (MetaInfo meta ) {
367
- meta .sharedLibrary = mResTable .getSharedLibrary ();
368
- }
369
-
370
- private void putSparseResourcesInfo (MetaInfo meta ) {
371
- meta .sparseResources = mResTable .getSparseResources ();
372
- }
373
-
374
- private void putUnknownInfo (MetaInfo meta ) {
375
- meta .unknownFiles = mResUnknownFiles .getUnknownFiles ();
376
- }
377
-
378
- private void putFileCompressionInfo (MetaInfo meta ) {
379
- if (mUncompressedFiles != null && !mUncompressedFiles .isEmpty ()) {
380
- meta .doNotCompress = mUncompressedFiles ;
381
- }
280
+ private Map <String , String > getMinSdkInfo () {
281
+ Map <String , String > sdkInfo = new LinkedHashMap <>();
282
+ sdkInfo .put ("minSdkVersion" , Integer .toString (mMinSdkVersion ));
283
+ return sdkInfo ;
382
284
}
383
285
384
- public void decodeSourcesRaw (ExtFile apkFile , File outDir , String filename )
286
+ public void copySourcesRaw (ExtFile apkFile , File outDir , String filename )
385
287
throws AndrolibException {
386
288
try {
387
289
LOGGER .info ("Copying raw " + filename + " file..." );
@@ -415,7 +317,7 @@ public void decodeSourcesSmali(File apkFile, File outDir, String filename)
415
317
}
416
318
}
417
319
418
- public void decodeManifestRaw (ExtFile apkFile , File outDir )
320
+ public void copyManifestRaw (ExtFile apkFile , File outDir )
419
321
throws AndrolibException {
420
322
try {
421
323
LOGGER .info ("Copying raw manifest..." );
@@ -430,7 +332,7 @@ public void decodeManifestFull(ExtFile apkFile, File outDir, ResTable resTable)
430
332
mAndRes .decodeManifest (resTable , apkFile , outDir );
431
333
}
432
334
433
- public void decodeResourcesRaw (ExtFile apkFile , File outDir )
335
+ public void copyResourcesRaw (ExtFile apkFile , File outDir )
434
336
throws AndrolibException {
435
337
try {
436
338
LOGGER .info ("Copying raw resources..." );
@@ -450,7 +352,7 @@ public void decodeManifestWithResources(ExtFile apkFile, File outDir, ResTable r
450
352
mAndRes .decodeManifestWithResources (resTable , apkFile , outDir );
451
353
}
452
354
453
- public void decodeRawFiles (ExtFile apkFile , File outDir )
355
+ public void copyRawFiles (ExtFile apkFile , File outDir )
454
356
throws AndrolibException {
455
357
LOGGER .info ("Copying assets and libs..." );
456
358
try {
@@ -484,7 +386,7 @@ private boolean isAPKFileNames(String file) {
484
386
return false ;
485
387
}
486
388
487
- public void decodeUnknownFiles (ExtFile apkFile , File outDir )
389
+ public void copyUnknownFiles (ExtFile apkFile , File outDir )
488
390
throws AndrolibException {
489
391
LOGGER .info ("Copying unknown files..." );
490
392
File unknownOut = new File (outDir , UNK_DIRNAME );
@@ -508,7 +410,7 @@ public void decodeUnknownFiles(ExtFile apkFile, File outDir)
508
410
}
509
411
}
510
412
511
- public void writeOriginalFiles (ExtFile apkFile , File outDir )
413
+ public void copyOriginalFiles (ExtFile apkFile , File outDir )
512
414
throws AndrolibException {
513
415
LOGGER .info ("Copying original files..." );
514
416
File originalDir = new File (outDir , "original" );
@@ -531,7 +433,7 @@ public void writeOriginalFiles(ExtFile apkFile, File outDir)
531
433
if (in .containsDir ("META-INF/services" )) {
532
434
// If the original APK contains the folder META-INF/services folder
533
435
// that is used for service locators (like coroutines on android),
534
- // copy it to the destination folder so it does not get dropped.
436
+ // copy it to the destination folder, so it does not get dropped.
535
437
LOGGER .info ("Copying META-INF/services directory" );
536
438
in .copyToDir (outDir , "META-INF/services" );
537
439
}
0 commit comments