forked from firka/flutter
Add metadata to indicate if the host app contains a Flutter module (#37731)
This commit is contained in:
@@ -89,6 +89,16 @@ bool hasMultipleOccurrences(String text, Pattern pattern) {
|
||||
return text.indexOf(pattern) != text.lastIndexOf(pattern);
|
||||
}
|
||||
|
||||
/// The Android home directory.
|
||||
String get _androidHome {
|
||||
final String androidHome = Platform.environment['ANDROID_HOME'] ??
|
||||
Platform.environment['ANDROID_SDK_ROOT'];
|
||||
if (androidHome == null || androidHome.isEmpty) {
|
||||
throw Exception('Unset env flag: `ANDROID_HOME` or `ANDROID_SDK_ROOT`.');
|
||||
}
|
||||
return androidHome;
|
||||
}
|
||||
|
||||
/// Utility class to analyze the content inside an APK using dexdump,
|
||||
/// which is provided by the Android SDK.
|
||||
/// https://android.googlesource.com/platform/art/+/master/dexdump/dexdump.cc
|
||||
@@ -117,18 +127,12 @@ class ApkExtractor {
|
||||
|
||||
/// Returns the full path to the [dexdump] tool.
|
||||
Future<String> _findDexDump() async {
|
||||
final String androidHome = Platform.environment['ANDROID_HOME'] ??
|
||||
Platform.environment['ANDROID_SDK_ROOT'];
|
||||
|
||||
if (androidHome == null || androidHome.isEmpty) {
|
||||
throw Exception('Unset env flag: `ANDROID_HOME` or `ANDROID_SDK_ROOT`.');
|
||||
}
|
||||
String dexdumps;
|
||||
if (Platform.isWindows) {
|
||||
dexdumps = await eval('dir', <String>['/s/b', 'dexdump.exe'],
|
||||
workingDirectory: androidHome);
|
||||
workingDirectory: _androidHome);
|
||||
} else {
|
||||
dexdumps = await eval('find', <String>[androidHome, '-name', 'dexdump']);
|
||||
dexdumps = await eval('find', <String>[_androidHome, '-name', 'dexdump']);
|
||||
}
|
||||
if (dexdumps.isEmpty) {
|
||||
throw Exception('Couldn\'t find a dexdump executable.');
|
||||
@@ -165,6 +169,13 @@ class ApkExtractor {
|
||||
}
|
||||
}
|
||||
|
||||
/// Gets the content of the `AndroidManifest.xml`.
|
||||
Future<String> getAndroidManifest(String apk) {
|
||||
final String apkAnalyzer = path.join(_androidHome, 'tools', 'bin', 'apkanalyzer');
|
||||
return eval(apkAnalyzer, <String>['manifest', 'print', apk],
|
||||
workingDirectory: _androidHome);
|
||||
}
|
||||
|
||||
/// Checks that the classes are contained in the APK, throws otherwise.
|
||||
Future<void> checkApkContainsClasses(File apk, List<String> classes) async {
|
||||
final ApkExtractor extractor = ApkExtractor(apk);
|
||||
|
||||
Reference in New Issue
Block a user