public static Package callParsePackage ( Path apkFile ) { PackageParser packageParser = new PackageParser ( ) ; int flags = PackageParser . PARSE_IGNORE_PROCESSES ; try { Package thePackage ; if ( RuntimeEnvironment . getApiLevel ( ) >= Build . VERSION_CODES . LOLLIPOP ) { // TODO(christianw/brettchabot): workaround for NPE from probable bug in Q. // Can be removed when upstream properly handles a null callback // PackageParser#setMinAspectRatio(Package) if ( RuntimeEnvironment . getApiLevel ( ) >= Build . VERSION_CODES . Q ) { QHelper . setCallback ( packageParser ) ; } thePackage = packageParser . parsePackage ( apkFile . toFile ( ) , flags ) ; } else { // JB -> KK thePackage = reflector ( _PackageParser_ . class , packageParser ) . parsePackage ( apkFile . toFile ( ) , Fs . externalize ( apkFile ) , new DisplayMetrics ( ) , flags ) ; } if ( thePackage == null ) { List < LogItem > logItems = ShadowLog . getLogsForTag ( "PackageParser" ) ; if ( logItems . isEmpty ( ) ) { throw new RuntimeException ( "Failed to parse package " + apkFile ) ; } else { LogItem logItem = logItems . get ( 0 ) ; throw new RuntimeException ( "Failed to parse package " + apkFile + ": " + logItem . msg , logItem . throwable ) ; } } return thePackage ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } }
Parses an AndroidManifest . xml file using the framework PackageParser .